Skip to content

feat(node,serverless): Add server-only context span attributes via processSegmentSpan hooks#20842

Draft
chargome wants to merge 1 commit into
developfrom
cg-server-context-span-attributes
Draft

feat(node,serverless): Add server-only context span attributes via processSegmentSpan hooks#20842
chargome wants to merge 1 commit into
developfrom
cg-server-context-span-attributes

Conversation

@chargome
Copy link
Copy Markdown
Member

@chargome chargome commented May 12, 2026

  • Converts server-only scope contexts to segment span attributes for span streaming, using processSegmentSpan hooks in their respective packages (so we avoid bundle size impact)
  • node-core: Maps missing_instrumentation context in existing nodeContextIntegration hook
  • aws-serverless: Adds processSegmentSpan to awsLambdaIntegration for aws attributes
  • google-cloud-serverless: New gcpContextIntegration for gcp attributes

Server side part of #20828

closes #20385

@chargome chargome self-assigned this May 12, 2026
@github-actions
Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 26.87 kB - -
@sentry/browser - with treeshaking flags 25.3 kB - -
@sentry/browser (incl. Tracing) 44.77 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 46.74 kB - -
@sentry/browser (incl. Tracing, Profiling) 49.76 kB - -
@sentry/browser (incl. Tracing, Replay) 84.4 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 73.83 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.1 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 101.74 kB - -
@sentry/browser (incl. Feedback) 44.05 kB - -
@sentry/browser (incl. sendFeedback) 31.68 kB - -
@sentry/browser (incl. FeedbackAsync) 36.79 kB - -
@sentry/browser (incl. Metrics) 27.95 kB - -
@sentry/browser (incl. Logs) 28.1 kB - -
@sentry/browser (incl. Metrics & Logs) 28.78 kB - -
@sentry/react 28.62 kB - -
@sentry/react (incl. Tracing) 47.03 kB - -
@sentry/vue 31.79 kB - -
@sentry/vue (incl. Tracing) 46.64 kB - -
@sentry/svelte 26.89 kB - -
CDN Bundle 29.25 kB - -
CDN Bundle (incl. Tracing) 47.16 kB - -
CDN Bundle (incl. Logs, Metrics) 30.62 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 48.28 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 69.96 kB - -
CDN Bundle (incl. Tracing, Replay) 84.54 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 85.62 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 90.36 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 91.46 kB - -
CDN Bundle - uncompressed 86.03 kB - -
CDN Bundle (incl. Tracing) - uncompressed 141.48 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 90.22 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 144.94 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 215.05 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 260.19 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 263.64 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 273.89 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 277.33 kB - -
@sentry/nextjs (client) 49.55 kB - -
@sentry/sveltekit (client) 45.26 kB - -
@sentry/node-core 60.89 kB +0.12% +70 B 🔺
@sentry/node 166.05 kB +0.06% +90 B 🔺
@sentry/node - without tracing 74.03 kB +0.12% +88 B 🔺
@sentry/aws-serverless 108.32 kB +0.25% +263 B 🔺
@sentry/cloudflare (withSentry) - minified 170.63 kB - -
@sentry/cloudflare (withSentry) 430.41 kB - -

View base workflow run

@chargome
Copy link
Copy Markdown
Member Author

@cursor review

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 2 potential issues.

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

instrumentAwsLambda(options);
},
processSegmentSpan(span) {
const { contexts } = getIsolationScope().getScopeData();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AWS Lambda reads context from wrong scope

High Severity

The processSegmentSpan hook reads aws.lambda and aws.cloudwatch.logs contexts from getIsolationScope(), but enhanceScopeWithEnvironmentData in sdk.ts sets these contexts on getCurrentScope() (the current scope obtained inside a withScope call). Since setContext only writes to the specific scope instance and doesn't propagate upward, the isolation scope will never contain these contexts. The GCP integration correctly uses getCurrentScope() for both writing and reading. This means the AWS Lambda and CloudWatch span attributes will never be populated.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 2367768. Configure here.


expect(span.attributes).toEqual({});
});
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing integration or E2E tests for feat PR

Low Severity

This is a feat PR but only includes unit tests with mocked scopes. There are no integration or E2E tests to verify that the processSegmentSpan hooks actually populate span attributes in a real SDK setup. Given the scope mismatch bug identified in the AWS Lambda integration, an integration test would likely have caught it.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 2367768. Configure here.

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.

Convert contexts set on scope to segment span attributes

1 participant