Skip to content

feat(core): Apply request data to segment spans in span streaming - #20654

Merged
chargome merged 10 commits into
developfrom
cg-req-data-integration-span-streaming
May 6, 2026
Merged

feat(core): Apply request data to segment spans in span streaming#20654
chargome merged 10 commits into
developfrom
cg-req-data-integration-span-streaming

Conversation

@chargome

Copy link
Copy Markdown
Member

Implements the span-streaming counterpart of the requestDataIntegration.processEvent hook.

Request data from the scope's sdkProcessingMetadata is mapped to span attributes following sentry-conventions, reusing httpHeadersToSpanAttributes for sensitivity filtering and gating IP extraction behind sendDefaultPii.

Note: The logic is also guarded by client.getIntegrationByName('RequestData') so users who opt out of the integration don't get request data on streamed spans either.

This approach was chosen over adding a processSegmentSpan hook to the integration because captureSpan is tree-shakeable for non-streaming users, keeping the request data code out of bundles that don't need it (see linked ticket).

Closes#20380

@chargomechargome self-assigned this May 4, 2026
@github-actions

github-actionsBot commented May 4, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser26.3 kB--
@sentry/browser - with treeshaking flags24.78 kB--
@sentry/browser (incl. Tracing)44.17 kB--
@sentry/browser (incl. Tracing + Span Streaming)46.39 kB--
@sentry/browser (incl. Tracing, Profiling)49.14 kB--
@sentry/browser (incl. Tracing, Replay)83.55 kB--
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags73.01 kB--
@sentry/browser (incl. Tracing, Replay with Canvas)88.23 kB--
@sentry/browser (incl. Tracing, Replay, Feedback)100.84 kB--
@sentry/browser (incl. Feedback)43.44 kB--
@sentry/browser (incl. sendFeedback)31.11 kB--
@sentry/browser (incl. FeedbackAsync)36.19 kB--
@sentry/browser (incl. Metrics)27.6 kB--
@sentry/browser (incl. Logs)27.73 kB--
@sentry/browser (incl. Metrics & Logs)28.43 kB--
@sentry/react28.04 kB--
@sentry/react (incl. Tracing)46.4 kB--
@sentry/vue31.18 kB--
@sentry/vue (incl. Tracing)46.02 kB--
@sentry/svelte26.32 kB--
CDN Bundle28.91 kB--
CDN Bundle (incl. Tracing)46.94 kB--
CDN Bundle (incl. Logs, Metrics)30.34 kB--
CDN Bundle (incl. Tracing, Logs, Metrics)48.04 kB--
CDN Bundle (incl. Replay, Logs, Metrics)69.4 kB--
CDN Bundle (incl. Tracing, Replay)84.07 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)85.15 kB--
CDN Bundle (incl. Tracing, Replay, Feedback)89.89 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)90.97 kB--
CDN Bundle - uncompressed84.88 kB--
CDN Bundle (incl. Tracing) - uncompressed140.44 kB--
CDN Bundle (incl. Logs, Metrics) - uncompressed89.08 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed143.9 kB--
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed212.99 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed258.24 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed261.69 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed271.94 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed275.38 kB--
@sentry/nextjs (client)48.9 kB--
@sentry/sveltekit (client)44.64 kB--
@sentry/node-core60.08 kB+0.46%+274 B 🔺
@sentry/node163.8 kB+0.15%+245 B 🔺
@sentry/node - without tracing73.08 kB+1.12%+808 B 🔺
@sentry/aws-serverless107.24 kB+0.28%+299 B 🔺
@sentry/cloudflare (withSentry) - minified169.35 kB+0.58%+967 B 🔺
@sentry/cloudflare (withSentry)427.5 kB+0.62%+2.6 kB 🔺

View base workflow run

@chargome
chargome requested a review from nicohrubecMay 4, 2026 15:00
@chargome
chargome marked this pull request as ready for review May 4, 2026 15:00
@chargome
chargome requested a review from a team as a code ownerMay 4, 2026 15:00
Comment threadpackages/core/src/tracing/spans/captureSpan.ts Outdated
Comment threadpackages/core/src/tracing/spans/captureSpan.ts Outdated
Comment threadpackages/core/src/tracing/spans/captureSpan.ts Outdated

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

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 fd48621. Configure here.

Comment threadpackages/core/src/tracing/spans/requestData.ts Outdated
@chargome
chargome marked this pull request as draft May 5, 2026 13:26
@chargome
chargome marked this pull request as ready for review May 6, 2026 07:53
@nicohrubec
nicohrubec self-requested a review May 6, 2026 11:13

function applyScopeToSegmentSpan(_segmentSpanJSON: StreamedSpanJSON, _scopeData: ScopeData): void {
// TODO: Apply all scope and request data from auto instrumentation (contexts, request) to segment span
// TODO: Apply contexts data from auto instrumentation to segment span

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: are the changes here just leftovers or intentional?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

leftover

if (include.headers) {
requestData.headers = headers;

// Remove the Cookie header in case cookie data should not be included in the event

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: why remove the comments here?

if (include.ip) {
const ip = (normalizedRequest.headers && getClientIPAddress(normalizedRequest.headers)) || ipAddress || undefined;
if (ip) {
safeSetSpanJSONAttributes(span, { [SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS]: ip });

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: any reason not to aggregate all attributes and then call safeSetSpanJSONAttributes once instead of splitting this up?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

To set cookies before headers for precedence

return event;
},
processSegmentSpan(span, client) {
const { sdkProcessingMetadata } = getIsolationScope().getScopeData();

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: could sdkProcessingMetadata ever be undefined? in the event processing path we use a default here to be safe

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

have a few minor comments, but else good to go 🚀

@chargome
chargome merged commit 7efc03f into developMay 6, 2026
261 checks passed
@chargome
chargome deleted the cg-req-data-integration-span-streaming branch May 6, 2026 14:46
Sign up for freeto 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: RequestData integration

3 participants

@chargome@JPeer264@nicohrubec