Skip to content

feat(core): Ensure url, http.query and http.fragment are directly added#22547

Open
mydea wants to merge 3 commits into
developfrom
fn/url-attributes
Open

feat(core): Ensure url, http.query and http.fragment are directly added#22547
mydea wants to merge 3 commits into
developfrom
fn/url-attributes

Conversation

@mydea

@mydea mydea commented Jul 23, 2026

Copy link
Copy Markdown
Member

We rely on this in many tests, but only set this in span inferral often, so it depends on OTEL stuff.

@mydea mydea changed the title feat(core): Ensure url, http.query and http.fragment are directly added feat(core): Ensure url, http.query and http.fragment are directly added Jul 23, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d6bc9b0. Configure here.

}
if (parsedUrl.hash) {
attributes['http.fragment'] = parsedUrl.hash;
attributes[HTTP_FRAGMENT] = parsedUrl.hash.slice(1) || undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Split HTTP query fragment formats

Medium Severity

This commit normalizes http.query and http.fragment by stripping leading ? and # in core fetch, HTTP breadcrumbs, URL span helpers, and Node server spans, but browser XHR and Node undici fetch breadcrumbs still emit the raw URL.search / URL.hash values with those prefixes. The same app can therefore report different query and fragment shapes on http.client spans and HTTP breadcrumbs depending on the API used.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d6bc9b0. Configure here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Confirmed. Need to update the following as well to match:

  • packages/browser/src/tracing/request.ts 402-403
  • packages/node/src/utils/outgoingFetchRequest.ts 261-264

Also found these:

  • packages/astro/src/server/middleware.ts 236 and 240
  • packages/bun/src/integrations/bunserver.ts 277 and 280

Also, there are TODO(v11) comments about this in packages/opentelemetry/src/utils/parseSpanDescription.ts line 202 and packages/opentelemetry/src/spanExporter.ts line 456 that seem related, and I think can be dropped, since the todo will be to-done after this PR.

Might want to verify that the stripping happening in the otel lib isn't going to double-strip these fields, since the field set in packages/core/src/integrations/requestdata.ts is stripped already. I think it's actually behaving properly, stripping it only where it needs to and not anywhere else (apart from the handful of locations noted above), and it'd likely fail a bunch of tests if it was double-stripping. In which case the TODO(v11) comments are definitely a bit of a hazard.

Comment thread packages/core/src/utils/url.ts Outdated
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 27.79 kB +0.02% +3 B 🔺
@sentry/browser - with treeshaking flags 26.23 kB - -
@sentry/browser (incl. Tracing) 46.33 kB +0.05% +20 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 48.13 kB +0.11% +51 B 🔺
@sentry/browser (incl. Tracing, Profiling) 51.12 kB +0.02% +7 B 🔺
@sentry/browser (incl. Tracing, Replay) 85.6 kB +0.03% +19 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.24 kB +0.02% +14 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 90.31 kB +0.03% +26 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 102.98 kB +0.02% +11 B 🔺
@sentry/browser (incl. Feedback) 44.96 kB +0.01% +4 B 🔺
@sentry/browser (incl. sendFeedback) 32.59 kB +0.02% +5 B 🔺
@sentry/browser (incl. FeedbackAsync) 37.64 kB +0.02% +6 B 🔺
@sentry/browser (incl. Metrics) 28.88 kB +0.02% +3 B 🔺
@sentry/browser (incl. Logs) 29.11 kB +0.02% +3 B 🔺
@sentry/browser (incl. Metrics & Logs) 29.8 kB +0.02% +3 B 🔺
@sentry/react 29.59 kB +0.02% +3 B 🔺
@sentry/react (incl. Tracing) 48.62 kB +0.05% +22 B 🔺
@sentry/vue 33.22 kB +0.01% +2 B 🔺
@sentry/vue (incl. Tracing) 48.3 kB +0.07% +29 B 🔺
@sentry/svelte 27.81 kB +0.02% +4 B 🔺
CDN Bundle 30.11 kB +0.01% +3 B 🔺
CDN Bundle (incl. Tracing) 48.16 kB +0.01% +2 B 🔺
CDN Bundle (incl. Logs, Metrics) 31.69 kB +0.01% +3 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 49.5 kB +0.04% +18 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 70.95 kB +0.01% +5 B 🔺
CDN Bundle (incl. Tracing, Replay) 85.74 kB +0.02% +12 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.05 kB +0.03% +21 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 91.51 kB +0.01% +8 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.79 kB +0.01% +4 B 🔺
CDN Bundle - uncompressed 89.77 kB +0.03% +20 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 144.91 kB +0.05% +61 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.48 kB +0.03% +20 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 148.89 kB +0.05% +61 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 219.24 kB +0.01% +20 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.15 kB +0.03% +61 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268.11 kB +0.03% +61 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 277.85 kB +0.03% +61 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 281.81 kB +0.03% +61 B 🔺
@sentry/nextjs (client) 51.15 kB +0.05% +23 B 🔺
@sentry/sveltekit (client) 46.76 kB +0.03% +14 B 🔺
@sentry/core/server 80.27 kB +0.11% +83 B 🔺
@sentry/core/browser 52.09 kB +0.19% +94 B 🔺
@sentry/node 124.74 kB +0.09% +106 B 🔺
@sentry/node (incl. diagnostics channel injection) 150.16 kB +0.08% +108 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 70.03 kB +0.01% +2 B 🔺
@sentry/node - without tracing 74.83 kB +0.09% +65 B 🔺
@sentry/aws-serverless 84.36 kB +0.13% +109 B 🔺
@sentry/cloudflare (withSentry) - minified 196.82 kB +0.1% +179 B 🔺
@sentry/cloudflare (withSentry) 484.33 kB +0.1% +455 B 🔺

View base workflow run

@mydea
mydea force-pushed the fn/url-attributes branch from 4345066 to 6c67654 Compare July 23, 2026 12:56
@mydea
mydea marked this pull request as ready for review July 23, 2026 13:28
@mydea
mydea requested review from a team as code owners July 23, 2026 13:28
@mydea
mydea requested review from andreiborza, isaacs, logaretm and msonnb and removed request for a team July 23, 2026 13:28

@isaacs isaacs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some suggestions for cleanup and I think the clanker comment is likely valid.

It might be good to add a helper utility that can strip fragment/search strings, since we have url.search?.strip(1) || undefined in a bunch of places now? Something like:

function stripUrlPart(part: string || undefined || null, prefix: '?' : '#') {
  return (part && part.charAt(0) === prefix) ? part.strip(1) : undefined;
}

Comment on lines +27 to +28
...(parsedUrl.search ? { 'http.query': parsedUrl.search.slice(1) || undefined } : {}),
...(parsedUrl.hash ? { 'http.fragment': parsedUrl.hash.slice(1) || undefined } : {}),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These get serialized with JSON.stringify, so undefined values are safe. Not a blocker, but worth cleaning up where we encounter it, imo. Also, these can probably pull in the costs to cut down on bundle size ever so slightly:

Suggested change
...(parsedUrl.search ? { 'http.query': parsedUrl.search.slice(1) || undefined } : {}),
...(parsedUrl.hash ? { 'http.fragment': parsedUrl.hash.slice(1) || undefined } : {}),
[HTTP_FRAGMENT]: parsedUrl.hash?.slice(1) || undefined,
[HTTP_QUERY]: parsedUrl?.search?.slice(1) || undefined,

Comment on lines +173 to +174
const query = urlObj?.search ? urlObj.search.slice(1) || undefined : undefined;
const fragment = urlObj?.hash ? urlObj.hash.slice(1) || undefined : undefined;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here

Suggested change
const query = urlObj?.search ? urlObj.search.slice(1) || undefined : undefined;
const fragment = urlObj?.hash ? urlObj.hash.slice(1) || undefined : undefined;
const query = urlObj?.search?.slice(1) || undefined;
const fragment = urlObj?.hash?.slice(1) || undefined;

}
if (parsedUrl.hash) {
attributes['http.fragment'] = parsedUrl.hash;
attributes[HTTP_FRAGMENT] = parsedUrl.hash.slice(1) || undefined;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Confirmed. Need to update the following as well to match:

  • packages/browser/src/tracing/request.ts 402-403
  • packages/node/src/utils/outgoingFetchRequest.ts 261-264

Also found these:

  • packages/astro/src/server/middleware.ts 236 and 240
  • packages/bun/src/integrations/bunserver.ts 277 and 280

Also, there are TODO(v11) comments about this in packages/opentelemetry/src/utils/parseSpanDescription.ts line 202 and packages/opentelemetry/src/spanExporter.ts line 456 that seem related, and I think can be dropped, since the todo will be to-done after this PR.

Might want to verify that the stripping happening in the otel lib isn't going to double-strip these fields, since the field set in packages/core/src/integrations/requestdata.ts is stripped already. I think it's actually behaving properly, stripping it only where it needs to and not anywhere else (apart from the handful of locations noted above), and it'd likely fail a bunch of tests if it was double-stripping. In which case the TODO(v11) comments are definitely a bit of a hazard.

[ATTR_HTTP_REQUEST_METHOD_ORIGINAL]: request.method,
[URL_FULL]: requestUrl.toString(),
[URL_PATH]: requestUrl.pathname,
[URL_QUERY]: requestUrl.search,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be requestUrl.search?.strip(1) || undefined?

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.

2 participants