Skip to content

fix(astro): Isolate request instrumentation middleware on server side #9709

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

Merged
merged 5 commits into from
Dec 4, 2023

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Nov 30, 2023

This PR adds isolation to our sever-side request instrumentation, similarly to the request handler in
Sveltekit.

Note for reviewers: The changes look more drastic than they are. The gist is, we run the previous instrumentation in a new async context if there's no ongoing span. Otherwise we just call the instrumentation.

@Lms24 Lms24 requested review from AbhiPrasad and lforst November 30, 2023 16:50
@Lms24 Lms24 changed the title fix(astro): Isolate request instrumentation on server side fix(astro): Isolate request instrumentation middleware on server side Nov 30, 2023
Copy link
Contributor

github-actions bot commented Nov 30, 2023

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 65.99 KB (+0.19% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 59.59 KB (+0.22% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 31.12 KB (0%)
@sentry/browser - Webpack (gzipped) 21.38 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 62.97 KB (+0.41% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 29.62 KB (+0.33% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 21.69 KB (+0.45% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 198.31 KB (+0.44% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 89.73 KB (+0.47% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 64.71 KB (+0.66% 🔺)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 32.29 KB (+0.22% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 66.35 KB (+0.16% 🔺)
@sentry/react - Webpack (gzipped) 21.42 KB (0%)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 83.07 KB (+0.14% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 48.21 KB (0%)
@sentry-internal/feedback - Webpack (gzipped) 16.17 KB (-0.13% 🔽)
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 74.63 KB (added)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 29.72 KB (added)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 71.22 KB (added)

headers.forEach((value, key) => {
allHeaders[key] = value;
});
const { dynamicSamplingContext, traceparentData, propagationContext } = tracingContextFromHeaders(
Copy link
Member

Choose a reason for hiding this comment

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

We can now use continueTrace for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

good point, will change it!

Copy link
Member Author

Choose a reason for hiding this comment

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

Done! 89c1ec0

Copy link
Member Author

Choose a reason for hiding this comment

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

(Great call - avoiding duplicating this logic is worth the refactor)

@Lms24 Lms24 requested a review from AbhiPrasad December 1, 2023 16:06
@Lms24 Lms24 force-pushed the lms/fix-astro-isolate-requests branch from d3a2f0e to 7f908d9 Compare December 1, 2023 16:14
@@ -226,7 +226,6 @@ export function continueTrace<V>(
* These values can be obtained from incoming request headers,
* or in the browser from `<meta name="sentry-trace">` and `<meta name="baggage">` HTML tags.
*
* It also takes an optional `request` option, which if provided will also be added to the scope & transaction metadata.
Copy link
Member Author

Choose a reason for hiding this comment

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

This line was outdated, the function doesn't take a request arg anymore

@Lms24 Lms24 requested a review from anonrig December 4, 2023 14:13
@Lms24
Copy link
Member Author

Lms24 commented Dec 4, 2023

@anonrig if you're curious, this PR deals with Node AsyncLocalStorage and how we use it to isolate request context
(Will probably merge this soon for timeline reasons but I think it's an interesting part of our SDKs)

return res;
} catch (e) {
sendErrorToSentry(e);
throw e;
Copy link
Contributor

@anonrig anonrig Dec 4, 2023

Choose a reason for hiding this comment

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

Question: This will change the error stack. If we want to change this, we need something like hideStackFrames in Node.js. Is it intended?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes this creates stack frames but when processing them in the Sentry backend, we remove them. You can compare the stack trace and the raw original stack trace on this event: https://sentry-sdks.sentry.io/issues/4674142395/?project=4506099854475265&query=is%3Aunresolved&referrer=issue-stream&statsPeriod=14d&stream_index=1

Copy link
Contributor

Choose a reason for hiding this comment

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

This link gave Too Many Redirects error to me.

@Lms24 Lms24 force-pushed the lms/fix-astro-isolate-requests branch from b59ebe3 to 988990c Compare December 4, 2023 16:09
@Lms24 Lms24 enabled auto-merge (squash) December 4, 2023 16:11
@Lms24 Lms24 merged commit bfc63cb into develop Dec 4, 2023
@Lms24 Lms24 deleted the lms/fix-astro-isolate-requests branch December 4, 2023 16:28
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.

3 participants