Skip to content

feat(browser): Add support for streamed spans in httpContextIntegration#20464

Open
nicohrubec wants to merge 2 commits intodevelopfrom
nh/span-streaming-httpcontextintegration
Open

feat(browser): Add support for streamed spans in httpContextIntegration#20464
nicohrubec wants to merge 2 commits intodevelopfrom
nh/span-streaming-httpcontextintegration

Conversation

@nicohrubec
Copy link
Copy Markdown
Member

This PR adds span processing support for the httpContextIntegration :

Closes #20378


const reqData = getHttpRequestData();

span.attributes = {
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: instead of spreading this here, can we just set the attributes we want to set directly? IMHO we can just have a utility we keep using like setIfNotExists(span.attributes, 'url.full', reqData.url), or similar? Not 100% sure but I'd suspect this is faster at scale than creating a new object all the time when processing spans like this?

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 have a utility @sentry/core that does exactly what we would want I think (ref). We could export that from core and then use it in any integrations we need to port. I copied the approach here from how Lukas did the cultureContext integration (ref), not sure if he had a specific reason in mind not to use this. Wdyt?

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.

sounds good to me (exporting this and using it). FWIW the approach from lukas and in this PR are not bad I just think it is slightly better (probably) to avoid creating new objects for these things all the time - and this will likely happen quite a lot if there are multiple event processors all just adding one or two attributes!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 23, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.93 kB +0.21% +54 B 🔺
@sentry/browser - with treeshaking flags 24.41 kB +0.26% +61 B 🔺
@sentry/browser (incl. Tracing) 43.87 kB +0.14% +59 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 45.56 kB +0.13% +55 B 🔺
@sentry/browser (incl. Tracing, Profiling) 48.79 kB +0.13% +60 B 🔺
@sentry/browser (incl. Tracing, Replay) 83.05 kB +0.08% +64 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 72.56 kB +0.09% +65 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 87.74 kB +0.08% +66 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 99.99 kB +0.07% +63 B 🔺
@sentry/browser (incl. Feedback) 42.76 kB +0.15% +62 B 🔺
@sentry/browser (incl. sendFeedback) 30.61 kB +0.19% +58 B 🔺
@sentry/browser (incl. FeedbackAsync) 35.61 kB +0.17% +60 B 🔺
@sentry/browser (incl. Metrics) 27.22 kB +0.2% +53 B 🔺
@sentry/browser (incl. Logs) 27.34 kB +0.21% +55 B 🔺
@sentry/browser (incl. Metrics & Logs) 28.04 kB +0.21% +56 B 🔺
@sentry/react 27.68 kB +0.22% +60 B 🔺
@sentry/react (incl. Tracing) 46.1 kB +0.12% +54 B 🔺
@sentry/vue 30.78 kB +0.22% +66 B 🔺
@sentry/vue (incl. Tracing) 45.69 kB +0.14% +63 B 🔺
@sentry/svelte 25.95 kB +0.23% +59 B 🔺
CDN Bundle 28.62 kB +0.17% +48 B 🔺
CDN Bundle (incl. Tracing) 46.13 kB +0.13% +57 B 🔺
CDN Bundle (incl. Logs, Metrics) 30.01 kB +0.18% +51 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 47.17 kB +0.13% +58 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 68.98 kB +0.09% +58 B 🔺
CDN Bundle (incl. Tracing, Replay) 83.19 kB +0.07% +57 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 84.22 kB +0.07% +55 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 88.68 kB +0.09% +76 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 89.76 kB +0.08% +69 B 🔺
CDN Bundle - uncompressed 83.83 kB +0.3% +246 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 137.86 kB +0.18% +241 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 87.98 kB +0.29% +246 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 141.27 kB +0.18% +241 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 211.55 kB +0.12% +246 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 255.3 kB +0.1% +241 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 258.7 kB +0.1% +241 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 268.21 kB +0.09% +241 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 271.6 kB +0.09% +241 B 🔺
@sentry/nextjs (client) 48.63 kB +0.11% +52 B 🔺
@sentry/sveltekit (client) 44.3 kB +0.19% +82 B 🔺
@sentry/node-core 58.35 kB +0.02% +9 B 🔺
@sentry/node 175.66 kB +0.01% +12 B 🔺
@sentry/node - without tracing 98.3 kB +0.02% +10 B 🔺
@sentry/aws-serverless 115.33 kB +0.01% +10 B 🔺

View base workflow run

@nicohrubec nicohrubec marked this pull request as ready for review April 23, 2026 13:02
Comment thread packages/browser/src/integrations/httpcontext.ts
Copy link
Copy Markdown

@cursor cursor Bot left a comment

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 1 potential issue.

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit 7c5c438. Configure here.

Comment thread packages/browser/src/integrations/httpcontext.ts
const reqData = getHttpRequestData();

span.attributes = {
'url.full': reqData.url,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The code unconditionally sets span.attributes['url.full'] even when the URL is an empty string, violating the Sentry span protocol which requires omitting empty attributes.
Severity: MEDIUM

Suggested Fix

Conditionally set the 'url.full' attribute only when reqData.url is a non-empty string. Add a check, such as if (reqData.url) { span.attributes['url.full'] = reqData.url; }, to ensure empty attributes are not sent, aligning with the protocol and the handling of other optional attributes.

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/httpcontext.ts#L38

Potential issue: In environments where `window.document.location.href` is inaccessible,
such as sandboxed iframes, the `getLocationHref()` function returns an empty string.
Consequently, `getHttpRequestData()` provides an empty string for the URL. The new code
at `processSegmentSpan` unconditionally assigns this empty string to
`span.attributes['url.full']`. This violates the Sentry span protocol, which mandates
that empty attributes must be omitted. This behavior is inconsistent with how other
optional attributes like `User-Agent` are handled, which are only added if they have a
value, and could lead to data validation issues.

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.

^^ this also seems legitimate, we likely need to make sure that passing in undefined as a value does not result in this being set on the attributes object.

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.

Event processor migration: Browser httpContextIntegration

2 participants