Skip to content

Commit 5ca9274

Browse files
committed
guard drop attribute
1 parent 4763ff1 commit 5ca9274

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/nextjs/src/common/utils/dropMiddlewareTunnelRequests.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SEMATTRS_HTTP_TARGET } from '@opentelemetry/semantic-conventions';
2-
import { GLOBAL_OBJ, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, type Span, type SpanAttributes } from '@sentry/core';
2+
import { getClient, GLOBAL_OBJ, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, type Span, type SpanAttributes } from '@sentry/core';
33
import { isSentryRequestSpan } from '@sentry/opentelemetry';
44
import { ATTR_NEXT_SPAN_TYPE } from '../nextSpanAttributes';
55
import { TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION } from '../span-attributes-with-logic-attached';
@@ -15,6 +15,12 @@ const globalWithInjectedValues = GLOBAL_OBJ as typeof GLOBAL_OBJ & {
1515
* 2. Requests to Sentry ingest (after rewrite)
1616
*/
1717
export function dropMiddlewareTunnelRequests(span: Span, attrs: SpanAttributes | undefined): void {
18+
// When the user brings their own OTel setup (skipOpenTelemetrySetup: true), we should not
19+
// mutate their spans with Sentry-internal attributes as it pollutes their tracing backends.
20+
if ((getClient()?.getOptions() as { skipOpenTelemetrySetup?: boolean } | undefined)?.skipOpenTelemetrySetup) {
21+
return;
22+
}
23+
1824
// Only filter middleware spans or HTTP fetch spans
1925
const isMiddleware = attrs?.[ATTR_NEXT_SPAN_TYPE] === 'Middleware.execute';
2026
// The fetch span could be originating from rewrites re-writing a tunnel request

packages/nextjs/src/common/utils/tracingUtils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { PropagationContext, Span, SpanAttributes } from '@sentry/core';
33
import {
44
debug,
55
getActiveSpan,
6+
getClient,
67
getRootSpan,
78
GLOBAL_OBJ,
89
Scope,
@@ -112,6 +113,12 @@ export function escapeNextjsTracing<T>(cb: () => T): T {
112113
* Drops the entire span tree this function was called in, if it was a span tree created by Next.js.
113114
*/
114115
export function dropNextjsRootContext(): void {
116+
// When the user brings their own OTel setup (skipOpenTelemetrySetup: true), we should not
117+
// mutate their spans with Sentry-internal attributes like `sentry.drop_transaction`
118+
if ((getClient()?.getOptions() as { skipOpenTelemetrySetup?: boolean } | undefined)?.skipOpenTelemetrySetup) {
119+
return;
120+
}
121+
115122
const nextJsOwnedSpan = getActiveSpan();
116123
if (nextJsOwnedSpan) {
117124
const rootSpan = getRootSpan(nextJsOwnedSpan);

0 commit comments

Comments
 (0)