Skip to content

feat(aws): Add support for automatic wrapping in ESM #17407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

msonnb
Copy link
Member

@msonnb msonnb commented Aug 13, 2025

This allows code-less setup for Lambda functions running in ESM (and thus the aws-serverless SDK in general) by vendoring the OpenTelemetry AwsLambda instrumentation and wrapping the patched handler with Sentry's wrapHandler.

Comment on lines +30 to +34
responseHook(_span, { err }) {
if (err) {
captureException(err, scope => markEventUnhandled(scope, 'auto.function.aws-serverless.otel'));
}
},
Copy link
Member Author

Choose a reason for hiding this comment

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

capturing errors here ensures that they're connected to the span correctly

Copy link
Member Author

Choose a reason for hiding this comment

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

moved init code to separate file to avoid circular dependency

@msonnb msonnb self-assigned this Aug 13, 2025
@msonnb msonnb changed the title feat(aws): Support automatic wrapping in ESM feat(aws): Add support for automatic wrapping in ESM Aug 13, 2025
Copy link
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.16 kB - -
@sentry/browser - with treeshaking flags 22.73 kB - -
@sentry/browser (incl. Tracing) 39.87 kB - -
@sentry/browser (incl. Tracing, Replay) 77.99 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.83 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 82.69 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 94.79 kB - -
@sentry/browser (incl. Feedback) 40.83 kB - -
@sentry/browser (incl. sendFeedback) 28.81 kB - -
@sentry/browser (incl. FeedbackAsync) 33.7 kB - -
@sentry/react 25.88 kB - -
@sentry/react (incl. Tracing) 41.86 kB - -
@sentry/vue 28.64 kB - -
@sentry/vue (incl. Tracing) 41.69 kB - -
@sentry/svelte 24.18 kB - -
CDN Bundle 25.66 kB - -
CDN Bundle (incl. Tracing) 39.76 kB - -
CDN Bundle (incl. Tracing, Replay) 75.82 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 81.27 kB - -
CDN Bundle - uncompressed 74.96 kB - -
CDN Bundle (incl. Tracing) - uncompressed 117.59 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 231.88 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 244.48 kB - -
@sentry/nextjs (client) 43.89 kB - -
@sentry/sveltekit (client) 40.32 kB - -
@sentry/node-core 47.99 kB -0.01% -1 B 🔽
@sentry/node 147.03 kB - -
@sentry/node - without tracing 92.24 kB -0.01% -1 B 🔽
@sentry/aws-serverless 104.46 kB +0.77% +790 B 🔺

View base workflow run

@msonnb msonnb requested review from mydea and andreiborza August 13, 2025 14:40
@msonnb msonnb marked this pull request as ready for review August 13, 2025 14:40
return new Promise((resolve, reject) => plugin._endSpan(span, err, () => reject(err)));
},
);
}
Copy link

Choose a reason for hiding this comment

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

Bug: Lambda Error Duplication in Sentry

Duplicate error events occur when Lambda handlers throw exceptions or return rejected promises. The vendored OpenTelemetry instrumentation's responseHook captures the exception, which is then re-thrown and subsequently captured again by the wrapHandler that wraps the patched handler. This leads to two identical error events in Sentry, with mechanism types 'auto.function.aws-serverless.otel' (from responseHook) and 'auto.function.aws-serverless.handler' (from wrapHandler).

Additional Locations (2)
Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

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

true, I guess in theory we could remove the catch block. But since errors are deduped anyway, we can also keep it just to be sure

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.

1 participant