Repository navigation
fix(astro): Initialize the server SDK on the first endpoint request - #25731
AyeshaWaseemAhmad wants to merge 1 commit into
Conversation
The server init was only imported through injectScript('page-ssr'),
which Astro adds to page modules but not to API endpoints. On a server
that had not rendered a page yet, getClient() was undefined, so the
request middleware skipped the request and errors thrown by endpoints
were dropped.
The middleware is now registered through a virtual module that imports
the server init before re-exporting onRequest from
@sentry/astro/middleware. With a server init file, the init is that
file, which the page-ssr injection imports as well. With the default
generated snippet, the snippet lives in a virtual module that both the
page-ssr injection and the middleware import. Either way the module is
shared, so Sentry.init() still runs once and still runs ahead of a
page's own imports.
Cloudflare Workers is unchanged, because the Worker wrapper already
initializes the SDK for every request. Netlify is unchanged too: its
optional edge middleware is bundled separately and cannot be detected
here, and running the init there fails on Deno.
Fixes getsentry#25729
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit aa825c3. Configure here.
| } finally { | ||
| wranglerPagesConfig = undefined; | ||
| } | ||
| }); |
There was a problem hiding this comment.
Conditional assertion in parameterized test
Low Severity
The Cloudflare Pages it.each still picks the expected page-ssr script with a ternary on serverInitPath. Nearby Netlify cases already put that expected script in the table. This was flagged because the review rules ask to split conditional paths instead of branching inside one test.
Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit aa825c3. Configure here.


The server init was only imported through
injectScript('page-ssr', ...), which Astro adds to page modules but not to API endpoints. On a server that has not rendered a page yet,getClient()is undefined, so the request middleware skips the request and errors thrown by endpoints are dropped.The middleware is now registered through a virtual module that imports the server init before re-exporting
onRequestfrom@sentry/astro/middleware. With a server init file, the init is that file, whichpage-ssrimports as well. With the default generated snippet, the snippet lives in a virtual module that both thepage-ssrinjection and the middleware import. Either way the module is shared, soSentry.init()still runs once, ahead of a page's own imports.On a fresh Node-adapter build the first request to an endpoint now runs the init and the error is captured, on Astro 4, 5, 6 and 7 (also in
astro devon 7, on@astrojs/vercelserverless and on Cloudflare Pages). Before, nothing was captured until a page had rendered.Cloudflare Workers is unchanged, because the Worker wrapper already initializes the SDK for every request. Netlify is unchanged too: its optional edge middleware is bundled into a separate Deno function and can't be detected here, and running the init there throws. Not covered: Netlify,
autoInstrumentation.requestHandler: false, and errors thrown before the first request. An init file that throws at import time now fails endpoint requests as well.Fixes #25729