Skip to content

Commit

Permalink
Fix server autoinstrument mergeOptions behavior in node v20+ (#1136)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaridmargolin authored Mar 18, 2024
1 parent 55cf3ca commit 35255bd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/server/telemetry/urlHelpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var url = require('url');
var { URL } = require('url');
var merge = require('../../merge');

Expand All @@ -12,11 +11,7 @@ function mergeOptions(input, options, cb) {
if (typeof input === 'string') {
const urlStr = input;
input = urlToHttpOptions(new URL(urlStr));
} else if (
input &&
input[url.searchParamsSymbol] &&
input[url.searchParamsSymbol][url.searchParamsSymbol]
) {
} else if (input && input instanceof URL) {
// url.URL instance
input = urlToHttpOptions(input);
} else {
Expand Down
27 changes: 27 additions & 0 deletions test/server.telemetry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ var https = require('https');

process.env.NODE_ENV = process.env.NODE_ENV || 'test-node-env';
var Rollbar = require('../src/server/rollbar');
var { mergeOptions } = require('../src/server/telemetry/urlHelpers');
const { URL } = require('url');

function wait(ms) {
return new Promise((resolve) => {
Expand Down Expand Up @@ -413,4 +415,29 @@ vows
},
},
})
.addBatch({
'while using autoinstrument': {
topic: function () {
const optionsUsingStringUrl = mergeOptions(
'http://example.com/api/users',
{ method: 'GET', headers: testHeaders1 },
);
const optionsUsingClassUrl = mergeOptions(
new URL('http://example.com/api/users'),
{ method: 'GET', headers: testHeaders1 },
);

return {
optionsUsingStringUrl,
optionsUsingClassUrl,
};
},
'mergeOptions should correctly handle URL and options': function ({
optionsUsingStringUrl,
optionsUsingClassUrl,
}) {
assert.deepStrictEqual(optionsUsingStringUrl, optionsUsingClassUrl);
},
},
})
.export(module, { error: false });

0 comments on commit 35255bd

Please sign in to comment.