Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps-dev): bump undici from 6.2.1 to 6.3.0 #3827

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 27 additions & 8 deletions test/instrumentation/modules/undici/undici.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ if (isUndiciIncompat) {
const http = require('http');
const { Writable } = require('stream');
const { promisify } = require('util');
const semver = require('semver');
const test = require('tape');
const undici = require('undici');
const undiciVer = require('undici/package.json').version;

const promisyApmFlush = promisify(apm.flush.bind(apm));
let server;
Expand Down Expand Up @@ -240,15 +242,32 @@ if (global.AbortController) {
{ name: 'aTransName', type: 'manual', sampled: true },
'error.transaction',
);
t.equal(
error.exception.message,
'Request aborted',
'error.exception.message',
);
t.equal(error.exception.type, 'AbortError', 'error.exception.type');
t.equal(error.exception.code, 'UND_ERR_ABORTED', 'error.exception.code');
t.equal(error.exception.module, 'undici', 'error.exception.module');
t.equal(error.exception.handled, true, 'error.exception.handled');
t.equal(error.exception.type, 'AbortError', 'error.exception.type');
if (semver.gte(undiciVer, '6.3.0')) {
// In undici@6.3.0 (https://github.com/nodejs/undici/pull/2592)
// `abort.reason` is used, if any. Node.js core AbortController's
// default reason uses "This operation was aborted".
t.equal(
error.exception.message,
'This operation was aborted',
'error.exception.message',
);
// https://developer.mozilla.org/en-US/docs/Web/API/DOMException#aborterror
t.equal(error.exception.code, '20', 'error.exception.code');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the lib instrumented changes the error codes and messages I guess it's expected and anyone having a query on ElasticSearch/Kibana should update it accordingly. But shouldn't error.exception.module be defined here with the value undici?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC error.exception.module comes from reading the err.stack. Now that Undici is passing through the Error object set on the abort.reason instead of creating its own, the err.stack points to a location in Node.js core where it is created (this loc: https://github.com/nodejs/node/blob/e133e5115a829aa7a445cfd8754df3a3dd586b0a/lib/internal/abort_controller.js#L395). That means the top frame in err.stack no longer points to a location in the undici module.

} else {
t.equal(
error.exception.message,
'Request aborted',
'error.exception.message',
);
t.equal(
error.exception.code,
'UND_ERR_ABORTED',
'error.exception.code',
);
t.equal(error.exception.module, 'undici', 'error.exception.module');
}

t.end();
}
Expand Down
63 changes: 36 additions & 27 deletions test/stacktraces/stacktraces.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const {
stackTraceFromErrStackString,
} = require('../../lib/stacktraces');

// Determine Node.js's default `Error.prepareStackTrace` value before any
// tests run that might start the agent, which changes this value.
const defaultNodePrepareStackTraceStr = Error.prepareStackTrace
? Error.prepareStackTrace.name
: 'undefined';

const log = logging.createLogger('off');

// Execute 'node fixtures/throw-an-error.js' and assert APM server gets the
Expand Down Expand Up @@ -452,7 +458,7 @@ tape.test('gatherStackTrace()', function (suite) {
});
});

tape.test('Error.prepareStackTrace is set', function (t) {
tape.test('Error.prepareStackTrace is set when agent active', function (t) {
const server = new MockAPMServer();
server.start(function (serverUrl) {
execFile(
Expand All @@ -479,32 +485,35 @@ tape.test('gatherStackTrace()', function (suite) {
});
});

tape.test('Error.prepareStackTrace is not set', function (t) {
const server = new MockAPMServer();
server.start(function (serverUrl) {
execFile(
process.execPath,
['fixtures/get-prepare-stacktrace.js'],
{
cwd: __dirname,
timeout: 3000,
env: Object.assign({}, process.env, {
ELASTIC_APM_ACTIVE: false,
}),
},
function done(err, _stdout, _stderr) {
t.ok(!err);
t.equals(
_stdout.trim(),
'undefined',
'Error.prepareStackTrace is not set',
);
server.close();
t.end();
},
);
});
});
tape.test(
'Error.prepareStackTrace is Node.js default when agent is inactive',
function (t) {
const server = new MockAPMServer();
server.start(function (serverUrl) {
execFile(
process.execPath,
['fixtures/get-prepare-stacktrace.js'],
{
cwd: __dirname,
timeout: 3000,
env: Object.assign({}, process.env, {
ELASTIC_APM_ACTIVE: false,
}),
},
function done(err, _stdout, _stderr) {
t.ok(!err);
t.equals(
_stdout.trim(),
defaultNodePrepareStackTraceStr,
'Error.prepareStackTrace is the Node.js default',
);
server.close();
t.end();
},
);
});
},
);

suite.end();
});