From c85fbe6682b9a8fd52e4b99bdbb079833b04e845 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Thu, 20 May 2021 08:04:44 -0400 Subject: [PATCH] Move suppress tracing context key to SDK (#2202) Co-authored-by: Valentin Marchaud --- packages/opentelemetry-core/package.json | 1 - .../propagation/HttpBaggagePropagator.ts | 22 ++++++---- packages/opentelemetry-core/src/index.ts | 1 + .../src/trace/HttpTraceContextPropagator.ts | 4 +- .../src/trace/suppress-tracing.ts | 33 +++++++++++++++ .../test/propagation/composite.test.ts | 42 +++++++++---------- .../trace/HttpTraceContextPropagator.test.ts | 6 +-- packages/opentelemetry-core/tsconfig.json | 3 -- .../package.json | 2 +- .../src/http.ts | 4 +- .../opentelemetry-propagator-b3/package.json | 3 ++ .../src/B3MultiPropagator.ts | 14 +++---- .../src/B3Propagator.ts | 4 +- .../src/B3SinglePropagator.ts | 6 +-- .../test/B3MultiPropagator.test.ts | 4 +- .../test/B3Propagator.test.ts | 14 +++---- .../test/B3SinglePropagator.test.ts | 10 ++--- .../opentelemetry-propagator-b3/tsconfig.json | 5 +++ .../src/JaegerPropagator.ts | 6 +-- .../test/JaegerPropagator.test.ts | 4 +- packages/opentelemetry-tracing/src/Tracer.ts | 3 +- .../src/export/BatchSpanProcessor.ts | 7 ++-- .../src/export/SimpleSpanProcessor.ts | 12 ++++-- .../opentelemetry-tracing/test/Tracer.test.ts | 22 +++++----- 24 files changed, 140 insertions(+), 92 deletions(-) create mode 100644 packages/opentelemetry-core/src/trace/suppress-tracing.ts diff --git a/packages/opentelemetry-core/package.json b/packages/opentelemetry-core/package.json index 08325e3ddb2..b20b593560b 100644 --- a/packages/opentelemetry-core/package.json +++ b/packages/opentelemetry-core/package.json @@ -56,7 +56,6 @@ }, "devDependencies": { "@opentelemetry/api": "^1.0.0-rc.0", - "@opentelemetry/propagator-b3": "0.19.0", "@types/mocha": "8.2.2", "@types/node": "14.14.43", "@types/semver": "7.3.5", diff --git a/packages/opentelemetry-core/src/baggage/propagation/HttpBaggagePropagator.ts b/packages/opentelemetry-core/src/baggage/propagation/HttpBaggagePropagator.ts index fb678a5e05a..770df35be6f 100644 --- a/packages/opentelemetry-core/src/baggage/propagation/HttpBaggagePropagator.ts +++ b/packages/opentelemetry-core/src/baggage/propagation/HttpBaggagePropagator.ts @@ -15,23 +15,27 @@ */ import { - Context, BaggageEntry, + Context, + createBaggage, getBaggage, setBaggage, TextMapGetter, TextMapPropagator, - TextMapSetter, - createBaggage, - isInstrumentationSuppressed, + TextMapSetter } from '@opentelemetry/api'; -import { getKeyPairs, serializeKeyPairs, parsePairKeyValue } from '../utils'; +import { isTracingSuppressed } from '../../trace/suppress-tracing'; import { - BAGGAGE_MAX_NAME_VALUE_PAIRS, - BAGGAGE_ITEMS_SEPARATOR, BAGGAGE_HEADER, - BAGGAGE_MAX_PER_NAME_VALUE_PAIRS, + BAGGAGE_ITEMS_SEPARATOR, + BAGGAGE_MAX_NAME_VALUE_PAIRS, + BAGGAGE_MAX_PER_NAME_VALUE_PAIRS } from '../constants'; +import { + getKeyPairs, + parsePairKeyValue, + serializeKeyPairs +} from '../utils'; /** * Propagates {@link Baggage} through Context format propagation. @@ -42,7 +46,7 @@ import { export class HttpBaggagePropagator implements TextMapPropagator { inject(context: Context, carrier: unknown, setter: TextMapSetter) { const baggage = getBaggage(context); - if (!baggage || isInstrumentationSuppressed(context)) return; + if (!baggage || isTracingSuppressed(context)) return; const keyPairs = getKeyPairs(baggage) .filter((pair: string) => { return pair.length <= BAGGAGE_MAX_PER_NAME_VALUE_PAIRS; diff --git a/packages/opentelemetry-core/src/index.ts b/packages/opentelemetry-core/src/index.ts index 139263bc2f1..71916bfda14 100644 --- a/packages/opentelemetry-core/src/index.ts +++ b/packages/opentelemetry-core/src/index.ts @@ -31,6 +31,7 @@ export * from './trace/sampler/AlwaysOffSampler'; export * from './trace/sampler/AlwaysOnSampler'; export * from './trace/sampler/ParentBasedSampler'; export * from './trace/sampler/TraceIdRatioBasedSampler'; +export * from './trace/suppress-tracing'; export * from './trace/TraceState'; export * from './utils/environment'; export * from './utils/sampling'; diff --git a/packages/opentelemetry-core/src/trace/HttpTraceContextPropagator.ts b/packages/opentelemetry-core/src/trace/HttpTraceContextPropagator.ts index 29888aa1f12..ff55a4da879 100644 --- a/packages/opentelemetry-core/src/trace/HttpTraceContextPropagator.ts +++ b/packages/opentelemetry-core/src/trace/HttpTraceContextPropagator.ts @@ -17,7 +17,6 @@ import { Context, getSpanContext, - isInstrumentationSuppressed, isSpanContextValid, setSpanContext, SpanContext, @@ -26,6 +25,7 @@ import { TextMapSetter, TraceFlags, } from '@opentelemetry/api'; +import { isTracingSuppressed } from './suppress-tracing'; import { TraceState } from './TraceState'; export const TRACE_PARENT_HEADER = 'traceparent'; @@ -77,7 +77,7 @@ export class HttpTraceContextPropagator implements TextMapPropagator { const spanContext = getSpanContext(context); if ( !spanContext || - isInstrumentationSuppressed(context) || + isTracingSuppressed(context) || !isSpanContextValid(spanContext) ) return; diff --git a/packages/opentelemetry-core/src/trace/suppress-tracing.ts b/packages/opentelemetry-core/src/trace/suppress-tracing.ts new file mode 100644 index 00000000000..a48c01dcdb4 --- /dev/null +++ b/packages/opentelemetry-core/src/trace/suppress-tracing.ts @@ -0,0 +1,33 @@ +/* + * 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. + */ + +import { Context, createContextKey } from '@opentelemetry/api'; + +const SUPPRESS_TRACING_KEY = createContextKey( + 'OpenTelemetry SDK Context Key SUPPRESS_TRACING' +); + +export function suppressTracing(context: Context): Context { + return context.setValue(SUPPRESS_TRACING_KEY, true); +} + +export function unsuppressTracing(context: Context): Context { + return context.deleteValue(SUPPRESS_TRACING_KEY); +} + +export function isTracingSuppressed(context: Context): boolean { + return context.getValue(SUPPRESS_TRACING_KEY) === true; +} diff --git a/packages/opentelemetry-core/test/propagation/composite.test.ts b/packages/opentelemetry-core/test/propagation/composite.test.ts index f0a75320304..6448ddbae2b 100644 --- a/packages/opentelemetry-core/test/propagation/composite.test.ts +++ b/packages/opentelemetry-core/test/propagation/composite.test.ts @@ -21,6 +21,8 @@ import { SpanContext, getSpanContext, setSpanContext, + TextMapGetter, + TextMapSetter, } from '@opentelemetry/api'; import { Context, ROOT_CONTEXT } from '@opentelemetry/api'; import * as assert from 'assert'; @@ -29,19 +31,27 @@ import { HttpTraceContextPropagator, RandomIdGenerator, } from '../../src'; -import { - B3Propagator, - B3InjectEncoding, - X_B3_SAMPLED, - X_B3_SPAN_ID, - X_B3_TRACE_ID, -} from '@opentelemetry/propagator-b3'; import { TRACE_PARENT_HEADER, TRACE_STATE_HEADER, } from '../../src/trace/HttpTraceContextPropagator'; import { TraceState } from '../../src/trace/TraceState'; +class DummyPropagator implements TextMapPropagator { + inject(context: Context, carrier: any, setter: TextMapSetter): void { + carrier['dummy'] = getSpanContext(context); + } + extract(context: Context, carrier: any, getter: TextMapGetter): Context { + if (carrier['dummy']) { + return setSpanContext(context, carrier['dummy']); + } + return context; + } + fields(): string[] { + return ['dummy']; + } +} + describe('Composite Propagator', () => { let traceId: string; let spanId: string; @@ -70,16 +80,11 @@ describe('Composite Propagator', () => { it('should inject context using all configured propagators', () => { const composite = new CompositePropagator({ - propagators: [ - new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER }), - new HttpTraceContextPropagator(), - ], + propagators: [new DummyPropagator(), new HttpTraceContextPropagator()], }); composite.inject(ctxWithSpanContext, carrier, defaultTextMapSetter); - assert.strictEqual(carrier[X_B3_TRACE_ID], traceId); - assert.strictEqual(carrier[X_B3_SPAN_ID], spanId); - assert.strictEqual(carrier[X_B3_SAMPLED], '1'); + assert.strictEqual(carrier['dummy'], spanContext); assert.strictEqual( carrier[TRACE_PARENT_HEADER], `00-${traceId}-${spanId}-01` @@ -108,9 +113,7 @@ describe('Composite Propagator', () => { beforeEach(() => { carrier = { - [X_B3_TRACE_ID]: traceId, - [X_B3_SPAN_ID]: spanId, - [X_B3_SAMPLED]: 1, + ['dummy']: { traceId, spanId }, [TRACE_PARENT_HEADER]: `00-${traceId}-${spanId}-01`, [TRACE_STATE_HEADER]: 'foo=bar', }; @@ -118,10 +121,7 @@ describe('Composite Propagator', () => { it('should extract context using all configured propagators', () => { const composite = new CompositePropagator({ - propagators: [ - new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER }), - new HttpTraceContextPropagator(), - ], + propagators: [new DummyPropagator(), new HttpTraceContextPropagator()], }); const spanContext = getSpanContext( composite.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) diff --git a/packages/opentelemetry-core/test/trace/HttpTraceContextPropagator.test.ts b/packages/opentelemetry-core/test/trace/HttpTraceContextPropagator.test.ts index 115dfd87c37..5199aed0bb9 100644 --- a/packages/opentelemetry-core/test/trace/HttpTraceContextPropagator.test.ts +++ b/packages/opentelemetry-core/test/trace/HttpTraceContextPropagator.test.ts @@ -23,7 +23,6 @@ import { ROOT_CONTEXT, setSpanContext, SpanContext, - suppressInstrumentation, TraceFlags, } from '@opentelemetry/api'; import * as assert from 'assert'; @@ -32,6 +31,7 @@ import { TRACE_PARENT_HEADER, TRACE_STATE_HEADER, } from '../../src/trace/HttpTraceContextPropagator'; +import { suppressTracing } from '../../src/trace/suppress-tracing'; import { TraceState } from '../../src/trace/TraceState'; describe('HttpTraceContextPropagator', () => { @@ -90,7 +90,7 @@ describe('HttpTraceContextPropagator', () => { }; httpTraceContext.inject( - suppressInstrumentation(setSpanContext(ROOT_CONTEXT, spanContext)), + suppressTracing(setSpanContext(ROOT_CONTEXT, spanContext)), carrier, defaultTextMapSetter ); @@ -107,7 +107,7 @@ describe('HttpTraceContextPropagator', () => { }; httpTraceContext.inject( - suppressInstrumentation(setSpanContext(ROOT_CONTEXT, spanContext)), + suppressTracing(setSpanContext(ROOT_CONTEXT, spanContext)), carrier, defaultTextMapSetter ); diff --git a/packages/opentelemetry-core/tsconfig.json b/packages/opentelemetry-core/tsconfig.json index 73b0dd709c9..0717beecbfb 100644 --- a/packages/opentelemetry-core/tsconfig.json +++ b/packages/opentelemetry-core/tsconfig.json @@ -9,9 +9,6 @@ "test/**/*.ts" ], "references": [ - { - "path": "../opentelemetry-propagator-b3" - }, { "path": "../opentelemetry-semantic-conventions" } diff --git a/packages/opentelemetry-instrumentation-http/package.json b/packages/opentelemetry-instrumentation-http/package.json index fd29b04c5b9..a81677fb74c 100644 --- a/packages/opentelemetry-instrumentation-http/package.json +++ b/packages/opentelemetry-instrumentation-http/package.json @@ -43,7 +43,6 @@ "devDependencies": { "@opentelemetry/api": "^1.0.0-rc.0", "@opentelemetry/context-async-hooks": "0.19.0", - "@opentelemetry/core": "0.19.0", "@opentelemetry/node": "0.19.0", "@opentelemetry/tracing": "0.19.0", "@types/got": "9.6.11", @@ -72,6 +71,7 @@ "@opentelemetry/api": "^1.0.0-rc.0" }, "dependencies": { + "@opentelemetry/core": "0.19.0", "@opentelemetry/instrumentation": "0.19.0", "@opentelemetry/semantic-conventions": "0.19.0", "semver": "^7.1.3" diff --git a/packages/opentelemetry-instrumentation-http/src/http.ts b/packages/opentelemetry-instrumentation-http/src/http.ts index 59d9539c33c..008eac92bcf 100644 --- a/packages/opentelemetry-instrumentation-http/src/http.ts +++ b/packages/opentelemetry-instrumentation-http/src/http.ts @@ -24,10 +24,10 @@ import { setSpan, ROOT_CONTEXT, getSpan, - suppressInstrumentation, NOOP_TRACER, diag, } from '@opentelemetry/api'; +import { suppressTracing } from '@opentelemetry/core'; import type * as http from 'http'; import type * as https from 'https'; import { Socket } from 'net'; @@ -388,7 +388,7 @@ export class HttpInstrumentation extends InstrumentationBase { (e: Error) => diag.error('caught ignoreIncomingPaths error: ', e) ) ) { - return context.with(suppressInstrumentation(context.active()), () => { + return context.with(suppressTracing(context.active()), () => { context.bind(request); context.bind(response); return original.apply(this, [event, ...args]); diff --git a/packages/opentelemetry-propagator-b3/package.json b/packages/opentelemetry-propagator-b3/package.json index 3d43aff3f66..20d1cb93682 100644 --- a/packages/opentelemetry-propagator-b3/package.json +++ b/packages/opentelemetry-propagator-b3/package.json @@ -42,6 +42,9 @@ "publishConfig": { "access": "public" }, + "dependencies": { + "@opentelemetry/core": "^0.19.0" + }, "peerDependencies": { "@opentelemetry/api": "^1.0.0-rc.0" }, diff --git a/packages/opentelemetry-propagator-b3/src/B3MultiPropagator.ts b/packages/opentelemetry-propagator-b3/src/B3MultiPropagator.ts index dba3a70de30..4fbd40827bc 100644 --- a/packages/opentelemetry-propagator-b3/src/B3MultiPropagator.ts +++ b/packages/opentelemetry-propagator-b3/src/B3MultiPropagator.ts @@ -17,7 +17,6 @@ import { Context, getSpanContext, - isInstrumentationSuppressed, isSpanContextValid, isValidSpanId, isValidTraceId, @@ -27,14 +26,15 @@ import { TextMapSetter, TraceFlags, } from '@opentelemetry/api'; +import { isTracingSuppressed } from '@opentelemetry/core'; +import { B3_DEBUG_FLAG_KEY } from './common'; import { - X_B3_TRACE_ID, - X_B3_SPAN_ID, - X_B3_SAMPLED, - X_B3_PARENT_SPAN_ID, X_B3_FLAGS, + X_B3_PARENT_SPAN_ID, + X_B3_SAMPLED, + X_B3_SPAN_ID, + X_B3_TRACE_ID, } from './constants'; -import { B3_DEBUG_FLAG_KEY } from './common'; const VALID_SAMPLED_VALUES = new Set([true, 'true', 'True', '1', 1]); const VALID_UNSAMPLED_VALUES = new Set([false, 'false', 'False', '0', 0]); @@ -99,7 +99,7 @@ export class B3MultiPropagator implements TextMapPropagator { if ( !spanContext || !isSpanContextValid(spanContext) || - isInstrumentationSuppressed(context) + isTracingSuppressed(context) ) return; diff --git a/packages/opentelemetry-propagator-b3/src/B3Propagator.ts b/packages/opentelemetry-propagator-b3/src/B3Propagator.ts index 7b40ef0527c..597873e36d8 100644 --- a/packages/opentelemetry-propagator-b3/src/B3Propagator.ts +++ b/packages/opentelemetry-propagator-b3/src/B3Propagator.ts @@ -16,11 +16,11 @@ import { Context, - isInstrumentationSuppressed, TextMapGetter, TextMapPropagator, TextMapSetter, } from '@opentelemetry/api'; +import { isTracingSuppressed } from '@opentelemetry/core'; import { B3MultiPropagator } from './B3MultiPropagator'; import { B3SinglePropagator } from './B3SinglePropagator'; import { B3_CONTEXT_HEADER } from './constants'; @@ -54,7 +54,7 @@ export class B3Propagator implements TextMapPropagator { } inject(context: Context, carrier: unknown, setter: TextMapSetter) { - if (isInstrumentationSuppressed(context)) { + if (isTracingSuppressed(context)) { return; } this._inject(context, carrier, setter); diff --git a/packages/opentelemetry-propagator-b3/src/B3SinglePropagator.ts b/packages/opentelemetry-propagator-b3/src/B3SinglePropagator.ts index acd36820e89..a0a83064fa9 100644 --- a/packages/opentelemetry-propagator-b3/src/B3SinglePropagator.ts +++ b/packages/opentelemetry-propagator-b3/src/B3SinglePropagator.ts @@ -17,7 +17,6 @@ import { Context, getSpanContext, - isInstrumentationSuppressed, isSpanContextValid, isValidSpanId, isValidTraceId, @@ -27,8 +26,9 @@ import { TextMapSetter, TraceFlags, } from '@opentelemetry/api'; -import { B3_CONTEXT_HEADER } from './constants'; +import { isTracingSuppressed } from '@opentelemetry/core'; import { B3_DEBUG_FLAG_KEY } from './common'; +import { B3_CONTEXT_HEADER } from './constants'; const B3_CONTEXT_REGEX = /((?:[0-9a-f]{16}){1,2})-([0-9a-f]{16})(?:-([01d](?![0-9a-f])))?(?:-([0-9a-f]{16}))?/; const PADDING = '0'.repeat(16); @@ -56,7 +56,7 @@ export class B3SinglePropagator implements TextMapPropagator { if ( !spanContext || !isSpanContextValid(spanContext) || - isInstrumentationSuppressed(context) + isTracingSuppressed(context) ) return; diff --git a/packages/opentelemetry-propagator-b3/test/B3MultiPropagator.test.ts b/packages/opentelemetry-propagator-b3/test/B3MultiPropagator.test.ts index a415c226035..d4c828af27c 100644 --- a/packages/opentelemetry-propagator-b3/test/B3MultiPropagator.test.ts +++ b/packages/opentelemetry-propagator-b3/test/B3MultiPropagator.test.ts @@ -20,10 +20,10 @@ import { getSpanContext, setSpanContext, SpanContext, - suppressInstrumentation, TraceFlags, } from '@opentelemetry/api'; import { ROOT_CONTEXT } from '@opentelemetry/api'; +import { suppressTracing } from '@opentelemetry/core'; import * as assert from 'assert'; import { B3MultiPropagator } from '../src/B3MultiPropagator'; import { @@ -147,7 +147,7 @@ describe('B3MultiPropagator', () => { traceFlags: TraceFlags.SAMPLED, }; b3Propagator.inject( - suppressInstrumentation(setSpanContext(ROOT_CONTEXT, spanContext)), + suppressTracing(setSpanContext(ROOT_CONTEXT, spanContext)), carrier, defaultTextMapSetter ); diff --git a/packages/opentelemetry-propagator-b3/test/B3Propagator.test.ts b/packages/opentelemetry-propagator-b3/test/B3Propagator.test.ts index bf0f89ff387..b86ea6e82e7 100644 --- a/packages/opentelemetry-propagator-b3/test/B3Propagator.test.ts +++ b/packages/opentelemetry-propagator-b3/test/B3Propagator.test.ts @@ -14,19 +14,18 @@ * limitations under the License. */ -import * as assert from 'assert'; import { defaultTextMapGetter, defaultTextMapSetter, - SpanContext, - TraceFlags, getSpanContext, - setSpanContext, ROOT_CONTEXT, - suppressInstrumentation, + setSpanContext, + SpanContext, + TraceFlags, } from '@opentelemetry/api'; +import { suppressTracing } from '@opentelemetry/core'; +import * as assert from 'assert'; import { B3Propagator } from '../src/B3Propagator'; -import { B3InjectEncoding } from '../src/types'; import { B3_CONTEXT_HEADER, X_B3_FLAGS, @@ -35,6 +34,7 @@ import { X_B3_SPAN_ID, X_B3_TRACE_ID, } from '../src/constants'; +import { B3InjectEncoding } from '../src/types'; describe('B3Propagator', () => { let propagator: B3Propagator; @@ -100,7 +100,7 @@ describe('B3Propagator', () => { }; propagator.inject( - suppressInstrumentation(setSpanContext(ROOT_CONTEXT, spanContext)), + suppressTracing(setSpanContext(ROOT_CONTEXT, spanContext)), carrier, defaultTextMapSetter ); diff --git a/packages/opentelemetry-propagator-b3/test/B3SinglePropagator.test.ts b/packages/opentelemetry-propagator-b3/test/B3SinglePropagator.test.ts index 4a6a65b8ac5..65f9fda6755 100644 --- a/packages/opentelemetry-propagator-b3/test/B3SinglePropagator.test.ts +++ b/packages/opentelemetry-propagator-b3/test/B3SinglePropagator.test.ts @@ -17,19 +17,19 @@ import { defaultTextMapGetter, defaultTextMapSetter, + getSpanContext, INVALID_SPANID, INVALID_TRACEID, - getSpanContext, + ROOT_CONTEXT, setSpanContext, SpanContext, TraceFlags, - suppressInstrumentation, } from '@opentelemetry/api'; -import { ROOT_CONTEXT } from '@opentelemetry/api'; +import { suppressTracing } from '@opentelemetry/core'; import * as assert from 'assert'; import { B3SinglePropagator } from '../src/B3SinglePropagator'; -import { B3_CONTEXT_HEADER } from '../src/constants'; import { B3_DEBUG_FLAG_KEY } from '../src/common'; +import { B3_CONTEXT_HEADER } from '../src/constants'; describe('B3SinglePropagator', () => { const propagator = new B3SinglePropagator(); @@ -133,7 +133,7 @@ describe('B3SinglePropagator', () => { }; propagator.inject( - suppressInstrumentation(setSpanContext(ROOT_CONTEXT, spanContext)), + suppressTracing(setSpanContext(ROOT_CONTEXT, spanContext)), carrier, defaultTextMapSetter ); diff --git a/packages/opentelemetry-propagator-b3/tsconfig.json b/packages/opentelemetry-propagator-b3/tsconfig.json index bdc94d22137..789e61fc86b 100644 --- a/packages/opentelemetry-propagator-b3/tsconfig.json +++ b/packages/opentelemetry-propagator-b3/tsconfig.json @@ -7,5 +7,10 @@ "include": [ "src/**/*.ts", "test/**/*.ts" + ], + "references": [ + { + "path": "../opentelemetry-core" + } ] } diff --git a/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts b/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts index 7f9daf1ffff..2c713409c3d 100644 --- a/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts +++ b/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts @@ -21,13 +21,13 @@ import { setBaggage, setSpanContext, SpanContext, - TraceFlags, TextMapGetter, TextMapPropagator, TextMapSetter, - isInstrumentationSuppressed, createBaggage, + TraceFlags, } from '@opentelemetry/api'; +import { isTracingSuppressed } from '@opentelemetry/core'; export const UBER_TRACE_ID_HEADER = 'uber-trace-id'; export const UBER_BAGGAGE_HEADER_PREFIX = 'uberctx'; @@ -61,7 +61,7 @@ export class JaegerPropagator implements TextMapPropagator { inject(context: Context, carrier: unknown, setter: TextMapSetter) { const spanContext = getSpanContext(context); const baggage = getBaggage(context); - if (spanContext && isInstrumentationSuppressed(context) === false) { + if (spanContext && isTracingSuppressed(context) === false) { const traceFlags = `0${( spanContext.traceFlags || TraceFlags.NONE ).toString(16)}`; diff --git a/packages/opentelemetry-propagator-jaeger/test/JaegerPropagator.test.ts b/packages/opentelemetry-propagator-jaeger/test/JaegerPropagator.test.ts index e12e6bfc62b..13721f862ea 100644 --- a/packages/opentelemetry-propagator-jaeger/test/JaegerPropagator.test.ts +++ b/packages/opentelemetry-propagator-jaeger/test/JaegerPropagator.test.ts @@ -24,10 +24,10 @@ import { setBaggage, setSpanContext, SpanContext, - suppressInstrumentation, TextMapGetter, TraceFlags, } from '@opentelemetry/api'; +import { suppressTracing } from '@opentelemetry/core'; import * as assert from 'assert'; import { JaegerPropagator, @@ -90,7 +90,7 @@ describe('JaegerPropagator', () => { }; jaegerPropagator.inject( - suppressInstrumentation(setSpanContext(ROOT_CONTEXT, spanContext)), + suppressTracing(setSpanContext(ROOT_CONTEXT, spanContext)), carrier, defaultTextMapSetter ); diff --git a/packages/opentelemetry-tracing/src/Tracer.ts b/packages/opentelemetry-tracing/src/Tracer.ts index e84ebf77b4d..e574f123dee 100644 --- a/packages/opentelemetry-tracing/src/Tracer.ts +++ b/packages/opentelemetry-tracing/src/Tracer.ts @@ -20,6 +20,7 @@ import { InstrumentationLibrary, RandomIdGenerator, sanitizeAttributes, + isTracingSuppressed, } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; import { BasicTracerProvider } from './BasicTracerProvider'; @@ -62,7 +63,7 @@ export class Tracer implements api.Tracer { options: api.SpanOptions = {}, context = api.context.active() ): api.Span { - if (api.isInstrumentationSuppressed(context)) { + if (isTracingSuppressed(context)) { api.diag.debug('Instrumentation suppressed, returning Noop Span'); return api.NOOP_TRACER.startSpan(name, options, context); } diff --git a/packages/opentelemetry-tracing/src/export/BatchSpanProcessor.ts b/packages/opentelemetry-tracing/src/export/BatchSpanProcessor.ts index 29a396bac31..92b596440f8 100644 --- a/packages/opentelemetry-tracing/src/export/BatchSpanProcessor.ts +++ b/packages/opentelemetry-tracing/src/export/BatchSpanProcessor.ts @@ -14,12 +14,13 @@ * limitations under the License. */ -import { context, suppressInstrumentation } from '@opentelemetry/api'; +import { context } from '@opentelemetry/api'; import { ExportResultCode, + getEnv, globalErrorHandler, + suppressTracing, unrefTimer, - getEnv, } from '@opentelemetry/core'; import { Span } from '../Span'; import { SpanProcessor } from '../SpanProcessor'; @@ -144,7 +145,7 @@ export class BatchSpanProcessor implements SpanProcessor { reject(new Error('Timeout')); }, this._exportTimeoutMillis); // prevent downstream exporter calls from generating spans - context.with(suppressInstrumentation(context.active()), () => { + context.with(suppressTracing(context.active()), () => { // Reset the finished spans buffer here because the next invocations of the _flush method // could pass the same finished spans to the exporter if the buffer is cleared // outside of the execution of this callback. diff --git a/packages/opentelemetry-tracing/src/export/SimpleSpanProcessor.ts b/packages/opentelemetry-tracing/src/export/SimpleSpanProcessor.ts index 487ccccea4f..c92b869bad5 100644 --- a/packages/opentelemetry-tracing/src/export/SimpleSpanProcessor.ts +++ b/packages/opentelemetry-tracing/src/export/SimpleSpanProcessor.ts @@ -14,12 +14,16 @@ * limitations under the License. */ -import { context, suppressInstrumentation } from '@opentelemetry/api'; -import { ExportResultCode, globalErrorHandler } from '@opentelemetry/core'; +import { context } from '@opentelemetry/api'; +import { + ExportResultCode, + globalErrorHandler, + suppressTracing, +} from '@opentelemetry/core'; import { Span } from '../Span'; -import { SpanExporter } from './SpanExporter'; import { SpanProcessor } from '../SpanProcessor'; import { ReadableSpan } from './ReadableSpan'; +import { SpanExporter } from './SpanExporter'; /** * An implementation of the {@link SpanProcessor} that converts the {@link Span} @@ -47,7 +51,7 @@ export class SimpleSpanProcessor implements SpanProcessor { } // prevent downstream exporter calls from generating spans - context.with(suppressInstrumentation(context.active()), () => { + context.with(suppressTracing(context.active()), () => { this._exporter.export([span], result => { if (result.code !== ExportResultCode.SUCCESS) { globalErrorHandler( diff --git a/packages/opentelemetry-tracing/test/Tracer.test.ts b/packages/opentelemetry-tracing/test/Tracer.test.ts index cde378b4eb9..7a69c4dbdbb 100644 --- a/packages/opentelemetry-tracing/test/Tracer.test.ts +++ b/packages/opentelemetry-tracing/test/Tracer.test.ts @@ -14,23 +14,23 @@ * limitations under the License. */ -import * as assert from 'assert'; import { + INVALID_TRACEID, + ROOT_CONTEXT, Sampler, SamplingDecision, - TraceFlags, - ROOT_CONTEXT, - suppressInstrumentation, - SpanContext, - INVALID_TRACEID, setSpanContext, + SpanContext, + TraceFlags, } from '@opentelemetry/api'; -import { BasicTracerProvider, Tracer, Span } from '../src'; import { - InstrumentationLibrary, - AlwaysOnSampler, AlwaysOffSampler, + AlwaysOnSampler, + InstrumentationLibrary, + suppressTracing, } from '@opentelemetry/core'; +import * as assert from 'assert'; +import { BasicTracerProvider, Span, Tracer } from '../src'; describe('Tracer', () => { const tracerProvider = new BasicTracerProvider(); @@ -121,8 +121,8 @@ describe('Tracer', () => { assert.strictEqual(lib.version, '0.0.1'); }); - describe('when suppressInstrumentation true', () => { - const context = suppressInstrumentation(ROOT_CONTEXT); + describe('when suppressTracing true', () => { + const context = suppressTracing(ROOT_CONTEXT); it('should return cached no-op span ', done => { const tracer = new Tracer(