Skip to content

feat(astro): Automatically add Sentry middleware in Astro integration #9532

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 6 commits into from
Nov 27, 2023

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Nov 10, 2023

This PR adds automatic registration of our Astro middleware. This is possible since Astro 3.5.2 by adding middleware entry points in the astro integration's setup hook.

Updated Readme

This is backwards compatible with previous Astro versions because we can simply check if the addMiddleware function exists and only make use of it if it does.

ref #9444

Copy link
Contributor

github-actions bot commented Nov 10, 2023

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 66.02 KB (0%)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 56.21 KB (0%)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 31.19 KB (0%)
@sentry/browser - Webpack (gzipped) 21.4 KB (0%)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 62.65 KB (0%)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 29.47 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped) 21.55 KB (0%)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 197.27 KB (0%)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 89.15 KB (0%)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 64.12 KB (0%)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 32.12 KB (0%)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 66.43 KB (0%)
@sentry/react - Webpack (gzipped) 21.45 KB (0%)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 83.16 KB (0%)
@sentry/nextjs Client - Webpack (gzipped) 48.32 KB (0%)
@sentry-internal/feedback - Webpack (gzipped) 16.19 KB (0%)

// Users on older versions of astro will need to add the middleware manually.
const supportsAddMiddleware = typeof addMiddleware === 'function';

if (supportsAddMiddleware && isSSR && shouldAddMiddleware) {
Copy link
Member

Choose a reason for hiding this comment

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

Just thinking, will this break if people update the SDK & astro to the latest version and already have the middleware added manually - e.g. will it then add the middleware twice? or do middlewares (or our middleware) handle this scenario?

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 this break if people update the SDK

Technically, we're still in alpha so I'd be fine with this. Furthermore, middleware wasn't yet documented anywhere except for the readme.

However, for general robustness, we can probably detect and handle double wrapping by writing a flag to the locals object that's passed into the middleware handlers. I'll check take a look.

Copy link
Member

Choose a reason for hiding this comment

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

if this is not documented yet, IMHO let's just break it! no need to introduce additional complexity then 👍

@Lms24
Copy link
Member Author

Lms24 commented Nov 27, 2023

The bug in Astro was fixed in withastro/astro#9057 (released with version 3.5.2), so we can now review and merge this.

Also tested that it works locally in a test app 👍

@Lms24 Lms24 force-pushed the lms/feat-astro-auto-add-middleware branch from 8e3a32c to 2c08271 Compare November 27, 2023 11:41
@Lms24 Lms24 self-assigned this Nov 27, 2023
@Lms24 Lms24 marked this pull request as ready for review November 27, 2023 11:43
@Lms24 Lms24 requested review from HazAT and lforst November 27, 2023 11:43
@Lms24 Lms24 merged commit 61bcf73 into develop Nov 27, 2023
@Lms24 Lms24 deleted the lms/feat-astro-auto-add-middleware branch November 27, 2023 13:26
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