Skip to content

Commit 7543412

Browse files
committed
fix: set the escape hatch in next sdk
1 parent ea06022 commit 7543412

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { debug, GLOBAL_OBJ } from '@sentry/core';
2+
import { DEBUG_BUILD } from '../common/debug-build';
3+
4+
type SafeRandomContextRunner = <T>(callback: () => T) => T;
5+
6+
/**
7+
* Prepares the global object to generate safe random IDs in cache components contexts
8+
* See: https://github.com/getsentry/sentry-javascript/blob/ceb003c15973c2d8f437dfb7025eedffbc8bc8b0/packages/core/src/utils/propagationContext.ts#L1
9+
*/
10+
export function prepareSafeIdGeneratorContext(): void {
11+
const sym = Symbol.for('__SENTRY_SAFE_RANDOM_ID_WRAPPER__');
12+
const globalWithSymbol: typeof GLOBAL_OBJ & { [sym]?: SafeRandomContextRunner } = GLOBAL_OBJ;
13+
globalWithSymbol[sym] = AsyncLocalStorage.snapshot();
14+
15+
DEBUG_BUILD && debug.log('[@sentry/nextjs] Prepared safe random ID generator context');
16+
}

0 commit comments

Comments
 (0)