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

fix(node): fill in span data from http request options object #9112

Conversation

vlad-zhukov
Copy link
Contributor

Currently, span data is missing for Node.js requests created with options object as the only argument, such as http.request(options).

@vlad-zhukov vlad-zhukov force-pushed the fix/node-span-data-from-http-request-object branch from d78a83f to 60169cd Compare September 25, 2023 21:37
@vlad-zhukov vlad-zhukov changed the title fix(node): fill in span data from http.RequestOptions object fix(node): fill in span data from http request options object Sep 25, 2023
@vlad-zhukov vlad-zhukov force-pushed the fix/node-span-data-from-http-request-object branch from 60169cd to 6c4c1d1 Compare September 25, 2023 21:37
@@ -168,6 +168,16 @@ export function normalizeRequestArgs(
requestOptions = urlToOptions(requestArgs[0]);
} else {
requestOptions = requestArgs[0];

if (!requestOptions.pathname || !requestOptions.search) {
const parsed = new URL(
Copy link
Member

Choose a reason for hiding this comment

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

Two things:

  1. Let's try-catch this to ensure this does not fail if we cannot generate an URL there, just to be on the safe side
  2. Let's instead set the parsed values only if they aren't set.

So something like this:

try {
  const parsed = new URL(...);
  requestOptions = { 
    pathname: parsed.pathname, 
    search: parsed.search, 
    hash: parsed.hash,
    ...requestOptions
  };
} catch (e) {
  // ignore errors here
}

@mydea
Copy link
Member

mydea commented Sep 26, 2023

Thank you for the PR! That makes sense to me, I left one comment, if you could address this I can merge this in - thanks a lot!

@mydea mydea self-assigned this Sep 26, 2023
@vlad-zhukov vlad-zhukov force-pushed the fix/node-span-data-from-http-request-object branch from 6c4c1d1 to 4de669b Compare September 26, 2023 14:05
@vlad-zhukov
Copy link
Contributor Author

Thanks @mydea! I've made the changes

@mydea mydea merged commit d47eb1a into getsentry:develop Sep 27, 2023
49 checks passed
@mydea
Copy link
Member

mydea commented Sep 27, 2023

Thank you for the PR! 🚀

c298lee pushed a commit that referenced this pull request Sep 27, 2023
Currently, span data is missing for Node.js requests created with
options object as the only argument, such as `http.request(options)`.
@AbhiPrasad
Copy link
Member

This PR was released with https://github.com/getsentry/sentry-javascript/releases/tag/7.73.0. Thanks for your help @vlad-zhukov!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants