Repository navigation
Conversation
On a Cloudflare preset, the Nuxt module now wraps the Nitro Worker entry with `withSentry` of `@sentry/cloudflare` and gets the options from the default export of `instrument.server.ts` in the app root. This is the same file that the Cloudflare Vite plugin reads. Nitro builds the Worker itself, with Rollup in Nitro 2 and with its own Vite build in Nitro 3, so the Cloudflare Vite plugin cannot wrap it. The client reports the Nuxt SDK name. With Rollup, the bundler plugin of the module replaces the entry when Rollup resolves it. Vite resolves the entry before it asks the plugin, so there the plugin replaces the code of the entry module in `transform`. When the Nitro entry exports a `$DurableObject` class, as with the `cloudflare_durable` preset, the module also wraps it with `instrumentDurableObjectWithSentry`, so a request that Nitro sends to it with `durableFetch` continues the trace of the Worker. With this file, the module also adds the Nitro plugins of the Node setup (errors, route names, meta tags, middleware, storage and database spans) and names the transaction of each request. On Cloudflare, the orchestrion transform now imports `tracingChannel` from the workerd facade of `@sentry/cloudflare`, which defers the events of module-scope calls until a request runs. `withSentry` instruments the bindings of the `env` that it gives to the handlers. db0 of Nitro 2 reads the D1 bindings from this `env`, but db0 of Nitro 3 reads them from the `env` of `cloudflare:workers`. So the wrapped entry runs each handler, and each method of the Nitro Durable Object, in `withEnv` of `cloudflare:workers` with the instrumented `env`. Then the code of the app that reads `env` from `cloudflare:workers` also gets the instrumented bindings. The database instrumentation of the module leaves out the databases with the `cloudflare-d1` connector, so on Nitro 2 and Nitro 3, `@sentry/cloudflare` creates the one span of each D1 query. `sentryCloudflareNitroPlugin` is deprecated. In an app that has `instrument.server.ts` and also the plugin, the plugin does nothing and prints a warning, so `withSentry` is the only wrapper of a request. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
size-limit report 📦Compared: 4167019 (PR test merge using develop at f2c00e2) Against: f2c00e2 (develop) · base run #67616 ✅ Baseline matches: this diff contains only this PR's changes.
|
Contributor
Optional E2E testsSome optional checks were not successful. They do not block the merge. 2 not successful, 63 successful. See the run.
Successful checks
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
follow up to #26285
Description
This sets up
@sentry/nuxton Cloudflare from aninstrument.server.tsin the app root. On a Cloudflare preset, the module wraps the Worker entry of Nitro withwithSentryand adds the Nitro plugins of the Node setup, so route names, meta tags, middleware, storage, cache and database spans work on Cloudflare too. This works with Nitro 2 (Nuxt 4) and Nitro 3 (Nuxt 5).The handlers run in
withEnvwith theenvthatwithSentryinstruments, so code that readsenvfromcloudflare:workers, like db0 of Nitro 3, gets the instrumented bindings too. On Nitro 2 and Nitro 3,@sentry/cloudflarecreates the D1 spans.This also deprecates
sentryCloudflareNitroPlugin. When an app hasinstrument.server.tsand the plugin, the plugin does nothing and logs a warning.Why
With
sentryCloudflareNitroPlugin, the module adds no middleware, storage, cache or database spans, and the baggage meta tag has no route, because the plugin creates it before the route is known.Sentry traces
Before, Nitro 2 with
sentryCloudflareNitroPlugin,/api/storage-testhas only thehttp.serverspan: https://sentry-sdks.sentry.io/explore/traces/trace/b35a22b46b6f422d96954dacdac2b169/?project=4510555608449024×tamp=1795360390Before, Nitro 2 with
sentryCloudflareNitroPlugin,/api/db-testhas no database spans: https://sentry-sdks.sentry.io/explore/traces/trace/9a45858334834dd7aa6128aeee46c5b0/?project=4510555608449024×tamp=1795360390After, Nitro 2,
/api/storage-testhas middleware and cache spans: https://sentry-sdks.sentry.io/explore/traces/trace/da68b8bebd09438baee03d50d4697300/?project=4510555608449024×tamp=1795360223After, Nitro 2,
/api/db-testhas D1 spans from@sentry/cloudflare: https://sentry-sdks.sentry.io/explore/traces/trace/3854bccf179e416e8c2329e5d2fca05a/?project=4510555608449024×tamp=1795360223After, Nitro 3,
/api/storage-testhas middleware and cache spans: https://sentry-sdks.sentry.io/explore/traces/trace/d628817679c542909abcd6cf31ffca66/?project=4510555608449024×tamp=1795361326After, Nitro 3,
/api/db-testhas D1 spans from@sentry/cloudflare: https://sentry-sdks.sentry.io/explore/traces/trace/98d7910d5b0c491dacf1b84ddbb6ae14/?project=4510555608449024×tamp=1795365743Node, Nitro 2,
/api/storage-testhas the same middleware and cache spans: https://sentry-sdks.sentry.io/explore/traces/trace/dedb120e79a84db48d42025513022e5e/?project=4510555608449024×tamp=1795431729Node, Nitro 2,
/api/db-testhas db0 spans from@sentry/nuxt: https://sentry-sdks.sentry.io/explore/traces/trace/3ec8c1026f824b6398120a7ec3fa4eee/?project=4510555608449024×tamp=1795431729Node, Nitro 3,
/api/storage-testhas the same middleware and cache spans: https://sentry-sdks.sentry.io/explore/traces/trace/015523693d2e4b08b0000b3c5cc16cae/?project=4510555608449024×tamp=1795431770Node, Nitro 3,
/api/db-testhas db0 spans from@sentry/nuxt: https://sentry-sdks.sentry.io/explore/traces/trace/ae507aa3f3d1487696f6745b340e7d5b/?project=4510555608449024×tamp=1795431770