Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(instrumentation-http)!: verbose log if URL passed to http request…
… cannot be parsed
  • Loading branch information
pichlermarc committed Nov 6, 2024
commit 4c5825ca6d2a9da90a9defcb38e2e3117280524e
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ export class HttpInstrumentation extends InstrumentationBase<HttpInstrumentation
? (args.shift() as http.RequestOptions)
: undefined;
const { method, invalidUrl, optionsParsed } = getRequestInfo(
instrumentation._diag,
options,
extraOptions
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,12 @@ function stringUrlToHttpOptions(
/**
* Makes sure options is an url object
* return an object with default value and parsed options
* @param logger component logger
* @param options original options for the request
* @param [extraOptions] additional options for the request
*/
export const getRequestInfo = (
logger: DiagLogger,
options: url.URL | RequestOptions | string,
extraOptions?: RequestOptions
): {
Expand All @@ -321,6 +323,10 @@ export const getRequestInfo = (
pathname = convertedOptions.pathname || '/';
} catch (e) {
invalidUrl = true;
logger.verbose(
'Unable to parse URL provided to HTTP request, using fallback to determine path. Original error:',
e
);
// for backward compatibility with how url.parse() behaved.
optionsParsed = {
path: options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('Utility', () => {
urlParsedWithUndefinedHostAndNullPort,
whatWgUrl,
]) {
const result = utils.getRequestInfo(param);
const result = utils.getRequestInfo(diag, param);
assert.strictEqual(result.optionsParsed.hostname, 'google.fr');
assert.strictEqual(result.optionsParsed.protocol, 'http:');
assert.strictEqual(result.optionsParsed.path, '/aPath?qu=ry');
Expand Down