Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/opentelemetry/src/trace.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Context, Span, SpanContext, SpanOptions, TimeInput, Tracer } from '@opentelemetry/api';
import { context, SpanStatusCode, trace, TraceFlags } from '@opentelemetry/api';
import { isTracingSuppressed, suppressTracing } from '@opentelemetry/core';
import { isTracingSuppressed, suppressTracing } from './utils/suppressTracing';
import type { Client, Scope, Span as SentrySpan } from '@sentry/core';
import {
getClient,
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry/src/tracer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Context, Span as OpenTelemetrySpan, SpanOptions, Tracer } from '@opentelemetry/api';
import { context, isSpanContextValid, trace } from '@opentelemetry/api';
import { isTracingSuppressed } from '@opentelemetry/core';
import { isTracingSuppressed } from './utils/suppressTracing';
import {
_INTERNAL_safeMathRandom,
_INTERNAL_setSpanForScope,
Expand Down
37 changes: 37 additions & 0 deletions packages/opentelemetry/src/utils/suppressTracing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* NOTICE from the Sentry authors:
* - Minimal vendored implementation of the tracing-suppression helpers from
* `@opentelemetry/core` to avoid pulling in that dependency.
* - The context key string must stay byte-identical to OTel's, since other
* OpenTelemetry instrumentation (e.g. `@opentelemetry/instrumentation-http`)
* writes to the same key and our tracer reads it back to suppress spans.
* - `unsuppressTracing` is dropped, as the SDK never removes the flag.
*/
import type { Context } from '@opentelemetry/api';
import { createContextKey } from '@opentelemetry/api';

const SUPPRESS_TRACING_KEY = createContextKey('OpenTelemetry SDK Context Key SUPPRESS_TRACING');

/** Returns a new context with tracing suppressed, so no spans are created within it. */
export function suppressTracing(context: Context): Context {
return context.setValue(SUPPRESS_TRACING_KEY, true);
}

/** Whether tracing is suppressed in the given context. */
export function isTracingSuppressed(context: Context): boolean {
return context.getValue(SUPPRESS_TRACING_KEY) === true;
}
2 changes: 1 addition & 1 deletion packages/opentelemetry/test/tracerProvider.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { context, SpanKind, trace, TraceFlags } from '@opentelemetry/api';
import { suppressTracing } from '@opentelemetry/core';
import { suppressTracing } from '../src/utils/suppressTracing';
import {
getActiveSpan,
getCapturedScopesOnSpan,
Expand Down
Loading