Skip to content
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

feat(nuxt): Improve serverless event flushing and scope isolation #14605

Merged
merged 4 commits into from
Dec 6, 2024

Conversation

s1gr1d
Copy link
Member

@s1gr1d s1gr1d commented Dec 6, 2024

Adds serverless (e.g. Vercel, Netlify) improvements:

  • Cloining/forking the isolation context when needed
  • flushing at the end of the h3 event handler and when an error happens
  • using Vercel's waitUntil for waiting on Sentry events to send before shutting down the function

Copy link
Contributor

github-actions bot commented Dec 6, 2024

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 23.19 KB - -
@sentry/browser - with treeshaking flags 21.87 KB - -
@sentry/browser (incl. Tracing) 35.68 KB - -
@sentry/browser (incl. Tracing, Replay) 72.59 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 63.02 KB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 76.9 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 89.39 KB - -
@sentry/browser (incl. Feedback) 39.95 KB - -
@sentry/browser (incl. sendFeedback) 27.81 KB - -
@sentry/browser (incl. FeedbackAsync) 32.6 KB - -
@sentry/react 25.87 KB - -
@sentry/react (incl. Tracing) 38.5 KB - -
@sentry/vue 27.4 KB - -
@sentry/vue (incl. Tracing) 37.52 KB - -
@sentry/svelte 23.36 KB - -
CDN Bundle 24.36 KB - -
CDN Bundle (incl. Tracing) 37.34 KB - -
CDN Bundle (incl. Tracing, Replay) 72.21 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 77.56 KB - -
CDN Bundle - uncompressed 71.56 KB - -
CDN Bundle (incl. Tracing) - uncompressed 110.85 KB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 223.92 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 237.13 KB - -
@sentry/nextjs (client) 38.79 KB - -
@sentry/sveltekit (client) 36.18 KB - -
@sentry/node 162.93 KB - -
@sentry/node - without tracing 99.81 KB - -
@sentry/aws-serverless 127.3 KB - -

View base workflow run

Copy link
Member

@andreiborza andreiborza left a comment

Choose a reason for hiding this comment

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

Can we add an e2e test for the isolation scope testing?


async function flushWithTimeout(): Promise<void> {
const sentryClient = getClient();
const isDebug = sentryClient ? sentryClient.getOptions().debug : false;
Copy link
Member

Choose a reason for hiding this comment

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

q: why aren't we using DEBUG_BUILD here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because this is in the runtime folder of the Nuxt module and it's not possible to use it there because it's a different build context :(

// In environments where we cannot make use of OTel httpInstrumentation, e.g. when just importing the Sentry server config at
// the top level instead of `--import` or dynamic import like on Vercel, we still need to ensure requests are properly isolated
const isolationScope = getIsolationScope();
const newIsolationScope = isolationScope === getDefaultIsolationScope() ? isolationScope.clone() : isolationScope;
Copy link
Member

Choose a reason for hiding this comment

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

maybe let's add a comment here that describes what/why we are doing here:

If otel instrumentation works, this will already be isolated at this point by the SentryHttpInstrumentation. We can identify this by comparing the current isolation scope to the default one. If that is the case, all good, we do not need to do anything. else, we fork the isolation scope here :)

const isolationScope = getIsolationScope();
const newIsolationScope = isolationScope === getDefaultIsolationScope() ? isolationScope.clone() : isolationScope;

consoleSandbox(() => {
Copy link
Member

Choose a reason for hiding this comment

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

no strong feelings, but do we need to always log this, or is logger.log not enough here? 🤔

@s1gr1d s1gr1d changed the title fix(nuxt): Improvements for serverless (flush, isolation scope) fix(nuxt): Improve serverless event flushing and scope isolation Dec 6, 2024
@s1gr1d s1gr1d changed the title fix(nuxt): Improve serverless event flushing and scope isolation feat(nuxt): Improve serverless event flushing and scope isolation Dec 6, 2024
@s1gr1d s1gr1d changed the base branch from sig/import-flag-default to develop December 6, 2024 10:23
@s1gr1d s1gr1d changed the base branch from develop to sig/import-flag-default December 6, 2024 10:24
Base automatically changed from sig/import-flag-default to develop December 6, 2024 10:44
@s1gr1d s1gr1d requested review from andreiborza and mydea December 6, 2024 10:44
@s1gr1d s1gr1d force-pushed the sig/serverless-handling branch from e77d345 to 790f765 Compare December 6, 2024 10:47
@s1gr1d s1gr1d merged commit ddd753f into develop Dec 6, 2024
37 checks passed
@s1gr1d s1gr1d deleted the sig/serverless-handling branch December 6, 2024 11:46
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.

4 participants