-
-
Couldn't load subscription status.
- Fork 1.7k
Latest advice for usage in an Astro site deployed on Cloudflare? Documentation improvements for that setup? #15097
-
Hello!
I recently built a site with the following stack:
- Astro, v5.1.1
- primarily statically rendered (as in
output: 'static'(default) in my astro config) - SSR by way of server islands components and actions
- primarily statically rendered (as in
- deployed on Cloudflare
I struggled to integrate Sentry, so I'm wondering: What's the latest recommend approach for using Sentry in Astro on Cloudflare? To identify if this is more an issue of me being a dummy or if I indeed ran into an integration issue
Or more to the point: is the approach documented in https://docs.sentry.io/platforms/javascript/guides/cloudflare/frameworks/astro/ specifically, recommending the sentryPagesPlugin approach, still current?
Based on what I was able to get working, it seems that, in astro's cloudflare integration, you don't have access to the underlying worker / onRequest middleware (I'm not sure this is the case, more wondering if the integration, at least under certain conditions, ignores any functions/_middleware.js file, as if I understand correctly, that integration outputs its own workers function under the hood), meaning:
- the approach in that doc, relying on defining a cloudflare middleware, wouldn't work. Or at least, it didn't work for me. I worked through that doc, tried a handful of astro / vite config changes, no luck (I can provide more detail, but end result was always that calling
Sentry.captureExceptionwasn't sending errors to my account) - the approach suggested in https://github.com/getsentry/sentry-javascript/tree/master/packages/cloudflare#setup-cloudflare-pages — "If you do not have access to the onRequest middleware API, you can use the
wrapRequestHandlerAPI instead" — is the right fit here- I first stumbled on that API when reviewing Compatibility of @sentry/astro with Cloudflare Pages #13217
So I'm wondering:
- for sentry usage in Astro/Cloudflare, is calling
wrapRequestHandlerin my astro middleware the way to go from hereon out?- This is exactly what I got working in the end: https://github.com/zemccartney/nba-surprise-teams/blob/6f3b952c77cdf562f7e8ba6d4eeab5479be2dad2/src/middleware.ts, which I then leverage via the
captureExceptionAPI: https://github.com/zemccartney/nba-surprise-teams/blob/6f3b952c77cdf562f7e8ba6d4eeab5479be2dad2/src/actions/index.ts#L158- In my case, actions were being called from the relatively new server islands components. Calling out in case a compounding factor here
- This is exactly what I got working in the end: https://github.com/zemccartney/nba-surprise-teams/blob/6f3b952c77cdf562f7e8ba6d4eeab5479be2dad2/src/middleware.ts, which I then leverage via the
- What's the purpose of the pages plugin? Is that actually usable when integrating with astro? Or is there an issue, perhaps on astro's side, whereby cloudflare's middleware function, as declared by the user, is ignored?
- Is https://docs.sentry.io/platforms/javascript/guides/cloudflare/frameworks/astro/ in need of an update to reflect this approach?
I think it's worth calling out in what situations a user might "not have access to the onRequest middleware API," such that it's easier to pinpoint when that approach vs. other sentry cloudflare APIs are better suited for integration
Beta Was this translation helpful? Give feedback.