Skip to content

feat: Emit low-cardinality http.client span names for fetch and XHR - #23682

Open
chargome wants to merge 2 commits into
developfrom
charlygomez/js-3412-http-client-fetch-xhr
Open

feat: Emit low-cardinality http.client span names for fetch and XHR#23682
chargome wants to merge 2 commits into
developfrom
charlygomez/js-3412-http-client-fetch-xhr

Conversation

@chargome

Copy link
Copy Markdown
Member

With span streaming, http.client spans are named {method} {url.domain} (GET api.example.com)
instead of {method} {sanitized-url}, falling back to the method alone when there is no domain
(relative and data URLs). traceLifecycle: 'static' is unchanged.

Covers instrumentFetchRequest in @sentry/core (browser, bun, cloudflare, vercel-edge), browser
XHR, and http.client.stream. node:http and undici follow separately.

Spans also get a url.domain attribute in both lifecycles, so the value in the name stays
filterable — same as the resource.* port.

Ref #23527

With span streaming, `http.client` spans are named `{method} {url.domain}` instead of
`{method} {sanitized-url}`, falling back to the method alone when there is no domain.
Covers `instrumentFetchRequest` in `@sentry/core`, browser XHR, and `http.client.stream`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@chargome chargome self-assigned this Aug 27, 2026
@linear-code

linear-code Bot commented Aug 27, 2026

Copy link
Copy Markdown

JS-3412

@chargome

Copy link
Copy Markdown
Member Author

bugbot run

Comment thread packages/browser/src/tracing/request.ts
Comment thread packages/browser/src/tracing/request.ts Outdated
Comment thread packages/browser/src/integrations/fetchStreamPerformance.ts Outdated
@github-actions

github-actions Bot commented Aug 27, 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 28.57 kB - -
@sentry/browser - with treeshaking flags 26.92 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 26.82 kB - -
@sentry/browser (incl. Tracing) 48.72 kB +0.19% +89 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 48.73 kB +0.17% +82 B 🔺
@sentry/browser (incl. Tracing, Profiling) 51.65 kB +0.17% +83 B 🔺
@sentry/browser (incl. Tracing, Replay) 88.21 kB +0.11% +93 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.61 kB +0.13% +98 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 92.9 kB +0.09% +81 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 105.59 kB +0.09% +88 B 🔺
@sentry/browser (incl. Feedback) 45.79 kB - -
@sentry/browser (incl. sendFeedback) 33.35 kB - -
@sentry/browser (incl. FeedbackAsync) 38.46 kB - -
@sentry/browser (incl. Metrics) 29.51 kB - -
@sentry/browser (incl. Logs) 29.8 kB - -
@sentry/browser (incl. Metrics & Logs) 30.43 kB - -
@sentry/react 30.31 kB - -
@sentry/react (incl. Tracing) 50.92 kB +0.17% +83 B 🔺
@sentry/vue 35.69 kB - -
@sentry/vue (incl. Tracing) 50.96 kB +0.17% +82 B 🔺
@sentry/svelte 28.59 kB - -
CDN Bundle 30.36 kB - -
CDN Bundle (incl. Tracing) 49.22 kB +0.2% +98 B 🔺
CDN Bundle (incl. Logs, Metrics) 32.56 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 51.11 kB +0.21% +104 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 73 kB - -
CDN Bundle (incl. Tracing, Replay) 86.73 kB +0.12% +103 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.62 kB +0.11% +97 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 92.53 kB +0.15% +130 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.44 kB +0.12% +111 B 🔺
CDN Bundle - uncompressed 89.97 kB - -
CDN Bundle (incl. Tracing) - uncompressed 147.13 kB +0.22% +310 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 96.26 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 152.82 kB +0.21% +310 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 225.42 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.63 kB +0.12% +310 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 272.31 kB +0.12% +310 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 280.32 kB +0.12% +310 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 285.99 kB +0.11% +310 B 🔺
@sentry/nextjs (client) 53.49 kB +0.16% +85 B 🔺
@sentry/sveltekit (client) 49.16 kB +0.16% +77 B 🔺
@sentry/core/server 65.2 kB -0.16% -103 B 🔽
@sentry/core/browser 52.42 kB +0.09% +45 B 🔺
@sentry/node 122.69 kB +0.18% +214 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 85.22 kB - -
@sentry/node - without tracing 87.73 kB +0.11% +93 B 🔺
@sentry/node - without channel injection 102.36 kB +0.19% +194 B 🔺
@sentry/aws-serverless 95.88 kB +0.1% +92 B 🔺
@sentry/cloudflare (withSentry) - minified 199.69 kB +0.05% +85 B 🔺
@sentry/cloudflare (withSentry) 496.22 kB +0.06% +279 B 🔺

View base workflow run

`parseUrl` returns the raw authority, so `user:pass@host:port` could reach the XHR span name
and `server.address`. Strip it, and set `url.domain` on browser fetch and XHR spans so the
value in the streamed name is filterable. `fetchStreamPerformance` now uses the client it
receives in `setup` instead of `getClient()`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@chargome

Copy link
Copy Markdown
Member Author

bugbot run

@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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit bdcfbb5. Configure here.

@chargome
chargome marked this pull request as ready for review August 27, 2026 16:13
@chargome
chargome requested a review from a team as a code owner August 27, 2026 16:13
@chargome
chargome requested review from logaretm and msonnb and removed request for a team August 27, 2026 16:13
Comment on lines +89 to 92
if (!hasSpanStreamingEnabled(client)) {
span.updateName(`${httpMethod} ${httpUrl} (${_getGraphQLOperation(graphqlBody)})`);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: When span streaming is enabled, the GraphQL operation name is not added as an attribute to the span, losing valuable information for tracing and observability.
Severity: HIGH

Suggested Fix

In _updateSpanWithGraphQLData, when hasSpanStreamingEnabled(client) is true, the GraphQL operation information should be set as an attribute on the span. After getting the operationInfo, add a call like span.setAttribute('graphql.operation.name', operationInfo) to ensure the data is captured on the span, aligning the implementation with the documented behavior.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/browser/src/integrations/graphqlClient.ts#L89-L92

Potential issue: When span streaming is enabled, the `_updateSpanWithGraphQLData`
function correctly avoids updating the span name to maintain low cardinality. However,
it fails to capture the GraphQL operation information (e.g., "query GetUser") as a span
attribute. The code calculates `operationInfo` but never attaches it to the span when
`hasSpanStreamingEnabled(client)` is true. This contradicts the migration documentation,
which states this information should be available on the `graphql.operation.name`
attribute. As a result, users lose the ability to differentiate between GraphQL
operations in their traces, impacting observability.

Did we get this right? 👍 / 👎 to inform future reviews.

const streamedName = domain ? `${method} ${domain}` : method;
const streamSpan = startInactiveSpan({
name: `${method} ${sanitizedUrl}`,
name: hasSpanStreamingEnabled(client) ? streamedName : `${method} ${sanitizedUrl}`,

@JPeer264 JPeer264 Aug 27, 2026

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.

q: The sanitizedUrl also takes care of "data: URLs", should the streamedName solely be domains?

Edit: seems like the PR description covers that part

// name or attribute.
const host = parsedUrl?.host?.replace(/^.*@/, '');
// Unlike `server.address`, `url.domain` excludes the port.
const domain = host?.replace(/:\d+$/, '');

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.

q: This works differently than in the fetchStreamPerformance integration, is that intended?

The other code I mean:

const domain = parsedUrl && !isURLObjectRelative(parsedUrl) ? parsedUrl.hostname : 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