GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat(nuxt): Set up Cloudflare from `sentry.cloudflare.config.ts` by JPeer264 · Pull Request #26754 · getsentry/sentry-javascript Conversation
|
size-limit report 📦Compared: e84181b (PR test merge using develop at 69dbad1) Against: 69dbad1 (develop) · base run #67826 ✅ Baseline matches: this diff contains only this PR's changes.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Optional E2E testsAll optional checks were successful. 12 successful. See the run. Successful checks
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
3a602e9 to
20c3ddf
Compare
There was an error while loading. Please reload this page.
| * @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.
The reason will be displayed to describe this comment to others. Learn more.
| * @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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
removed without hesitation
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| */ | ||
| 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.
The reason will be displayed to describe this comment to others. Learn more.
| 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?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| 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.
The reason will be displayed to describe this comment to others. Learn more.
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?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
moved it now to the new config file name.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // 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.
The reason will be displayed to describe this comment to others. Learn more.
| `[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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Let's work on this together since it seems you already have a clear idea in your head on how this could work out.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| // `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.
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test for this request hook for a v1 and v2 H3Event?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yap, added
Sorry, something went wrong.
There was an error while loading. Please reload this page.
instrument.server.tssentry.cloudflare.config.ts
cd30cce to
5edb5da
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Just a mini comment, otherwise good
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| const options = optionsCallbackWithMetadata(env); | ||
| return { | ||
| ...options, | ||
| ignoreSpans: [...(options.ignoreSpans || []), ...getBuildAssetRequestFilters(buildAssetsPath)], | ||
| }; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The sdk setup uses _INTERNAL_captureOptionsSetByUser, should we maybe also check that here? so it captures the user options first
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
smart move, added.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
2ec5522 to
74d0341
Compare
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.