Skip to content

Commit 594f284

Browse files
nicohrubecclaude
andauthored
ref(opentelemetry): Vendor OTel context suppress helpers (#23030)
Vendors the OTel-context-based `suppressTracing`/`isTracingSuppressed` helpers from `@opentelemetry/core` into a local module, in preparation for dropping that dependency. The vendored copy reuses OTel's exact context key string, since third-party instrumentation like `@opentelemetry/instrumentation-http` writes suppression to the same key and `SentryTracer` reads it back to produce non-recording spans. Fixes #22282 Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
1 parent 3400ffe commit 594f284

4 files changed

Lines changed: 40 additions & 3 deletions

File tree

‎packages/opentelemetry/src/trace.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Context, Span, SpanContext, SpanOptions, TimeInput, Tracer } from '@opentelemetry/api';
22
import { context, SpanStatusCode, trace, TraceFlags } from '@opentelemetry/api';
3-
import { isTracingSuppressed, suppressTracing } from '@opentelemetry/core';
3+
import { isTracingSuppressed, suppressTracing } from './utils/suppressTracing';
44
import type { Client, Scope, Span as SentrySpan } from '@sentry/core';
55
import {
66
getClient,

‎packages/opentelemetry/src/tracer.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Context, Span as OpenTelemetrySpan, SpanOptions, Tracer } from '@opentelemetry/api';
22
import { context, isSpanContextValid, trace } from '@opentelemetry/api';
3-
import { isTracingSuppressed } from '@opentelemetry/core';
3+
import { isTracingSuppressed } from './utils/suppressTracing';
44
import {
55
_INTERNAL_safeMathRandom,
66
_INTERNAL_setSpanForScope,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* NOTICE from the Sentry authors:
17+
* - Minimal vendored implementation of the tracing-suppression helpers from
18+
* `@opentelemetry/core` to avoid pulling in that dependency.
19+
* - The context key string must stay byte-identical to OTel's, since other
20+
* OpenTelemetry instrumentation (e.g. `@opentelemetry/instrumentation-http`)
21+
* writes to the same key and our tracer reads it back to suppress spans.
22+
* - `unsuppressTracing` is dropped, as the SDK never removes the flag.
23+
*/
24+
import type { Context } from '@opentelemetry/api';
25+
import { createContextKey } from '@opentelemetry/api';
26+
27+
const SUPPRESS_TRACING_KEY = createContextKey('OpenTelemetry SDK Context Key SUPPRESS_TRACING');
28+
29+
/** Returns a new context with tracing suppressed, so no spans are created within it. */
30+
export function suppressTracing(context: Context): Context {
31+
return context.setValue(SUPPRESS_TRACING_KEY, true);
32+
}
33+
34+
/** Whether tracing is suppressed in the given context. */
35+
export function isTracingSuppressed(context: Context): boolean {
36+
return context.getValue(SUPPRESS_TRACING_KEY) === true;
37+
}

‎packages/opentelemetry/test/tracerProvider.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { context, SpanKind, trace, TraceFlags } from '@opentelemetry/api';
2-
import { suppressTracing } from '@opentelemetry/core';
2+
import { suppressTracing } from '../src/utils/suppressTracing';
33
import {
44
getActiveSpan,
55
getCapturedScopesOnSpan,

0 commit comments

Comments
 (0)