From 4d8697a7a916fd5ed864b2449bba946393bc7738 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 27 Jul 2026 13:57:11 +0200 Subject: [PATCH 1/3] ref(nextjs): Remove next escaping code --- .../nextjs/src/common/utils/tracingUtils.ts | 44 ------------------- 1 file changed, 44 deletions(-) diff --git a/packages/nextjs/src/common/utils/tracingUtils.ts b/packages/nextjs/src/common/utils/tracingUtils.ts index 3c559a481086..57b2eaa29db4 100644 --- a/packages/nextjs/src/common/utils/tracingUtils.ts +++ b/packages/nextjs/src/common/utils/tracingUtils.ts @@ -2,17 +2,13 @@ import { HTTP_ROUTE } from '@sentry/conventions/attributes'; import type { PropagationContext, Span, SpanAttributes } from '@sentry/core'; import { isObjectLike, - debug, getActiveSpan, getClient, getRootSpan, - GLOBAL_OBJ, Scope, SEMANTIC_ATTRIBUTE_SENTRY_OP, spanToJSON, - startNewTrace, } from '@sentry/core'; -import { DEBUG_BUILD } from '../debug-build'; import { ATTR_NEXT_SEGMENT, ATTR_NEXT_SPAN_NAME, ATTR_NEXT_SPAN_TYPE } from '../nextSpanAttributes'; import { TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION } from '../span-attributes-with-logic-attached'; @@ -68,46 +64,6 @@ export function commonObjectToIsolationScope(commonObject: unknown): Scope { } } -interface AsyncLocalStorage { - getStore(): T | undefined; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - run(store: T, callback: (...args: TArgs) => R, ...args: TArgs): R; -} - -let nextjsEscapedAsyncStorage: AsyncLocalStorage; - -/** - * Will mark the execution context of the callback as "escaped" from Next.js internal tracing by unsetting the active - * span and propagation context. When an execution passes through this function multiple times, it is a noop after the - * first time. - */ -export function escapeNextjsTracing(cb: () => T): T { - const MaybeGlobalAsyncLocalStorage = (GLOBAL_OBJ as { AsyncLocalStorage?: new () => AsyncLocalStorage }) - .AsyncLocalStorage; - - if (!MaybeGlobalAsyncLocalStorage) { - DEBUG_BUILD && - debug.warn( - "Tried to register AsyncLocalStorage async context strategy in a runtime that doesn't support AsyncLocalStorage.", - ); - return cb(); - } - - if (!nextjsEscapedAsyncStorage) { - nextjsEscapedAsyncStorage = new MaybeGlobalAsyncLocalStorage(); - } - - if (nextjsEscapedAsyncStorage.getStore()) { - return cb(); - } else { - return startNewTrace(() => { - return nextjsEscapedAsyncStorage.run(true, () => { - return cb(); - }); - }); - } -} - /** * Ideally this function never lands in the develop branch. * From 2f05cd6bbaae3df47c92094073fbaaa35e5c33d3 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 27 Jul 2026 14:16:08 +0200 Subject: [PATCH 2/3] remove more --- .../nextjs/src/common/utils/tracingUtils.ts | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/packages/nextjs/src/common/utils/tracingUtils.ts b/packages/nextjs/src/common/utils/tracingUtils.ts index 57b2eaa29db4..5c070f33a9a5 100644 --- a/packages/nextjs/src/common/utils/tracingUtils.ts +++ b/packages/nextjs/src/common/utils/tracingUtils.ts @@ -64,28 +64,6 @@ export function commonObjectToIsolationScope(commonObject: unknown): Scope { } } -/** - * Ideally this function never lands in the develop branch. - * - * Drops the entire span tree this function was called in, if it was a span tree created by Next.js. - */ -export function dropNextjsRootContext(): void { - // When the user brings their own OTel setup (skipOpenTelemetrySetup: true), we should not - // mutate their spans with Sentry-internal attributes like `sentry.drop_transaction` - if ((getClient()?.getOptions() as { skipOpenTelemetrySetup?: boolean } | undefined)?.skipOpenTelemetrySetup) { - return; - } - - const nextJsOwnedSpan = getActiveSpan(); - if (nextJsOwnedSpan) { - const rootSpan = getRootSpan(nextJsOwnedSpan); - const rootSpanAttributes = spanToJSON(rootSpan).data; - if (rootSpanAttributes?.['next.span_type']) { - getRootSpan(nextJsOwnedSpan)?.setAttribute(TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION, true); - } - } -} - /** * Checks if the span is a resolve segment span. * @param spanAttributes The attributes of the span to check. From af6052fe3dcbf3c1a367d1486018e63a5a41e5e3 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 27 Jul 2026 14:47:32 +0200 Subject: [PATCH 3/3] fix lint --- packages/nextjs/src/common/utils/tracingUtils.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/packages/nextjs/src/common/utils/tracingUtils.ts b/packages/nextjs/src/common/utils/tracingUtils.ts index 5c070f33a9a5..166f2d2b1a46 100644 --- a/packages/nextjs/src/common/utils/tracingUtils.ts +++ b/packages/nextjs/src/common/utils/tracingUtils.ts @@ -1,16 +1,7 @@ import { HTTP_ROUTE } from '@sentry/conventions/attributes'; import type { PropagationContext, Span, SpanAttributes } from '@sentry/core'; -import { - isObjectLike, - getActiveSpan, - getClient, - getRootSpan, - Scope, - SEMANTIC_ATTRIBUTE_SENTRY_OP, - spanToJSON, -} from '@sentry/core'; +import { isObjectLike, Scope, SEMANTIC_ATTRIBUTE_SENTRY_OP } from '@sentry/core'; import { ATTR_NEXT_SEGMENT, ATTR_NEXT_SPAN_NAME, ATTR_NEXT_SPAN_TYPE } from '../nextSpanAttributes'; -import { TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION } from '../span-attributes-with-logic-attached'; const commonPropagationContextMap = new WeakMap();