Skip to content

fix(browser): Set user_agent.original on all spans for consistent filtering - #24216

Merged
Lms24 merged 4 commits into
developfrom
lms/fix-browser-user-agent-original
Sep 9, 2026
Merged

fix(browser): Set user_agent.original on all spans for consistent filtering#24216
Lms24 merged 4 commits into
developfrom
lms/fix-browser-user-agent-original

Conversation

@Lms24

@Lms24 Lms24 commented Sep 8, 2026

Copy link
Copy Markdown
Member

This PR adjusts the browser httpContextIntegration to:

  • send user_agent.original instead of http.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.
  • ensure user_agent.original is 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

@Lms24
Lms24 requested a review from a team as a code owner September 8, 2026 16:39
@Lms24
Lms24 requested review from logaretm and msonnb and removed request for a team September 8, 2026 16:39
@Lms24 Lms24 self-assigned this Sep 8, 2026
@linear-code

linear-code Bot commented Sep 8, 2026

Copy link
Copy Markdown

ENG-8468

Comment thread packages/browser/src/integrations/httpcontext.ts Outdated
@Lms24
Lms24 requested a review from shellmayr September 8, 2026 16:59
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 28.81 kB +0.04% +11 B 🔺
@sentry/browser - with treeshaking flags 27.12 kB +0.04% +10 B 🔺
@sentry/browser - with treeshaking flags tracing without tracing 27.01 kB +0.03% +7 B 🔺
@sentry/browser (incl. Tracing) 49.22 kB -0.01% -2 B 🔽
@sentry/browser (incl. Tracing + Span Streaming) 49.22 kB +0.02% +5 B 🔺
@sentry/browser (incl. Tracing, Profiling) 52.15 kB +0.05% +21 B 🔺
@sentry/browser (incl. Tracing, Replay) 88.76 kB -0.01% -2 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.94 kB -0.02% -10 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 93.44 kB +0.01% +1 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 106.38 kB +0.01% +10 B 🔺
@sentry/browser (incl. Feedback) 46.3 kB +0.02% +5 B 🔺
@sentry/browser (incl. sendFeedback) 33.87 kB +0.02% +6 B 🔺
@sentry/browser (incl. FeedbackAsync) 38.99 kB +0.04% +13 B 🔺
@sentry/browser (incl. Metrics) 29.84 kB +0.08% +23 B 🔺
@sentry/browser (incl. Logs) 30.1 kB +0.06% +18 B 🔺
@sentry/browser (incl. Metrics & Logs) 30.78 kB +0.11% +31 B 🔺
@sentry/react 30.57 kB +0.05% +14 B 🔺
@sentry/react (incl. Tracing) 51.57 kB +0.03% +12 B 🔺
@sentry/vue 36.07 kB +0.05% +17 B 🔺
@sentry/vue (incl. Tracing) 51.49 kB +0.04% +19 B 🔺
@sentry/svelte 28.85 kB +0.06% +15 B 🔺
CDN Bundle 30.56 kB +0.05% +15 B 🔺
CDN Bundle (incl. Tracing) 49.76 kB +0.06% +25 B 🔺
CDN Bundle (incl. Logs, Metrics) 32.83 kB +0.03% +9 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 51.7 kB -0.01% -1 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) 73.48 kB -0.01% -4 B 🔽
CDN Bundle (incl. Tracing, Replay) 87.28 kB -0.01% -8 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 89.2 kB +0.03% +20 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 93.21 kB -0.01% -3 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 95.22 kB +0.01% +8 B 🔺
CDN Bundle - uncompressed 90.47 kB +0.01% +8 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 148.17 kB -0.01% -1 B 🔽
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.04 kB +0.01% +8 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 154.13 kB -0.01% -1 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 226.3 kB +0.01% +8 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 267.76 kB -0.01% -1 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 273.71 kB -0.01% -1 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 281.46 kB -0.01% -1 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 287.4 kB -0.01% -1 B 🔽
@sentry/nextjs (client) 54.02 kB +0.04% +20 B 🔺
@sentry/sveltekit (client) 49.68 kB +0.06% +26 B 🔺
@sentry/core/server 36.99 kB - -
@sentry/core/browser 13.55 kB - -
@sentry/node 127.86 kB +0.06% +67 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 81.61 kB - -
@sentry/node - without tracing 88.73 kB +0.03% +21 B 🔺
@sentry/node - without channel injection 107.11 kB +0.08% +80 B 🔺
@sentry/aws-serverless 97.12 kB +0.03% +28 B 🔺
@sentry/cloudflare (withSentry) - minified 201.98 kB - -
@sentry/cloudflare (withSentry) 502.68 kB - -

View base workflow run

…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 logaretm 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.

Just a Q and an L

// 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'

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.

super super l: might as well use the attr from sentry conventions?

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.

yup, good catch, thanks!

processSegmentSpan(span, client) {
const spanOp = span.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_OP];

processSpan(span, client) {

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: what's the reason for this hook change?

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.

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
Lms24 merged commit e4bf207 into develop Sep 9, 2026
246 of 247 checks passed
@Lms24
Lms24 deleted the lms/fix-browser-user-agent-original branch September 9, 2026 07:47
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.
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