Skip to content

Commit 0b651ff

Browse files
authored
ref(nextjs): Ignore sentry spans based on query param attribute (#13905)
I had a situation once that I couldn't reproduce where I encountered Sentry spans being sent with Next.js OTEL tracing. This PR ignores those spans.
1 parent 05a368f commit 0b651ff

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/nextjs/src/server/index.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { GLOBAL_OBJ, logger } from '@sentry/utils';
1414
import {
1515
ATTR_HTTP_REQUEST_METHOD,
1616
ATTR_HTTP_ROUTE,
17+
ATTR_URL_QUERY,
1718
SEMATTRS_HTTP_METHOD,
1819
SEMATTRS_HTTP_TARGET,
1920
} from '@opentelemetry/semantic-conventions';
@@ -157,11 +158,14 @@ export function init(options: NodeOptions): NodeClient | undefined {
157158
// We need to drop these spans.
158159
if (
159160
// eslint-disable-next-line deprecation/deprecation
160-
typeof spanAttributes[SEMATTRS_HTTP_TARGET] === 'string' &&
161-
// eslint-disable-next-line deprecation/deprecation
162-
spanAttributes[SEMATTRS_HTTP_TARGET].includes('sentry_key') &&
163-
// eslint-disable-next-line deprecation/deprecation
164-
spanAttributes[SEMATTRS_HTTP_TARGET].includes('sentry_client')
161+
(typeof spanAttributes[SEMATTRS_HTTP_TARGET] === 'string' &&
162+
// eslint-disable-next-line deprecation/deprecation
163+
spanAttributes[SEMATTRS_HTTP_TARGET].includes('sentry_key') &&
164+
// eslint-disable-next-line deprecation/deprecation
165+
spanAttributes[SEMATTRS_HTTP_TARGET].includes('sentry_client')) ||
166+
(typeof spanAttributes[ATTR_URL_QUERY] === 'string' &&
167+
spanAttributes[ATTR_URL_QUERY].includes('sentry_key') &&
168+
spanAttributes[ATTR_URL_QUERY].includes('sentry_client'))
165169
) {
166170
samplingDecision.decision = false;
167171
}

0 commit comments

Comments
 (0)