fix(browser): Set user_agent.original on all spans for consistent filtering - #24216
Merged
Conversation
Lms24
requested review from
logaretm and
msonnb
and removed request for
a team
September 8, 2026 16:39
Contributor
size-limit report 📦
|
…r race The browser `httpContextIntegration` now emits `user_agent.original` instead of `http.request.header.user_agent`, so update the Next.js app-router and pages-router pageload/navigation assertions accordingly. Also tighten the nitro-3 error assertion: the thrown route error is reported twice (h3 tracing channel and Nitro's `error` hook, the latter seeing it wrapped in an `HTTPError`), so the previous predicate matched whichever event arrived first. Match on the mechanism instead. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
logaretm
approved these changes
Sep 8, 2026
| // Coerce empty string to undefined so the helper's nullish check drops it, | ||
| // rather than writing an empty `url.full` attribute onto the span. | ||
| [URL_FULL]: | ||
| span.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_OP] !== 'http.client' |
Member
There was a problem hiding this comment.
super super l: might as well use the attr from sentry conventions?
| processSegmentSpan(span, client) { | ||
| const spanOp = span.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_OP]; | ||
|
|
||
| processSpan(span, client) { |
Member
There was a problem hiding this comment.
q: what's the reason for this hook change?
Member
Author
There was a problem hiding this comment.
we want to attach the user_agent.original attribute to every span, and only attach the other two attributes to segment spans. So since we now need a hook that runs on every span, I changed the processSegmentSpan to processSpan for all attributes and just gate on span.is_segment for the two attributes. I think runtime-wise, the perf hit for the two attributes is negligible but we save a lot couple of bytes by not having two hooks.
Lms24
added a commit
that referenced
this pull request
Sep 9, 2026
…nt filtering (#24226) Backport of: #24216 Technically, this removes an attribute and sets another. However, this only affects span streaming, which is opt-in and not 100% stable on v10, so I think it's fine. ## Differences to the original PR - `packages/browser/src/integrations/httpcontext.ts`: kept v10's `@sentry/core/browser` import path and its unfiltered `reqData.headers` / `reqData.url`. v10 has no `dataCollection` header filtering (`_INTERNAL_filterKeyValueData`, `filterCollectedUrl`), so `processSpan` takes no `client` argument here. - `packages/browser/test/integrations/httpcontext.test.ts`: dropped the `dataCollection` suite updates (that suite doesn't exist on v10) and added the `USER_AGENT` const the ported assertions reference. - Skipped `nextjs-app-dir` / `nextjs-pages-dir` `transactions.test.ts`: on v10 these still assert on transaction-event `contexts.trace.data`, which carries no user-agent attribute, so there is nothing to rename. - The interaction test lives at `browserTracingIntegration/interactions-streamed/` on v10 rather than `tracing/interactions/spans/`; same content, different path. The behavioral fix itself is ported in full.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adjusts the browser
httpContextIntegrationto:user_agent.originalinstead ofhttp.request.headers.user_agent: The former should be used to get the browser's user agent, while the latter shall only be used for outgoing requests.user_agent.originalis set as a span attribute on every span, and not just the segment span as previously. The other attributes are still only set on the segment span.Why? Sentry's "Filter events from legacy browsers" inbound filter stopped working for streamed spans because the wrong attribute was used and it was only applied to the segment span. This PR fixes both of these issues.
closes https://linear.app/getsentry/issue/ENG-8468/make-sure-user-agentoriginal-is-present-on-all-spans-not-just-segments