Skip to content

feat: Emit low-cardinality http.client span names for node:http and undici - #23690

Merged
chargome merged 4 commits into
developfrom
charlygomez/js-3412-http-client-node
Sep 1, 2026
Merged

feat: Emit low-cardinality http.client span names for node:http and undici#23690
chargome merged 4 commits into
developfrom
charlygomez/js-3412-http-client-node

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.
traceLifecycle: 'static' is unchanged.

Covers outgoing node:http/https requests, undici (global fetch), and
googleCloudHttpIntegration. The fetch and XHR side is #23682, which also carries the
migration note for both.

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

…ndici

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 outgoing `node:http`/`https` requests, undici, and `googleCloudHttpIntegration`.

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

@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 28.56 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.86 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.87 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.79 kB - -
@sentry/browser (incl. Tracing, Replay) 88.35 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.75 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 93.04 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 106 kB - -
@sentry/browser (incl. Feedback) 46.05 kB - -
@sentry/browser (incl. sendFeedback) 33.62 kB - -
@sentry/browser (incl. FeedbackAsync) 38.73 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.3 kB - -
@sentry/react (incl. Tracing) 51.06 kB - -
@sentry/vue 35.73 kB - -
@sentry/vue (incl. Tracing) 51.13 kB - -
@sentry/svelte 28.59 kB - -
CDN Bundle 30.35 kB - -
CDN Bundle (incl. Tracing) 49.5 kB - -
CDN Bundle (incl. Logs, Metrics) 32.58 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 51.41 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.17 kB - -
CDN Bundle (incl. Tracing, Replay) 87 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.86 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 92.93 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.83 kB - -
CDN Bundle - uncompressed 89.95 kB - -
CDN Bundle (incl. Tracing) - uncompressed 147.56 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 96.24 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 153.25 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 225.41 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 267.05 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 272.73 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 280.75 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 286.42 kB - -
@sentry/nextjs (client) 53.68 kB - -
@sentry/sveltekit (client) 49.29 kB - -
@sentry/core/server 65.82 kB +0.07% +43 B 🔺
@sentry/core/browser 51.94 kB - -
@sentry/node 123.85 kB +0.08% +98 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 85.53 kB - -
@sentry/node - without tracing 88.15 kB +0.16% +136 B 🔺
@sentry/node - without channel injection 103.27 kB +0.12% +114 B 🔺
@sentry/aws-serverless 96.5 kB +0.11% +105 B 🔺
@sentry/cloudflare (withSentry) - minified 201.21 kB - -
@sentry/cloudflare (withSentry) 500.7 kB - -

View base workflow run

The outgoing request span now carries `url.domain`, and the assertion compares `data` exactly.

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!

1 issue from previous review remains unresolved.

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit 1c6aa69. Configure here.

@chargome
chargome marked this pull request as ready for review August 27, 2026 16:13
@chargome
chargome requested review from a team as code owners August 27, 2026 16:13
@chargome
chargome requested review from JPeer264 and isaacs and removed request for a team August 27, 2026 16:13
Comment on lines 222 to 228
[HTTP_REQUEST_METHOD]: requestMethod,
[ATTR_HTTP_REQUEST_METHOD_ORIGINAL]: request.method,
[URL_FULL]: filterCollectedUrl(requestUrl.toString()),
[URL_DOMAIN]: requestUrl.hostname || undefined,
[URL_PATH]: requestUrl.pathname,
[URL_QUERY]: filterCollectedUrlQuery(getUrlQuery(requestUrl.search)),
[URL_FRAGMENT]: getUrlFragment(requestUrl.hash),

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: The streaming path for undici/fetch does not strip the internal SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME attribute for data: URLs, leading to a potential high-cardinality transaction name in Sentry.
Severity: LOW

Suggested Fix

Before serializing the span for streaming, delete the SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME attribute from the span's attributes. This would mirror the cleanup logic already present in the static (non-streaming) path's SentrySpan._convertSpanToTransaction() function.

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/node/src/integrations/node-fetch/undici-instrumentation.ts#L222-L228

Potential issue: When span streaming is enabled for `undici`/`fetch` and a `data:` URL
is used, the internal attribute `SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME` is not
removed from the streamed span's attributes. The static (non-streaming) path correctly
deletes this attribute before sending the transaction, but the streaming path does not.
This inconsistency causes the attribute to be leaked, which can result in the Sentry
backend using a high-cardinality name for the transaction instead of the intended
low-cardinality one.

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

@chargome
chargome requested a review from Lms24 August 31, 2026 08:05

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

Changes look good besides questions about relative URLs like in #23682. Also could we add relative url integration tests for streaming? Not sure if we have some for static spans but one or two would be good to have IMHO 🙏

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.

l: unless I'm missing something, can we still assert on the span name here?

// domain is kept. Outgoing requests have no route to parameterize.
const client = getClient();
const method = request.method?.toUpperCase();
const domain = urlObject && !isURLObjectRelative(urlObject) ? urlObject.hostname : 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.

Related to #23682 (comment), I guess server-side, we can't really get a doman/hostname for relative URLs 🤔 So omitting it for relative URLs is probably fine... wdyt? logaf-lower-than-in-browser tbh 😅

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, added a comment!

Comment on lines +119 to +124
// With span streaming the span already carries a low-cardinality name, so it must not be
// renamed back to something containing the URL.
const client = getClient();
if (!client || !hasSpanStreamingEnabled(client)) {
span.updateName(`${request.method || 'GET'} ${sanitizedUrl}`);
}

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: should we also just set the request method in a new else block when a URL does not start with :data? Or is this already handled on a lower level?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Already handled in getOutgoingRequestSpanData

chargome and others added 2 commits September 1, 2026 07:18
…90-feed

# Conflicts:
#	packages/core/src/integrations/http/get-outgoing-span-data.ts
The e2e outgoing-fetch spans dropped their name assertion when the name stopped carrying the
URL. Every outgoing span in that app shares one domain, so keep `url.full` for selecting the
span and assert the name separately.

Cover the no-domain fallback too: a request with no host leaves the URL relative, which a
server runtime cannot resolve against a page origin the way a browser can.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XvHhCTmsaPtA8vMDuHXSwd
@chargome

chargome commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

Added more tests!

@chargome
chargome requested a review from Lms24 September 1, 2026 05:55

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

thanks!

@chargome
chargome merged commit bdae903 into develop Sep 1, 2026
552 of 556 checks passed
@chargome
chargome deleted the charlygomez/js-3412-http-client-node branch September 1, 2026 07:46
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