Repository navigation
Conversation
size-limit report 📦Compared: 1823984 (PR test merge using develop at 1f32728) Against: 1f32728 (develop) · base run #67760 ✅ Baseline matches: this diff contains only this PR's changes.
|
Optional E2E testsAll optional checks were successful. 12 successful. See the run. Successful checks
|
3a602e9 to
20c3ddf
Compare
| * @deprecated Add an `instrument.server.ts` file to the root of the Nuxt app instead. Its default export returns the | ||
| * options of `@sentry/cloudflare`, and the Sentry Nuxt module wraps the Worker with `withSentry`. |
There was a problem hiding this comment.
| * @deprecated Add an `instrument.server.ts` file to the root of the Nuxt app instead. Its default export returns the | |
| * options of `@sentry/cloudflare`, and the Sentry Nuxt module wraps the Worker with `withSentry`. | |
| * @deprecated Add an `instrument.server.ts` file with the Sentry setup to the root of the Nuxt app instead. Its default export returns the | |
| * options of `@sentry/cloudflare`, and the Sentry Nuxt module wraps the Worker with `withSentry`. |
Not sure if we should leave the second sentence "Its default export ..." as it's almost too internal-technical information for users.
There was a problem hiding this comment.
removed without hesitation
| */ | ||
| export function setupCloudflareEntry(nuxt: Nuxt, optionsFile: string): void { | ||
| nuxt.hook('nitro:init', nitro => { | ||
| if (nuxt.options._prepare || !isCloudflarePreset(nitro.options.preset)) { |
There was a problem hiding this comment.
| if (nuxt.options._prepare || !isCloudflarePreset(nitro.options.preset)) { | |
| if (nuxt.options._prepare || nitro.options.dev || !isCloudflarePreset(nitro.options.preset)) { |
cloudflare-dev (which is used in dev) would also be matched here. But we should probably skip this in dev, no? Did you check/test devmode already?
There was a problem hiding this comment.
Good catch. In nuxt dev, with Nitro 2, uses the cloudflare-dev preset, which apparently extends nitro-dev, so there is no Worker entry to wrap as it's not really using miniflare, and the module printed a wrong warning which is gone now.
Nitro 3 dev, which actually runs miniflare fails currently also without Sentry, so I couldn't test it there. I will do a follow up there.
| export async function findCloudflareOptionsFile( | ||
| nuxt?: Nuxt, | ||
| options?: SentryNuxtModuleOptions, | ||
| ): Promise<string | undefined> { | ||
| return findConfigFile('instrument.server', nuxt, options); | ||
| } | ||
|
|
||
| async function findConfigFile( | ||
| basename: string, | ||
| nuxt?: Nuxt, | ||
| options?: SentryNuxtModuleOptions, | ||
| ): Promise<string | undefined> { | ||
| const possibleFileExtensions = ['ts', 'js', 'mjs', 'cjs', 'mts', 'cts']; | ||
| const relativePaths = possibleFileExtensions.map(ext => `sentry.${type}.config.${ext}`); | ||
| const relativePaths = possibleFileExtensions.map(ext => `${basename}.${ext}`); |
There was a problem hiding this comment.
We deprecated and removed support for the instrument.server file in v11. It's a bit weird if this file comes back again. Maybe we could rename it to sentry.cf.config.ts, sentry.cloudflare.config.ts or sentry.workers.config.ts?
There was a problem hiding this comment.
Good call. I like sentry.cloudflare.config.ts actually most (since it is our Cloudflare SDK, even though "workers" would be more accurate). I like it so much that is something we could and should actually support everywhere by default.
There was a problem hiding this comment.
moved it now to the new config file name.
| // eslint-disable-next-line no-console | ||
| console.warn( | ||
| `[Sentry] Found \`${basename(configPath)}\`, but the Nitro preset targets Cloudflare, where this file is not used. Set up the SDK with \`sentryCloudflareNitroPlugin\` instead: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/cloudflare-workers/`, | ||
| `[Sentry] Found \`${basename(configPath)}\`, but the Nitro preset targets Cloudflare, where this file is not used. Set up the SDK in \`instrument.server.ts\` instead: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/cloudflare-workers/`, |
There was a problem hiding this comment.
| `[Sentry] Found \`${basename(configPath)}\`, but the Nitro preset targets Cloudflare, where this file is not used. Set up the SDK in \`instrument.server.ts\` instead: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/cloudflare-workers/`, | |
| `[Sentry] Found \`${basename(configPath)}\`, but the Nitro preset targets Cloudflare, where this file is not used. Set up the SDK in \`......\` instead: https://docs.sentry.io/platforms/javascript/guides/nuxt/install/cloudflare-workers/`, |
Make sure this name is matched with whatever is used in the end.
Also, we need to update the docs because this is showing the old setup. I would propose we still show the deprecated setup steps in the docs (in case people are on old versions - we can also add versioned docs for that) and also show a mini migration guide.
There was a problem hiding this comment.
Let's work on this together since it seems you already have a clear idea in your head on how this could work out.
|
|
||
| // `withSentry` sets no transaction name, so errors captured during the request would have none. | ||
| // This is the same best-effort name the Node SDK sets when a request starts. | ||
| nitroApp.hooks.hook('request', (event: H3Event) => { |
There was a problem hiding this comment.
Can we add a test for this request hook for a v1 and v2 H3Event?
instrument.server.tssentry.cloudflare.config.ts
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>
cd30cce to
5edb5da
Compare
s1gr1d
left a comment
There was a problem hiding this comment.
Just a mini comment, otherwise good
| const options = optionsCallbackWithMetadata(env); | ||
| return { | ||
| ...options, | ||
| ignoreSpans: [...(options.ignoreSpans || []), ...getBuildAssetRequestFilters(buildAssetsPath)], | ||
| }; |
There was a problem hiding this comment.
The sdk setup uses _INTERNAL_captureOptionsSetByUser, should we maybe also check that here? so it captures the user options first
follow up to #26285
Description
This sets up
@sentry/nuxton Cloudflare from asentry.cloudflare.config.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. Like on Node, the SDK ignores the server spans of requests to the build output (app.baseURL+app.buildAssetsDir).This also deprecates
sentryCloudflareNitroPlugin. When an app hassentry.cloudflare.config.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.Known issues
nuxt devdoes not run the Worker entry, because thecloudflare-devpreset extendsnitro-dev. So the module does not wrap anything in dev.cloudflare-worker(service worker) preset of Nitro 2 has no default export to wrap. There the module only logs a warning.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