Repository navigation
fix(nextjs): Skip init inside a request of @sentry/cloudflare - #24996
Conversation
size-limit report 📦
|
20fa56b to
97c3369
Compare
97c3369 to
5fe8fa2
Compare
|
bugbot run |
5fe8fa2 to
aab82c2
Compare
aab82c2 to
07e8240
Compare
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 6987310. Configure here.
6987310 to
94224ee
Compare
| | Nuxt server | Keeps the first client and returns it. Logs that a `--import` preload is no longer needed. | | ||
| | Cloudflare (default) | Keeps the first client of the isolate and returns it, unless that client is closed or closing. `cacheClient: false` makes a new client on each call, with no warning. | | ||
| | Next.js edge | Warns, then replaces the client. Returns `void`. | | ||
| | Next.js server and edge in a request of `withSentry` (Cloudflare) | Creates no client, because the client of `withSentry` handles the request. Returns `undefined`. | |
There was a problem hiding this comment.
Why do we have this file in here? 😅
There was a problem hiding this comment.
This got added via #24962 and acts as a list of defined behaviors for our init() function. This will be then aligned in v12.
| * context strategy while the request runs (#24603). | ||
| */ | ||
| export function isAsyncContextOwnedByCloudflare(): boolean { | ||
| const strategy = getAsyncContextStrategy(getMainCarrier()); |
There was a problem hiding this comment.
Just pointing out that this detection might be brittle bc @sentry/nextjs and @sentry/cloudlfare need to be on the exact same version for this to work
There was a problem hiding this comment.
Yeah it does. But I guess this will be solved when we add this as a optional peer dependency and is documented for the, soon to be added, @sentry/nextjs/cloudflare entrypoint
Edit: Ok maybe a direct dependency might be better. But that is for another PR
Next.js calls `register()` inside the first request. When the Worker is wrapped with `withSentry` from `@sentry/cloudflare`, the server and edge `init` then installed the OpenTelemetry async context strategy on the storage of that request, and every later request failed with `context.getValue is not a function`. On Cloudflare Workers, `init` now creates no client while a request of `withSentry` from `@sentry/cloudflare` runs, because that client already handles the request. Both still set the turbopack tag. The server `init` adds its event processors to the global scope there, because it has no client of its own and runs once per isolate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2bd0505 to
a205928
Compare
Next.js calls
register()inside the first request. When the Worker is wrapped withwithSentryfrom@sentry/cloudflare, the server and edgeinitinstalled the OpenTelemetry async context strategy on the storage of that running request, and every later request failed withcontext.getValue is not a function(#24603).On Workers,
initnow creates no client while a request ofwithSentryruns, because that client already handles the request. The SDK detects this from the installed strategy (AsyncLocalStorage, a store is set,Cloudflare-Workersuser agent) instead of a new option, so existing setups need no change. The serverinitstill adds its global event processors and theturbopacktag, which also apply to the events of the Cloudflare client.🤖 Generated with Claude Code