Repository navigation
fix(nextjs): Skip init inside a request of @sentry/cloudflare
#24996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import type { Span } from '@sentry/core'; | ||
| import { debug, fill, flush, GLOBAL_OBJ, setHttpStatus } from '@sentry/core'; | ||
| import { debug, fill, flush, getAsyncContextStrategy, getMainCarrier, GLOBAL_OBJ, setHttpStatus } from '@sentry/core'; | ||
| import { vercelWaitUntil } from '@sentry/core/server'; | ||
| import type { ServerResponse } from 'http'; | ||
| import { DEBUG_BUILD } from '../debug-build'; | ||
|
|
@@ -105,3 +105,20 @@ export function cloudflareWaitUntil(task: Promise<unknown>): void { | |
| export function isCloudflareWaitUntilAvailable(): boolean { | ||
| return typeof _getOpenNextCloudflareContext()?.waitUntil === 'function'; | ||
| } | ||
|
|
||
| /** | ||
| * Whether a request of `withSentry` from `@sentry/cloudflare` runs. A client of `init` would then replace its async | ||
| * context strategy while the request runs (#24603). | ||
| */ | ||
| export function isAsyncContextOwnedByCloudflare(): boolean { | ||
| const strategy = getAsyncContextStrategy(getMainCarrier()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just pointing out that this detection might be brittle bc
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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, Edit: Ok maybe a direct dependency might be better. But that is for another PR |
||
| // The AsyncLocalStorage strategy of `@sentry/cloudflare` has no `withActiveSpan`. | ||
| const asyncLocalStorage = strategy.getTracingChannelBinding?.()?.asyncLocalStorage as | ||
| | { getStore(): unknown } | ||
| | undefined; | ||
| return ( | ||
| !strategy.withActiveSpan && | ||
| asyncLocalStorage?.getStore() !== undefined && | ||
| GLOBAL_OBJ.navigator?.userAgent === 'Cloudflare-Workers' | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have this file in here? 馃槄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This got added via #24962 and acts as a list of defined behaviors for our
init()function. This will be then aligned in v12.