From c1d4264a9f5dc755f20456dca239ee7510c92eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerhard=20St=C3=B6bich?= Date: Mon, 21 Dec 2020 16:15:47 +0100 Subject: [PATCH] chore: improve naming of span related context APIs (#1749) --- .../opentelemetry-api/src/context/context.ts | 34 ++++++-------- .../opentelemetry-api/src/trace/NoopTracer.ts | 4 +- .../noop-implementations/noop-tracer.test.ts | 4 +- .../context/propagation/HttpTraceContext.ts | 8 ++-- .../src/trace/sampler/ParentBasedSampler.ts | 4 +- .../test/context/HttpTraceContext.test.ts | 30 ++++++------ .../test/context/composite.test.ts | 10 ++-- .../test/trace/ParentBasedSampler.test.ts | 10 ++-- .../src/http.ts | 4 +- .../test/functionals/http-enable.test.ts | 6 +-- .../test/utils/DummyPropagation.ts | 8 ++-- .../test/NodeTracerProvider.test.ts | 14 ++---- .../opentelemetry-plugin-fetch/src/fetch.ts | 2 +- .../opentelemetry-plugin-http/src/http.ts | 4 +- .../test/functionals/http-enable.test.ts | 6 +-- .../test/utils/DummyPropagation.ts | 8 ++-- .../test/utils/DummyPropagation.ts | 8 ++-- .../src/B3MultiPropagator.ts | 8 ++-- .../src/B3SinglePropagator.ts | 8 ++-- .../test/B3MultiPropagator.test.ts | 46 +++++++++---------- .../test/B3Propagator.test.ts | 14 +++--- .../test/B3SinglePropagator.test.ts | 32 ++++++------- .../src/shim.ts | 8 ++-- packages/opentelemetry-tracing/src/Tracer.ts | 10 ++-- .../test/BasicTracerProvider.test.ts | 16 +++---- .../test/export/InMemorySpanExporter.test.ts | 10 ++-- 26 files changed, 150 insertions(+), 166 deletions(-) diff --git a/packages/opentelemetry-api/src/context/context.ts b/packages/opentelemetry-api/src/context/context.ts index 104e8f5945..4dc2b4c47c 100644 --- a/packages/opentelemetry-api/src/context/context.ts +++ b/packages/opentelemetry-api/src/context/context.ts @@ -18,11 +18,9 @@ import { Context, createContextKey } from '@opentelemetry/context-base'; import { Baggage, NoopSpan, Span, SpanContext } from '../'; /** - * Active span key + * span key */ -const ACTIVE_SPAN_KEY = createContextKey( - 'OpenTelemetry Context Key ACTIVE_SPAN' -); +const SPAN_KEY = createContextKey('OpenTelemetry Context Key SPAN'); /** * Shared key for indicating if instrumentation should be suppressed beyond @@ -38,49 +36,45 @@ const SUPPRESS_INSTRUMENTATION_KEY = createContextKey( const BAGGAGE_KEY = createContextKey('OpenTelemetry Baggage Key'); /** - * Return the active span if one exists + * Return the span if one exists * * @param context context to get span from */ -export function getActiveSpan(context: Context): Span | undefined { - return (context.getValue(ACTIVE_SPAN_KEY) as Span) || undefined; +export function getSpan(context: Context): Span | undefined { + return (context.getValue(SPAN_KEY) as Span) || undefined; } /** - * Set the active span on a context + * Set the span on a context * * @param context context to use as parent * @param span span to set active */ -export function setActiveSpan(context: Context, span: Span): Context { - return context.setValue(ACTIVE_SPAN_KEY, span); +export function setSpan(context: Context, span: Span): Context { + return context.setValue(SPAN_KEY, span); } /** - * Wrap extracted span context in a NoopSpan and set as active span in a new + * Wrap span context in a NoopSpan and set as span in a new * context * * @param context context to set active span on * @param spanContext span context to be wrapped */ -export function setExtractedSpanContext( +export function setSpanContext( context: Context, spanContext: SpanContext ): Context { - return setActiveSpan(context, new NoopSpan(spanContext)); + return setSpan(context, new NoopSpan(spanContext)); } /** - * Get the span context of the parent span if it exists, - * or the extracted span context if there is no active - * span. + * Get the span context of the span if it exists. * * @param context context to get values from */ -export function getParentSpanContext( - context: Context -): SpanContext | undefined { - return getActiveSpan(context)?.context(); +export function getSpanContext(context: Context): SpanContext | undefined { + return getSpan(context)?.context(); } /** diff --git a/packages/opentelemetry-api/src/trace/NoopTracer.ts b/packages/opentelemetry-api/src/trace/NoopTracer.ts index d733c930ea..239db89b22 100644 --- a/packages/opentelemetry-api/src/trace/NoopTracer.ts +++ b/packages/opentelemetry-api/src/trace/NoopTracer.ts @@ -18,7 +18,7 @@ import { Span, SpanOptions, Tracer, SpanContext } from '..'; import { Context } from '@opentelemetry/context-base'; import { NoopSpan, NOOP_SPAN } from './NoopSpan'; import { isSpanContextValid } from './spancontext-utils'; -import { getParentSpanContext } from '../context/context'; +import { getSpanContext } from '../context/context'; /** * No-op implementations of {@link Tracer}. @@ -35,7 +35,7 @@ export class NoopTracer implements Tracer { return NOOP_SPAN; } - const parentFromContext = context && getParentSpanContext(context); + const parentFromContext = context && getSpanContext(context); if ( isSpanContext(parentFromContext) && diff --git a/packages/opentelemetry-api/test/noop-implementations/noop-tracer.test.ts b/packages/opentelemetry-api/test/noop-implementations/noop-tracer.test.ts index bfc06b8133..232428e48d 100644 --- a/packages/opentelemetry-api/test/noop-implementations/noop-tracer.test.ts +++ b/packages/opentelemetry-api/test/noop-implementations/noop-tracer.test.ts @@ -22,7 +22,7 @@ import { SpanKind, TraceFlags, context, - setExtractedSpanContext, + setSpanContext, } from '../../src'; describe('NoopTracer', () => { @@ -70,7 +70,7 @@ describe('NoopTracer', () => { const span = tracer.startSpan( 'test-1', {}, - setExtractedSpanContext(context.active(), parent) + setSpanContext(context.active(), parent) ); assert(span.context().traceId === parent.traceId); assert(span.context().spanId === parent.spanId); diff --git a/packages/opentelemetry-core/src/context/propagation/HttpTraceContext.ts b/packages/opentelemetry-core/src/context/propagation/HttpTraceContext.ts index 9675a864cb..5957b2228d 100644 --- a/packages/opentelemetry-core/src/context/propagation/HttpTraceContext.ts +++ b/packages/opentelemetry-core/src/context/propagation/HttpTraceContext.ts @@ -16,8 +16,8 @@ import { Context, - getParentSpanContext, - setExtractedSpanContext, + getSpanContext, + setSpanContext, SpanContext, TextMapGetter, TextMapPropagator, @@ -86,7 +86,7 @@ export function parseTraceParent(traceParent: string): SpanContext | null { */ export class HttpTraceContext implements TextMapPropagator { inject(context: Context, carrier: unknown, setter: TextMapSetter) { - const spanContext = getParentSpanContext(context); + const spanContext = getSpanContext(context); if (!spanContext) return; const traceParent = `${VERSION}-${spanContext.traceId}-${ @@ -126,7 +126,7 @@ export class HttpTraceContext implements TextMapPropagator { typeof state === 'string' ? state : undefined ); } - return setExtractedSpanContext(context, spanContext); + return setSpanContext(context, spanContext); } fields(): string[] { diff --git a/packages/opentelemetry-core/src/trace/sampler/ParentBasedSampler.ts b/packages/opentelemetry-core/src/trace/sampler/ParentBasedSampler.ts index e0966068c1..eb21a01829 100644 --- a/packages/opentelemetry-core/src/trace/sampler/ParentBasedSampler.ts +++ b/packages/opentelemetry-core/src/trace/sampler/ParentBasedSampler.ts @@ -17,7 +17,7 @@ import { Attributes, Context, - getParentSpanContext, + getSpanContext, Link, Sampler, SamplingResult, @@ -67,7 +67,7 @@ export class ParentBasedSampler implements Sampler { attributes: Attributes, links: Link[] ): SamplingResult { - const parentContext = getParentSpanContext(context); + const parentContext = getSpanContext(context); if (!parentContext) { return this._root.shouldSample( diff --git a/packages/opentelemetry-core/test/context/HttpTraceContext.test.ts b/packages/opentelemetry-core/test/context/HttpTraceContext.test.ts index 44dbb2632f..d0c6148fd5 100644 --- a/packages/opentelemetry-core/test/context/HttpTraceContext.test.ts +++ b/packages/opentelemetry-core/test/context/HttpTraceContext.test.ts @@ -19,8 +19,8 @@ import { defaultTextMapSetter, SpanContext, TraceFlags, - getParentSpanContext, - setExtractedSpanContext, + getSpanContext, + setSpanContext, } from '@opentelemetry/api'; import { ROOT_CONTEXT } from '@opentelemetry/context-base'; import * as assert from 'assert'; @@ -48,7 +48,7 @@ describe('HttpTraceContext', () => { }; httpTraceContext.inject( - setExtractedSpanContext(ROOT_CONTEXT, spanContext), + setSpanContext(ROOT_CONTEXT, spanContext), carrier, defaultTextMapSetter ); @@ -68,7 +68,7 @@ describe('HttpTraceContext', () => { }; httpTraceContext.inject( - setExtractedSpanContext(ROOT_CONTEXT, spanContext), + setSpanContext(ROOT_CONTEXT, spanContext), carrier, defaultTextMapSetter ); @@ -84,7 +84,7 @@ describe('HttpTraceContext', () => { it('should extract context of a sampled span from carrier', () => { carrier[TRACE_PARENT_HEADER] = '00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01'; - const extractedSpanContext = getParentSpanContext( + const extractedSpanContext = getSpanContext( httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); @@ -99,7 +99,7 @@ describe('HttpTraceContext', () => { it('should extract context of a sampled span from carrier using a future version', () => { carrier[TRACE_PARENT_HEADER] = 'cc-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01'; - const extractedSpanContext = getParentSpanContext( + const extractedSpanContext = getSpanContext( httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); @@ -114,7 +114,7 @@ describe('HttpTraceContext', () => { it('should extract context of a sampled span from carrier using a future version and future fields', () => { carrier[TRACE_PARENT_HEADER] = 'cc-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01-what-the-future-will-be-like'; - const extractedSpanContext = getParentSpanContext( + const extractedSpanContext = getSpanContext( httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); @@ -128,7 +128,7 @@ describe('HttpTraceContext', () => { it('returns null if traceparent header is missing', () => { assert.deepStrictEqual( - getParentSpanContext( + getSpanContext( httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ), undefined @@ -138,7 +138,7 @@ describe('HttpTraceContext', () => { it('returns null if traceparent header is invalid', () => { carrier[TRACE_PARENT_HEADER] = 'invalid!'; assert.deepStrictEqual( - getParentSpanContext( + getSpanContext( httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ), undefined @@ -151,7 +151,7 @@ describe('HttpTraceContext', () => { '00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01-extra'; assert.deepStrictEqual( - getParentSpanContext( + getSpanContext( httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ), undefined @@ -162,7 +162,7 @@ describe('HttpTraceContext', () => { carrier[TRACE_PARENT_HEADER] = [ '00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01', ]; - const extractedSpanContext = getParentSpanContext( + const extractedSpanContext = getSpanContext( httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); assert.deepStrictEqual(extractedSpanContext, { @@ -177,7 +177,7 @@ describe('HttpTraceContext', () => { carrier[TRACE_PARENT_HEADER] = '00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01'; carrier[TRACE_STATE_HEADER] = 'foo=bar,baz=qux'; - const extractedSpanContext = getParentSpanContext( + const extractedSpanContext = getSpanContext( httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); @@ -195,7 +195,7 @@ describe('HttpTraceContext', () => { carrier[TRACE_PARENT_HEADER] = '00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01'; carrier[TRACE_STATE_HEADER] = ['foo=bar,baz=qux', 'quux=quuz']; - const extractedSpanContext = getParentSpanContext( + const extractedSpanContext = getSpanContext( httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); assert.deepStrictEqual(extractedSpanContext, { @@ -249,7 +249,7 @@ describe('HttpTraceContext', () => { Object.getOwnPropertyNames(testCases).forEach(testCase => { carrier[TRACE_PARENT_HEADER] = testCases[testCase]; - const extractedSpanContext = getParentSpanContext( + const extractedSpanContext = getSpanContext( httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); assert.deepStrictEqual(extractedSpanContext, undefined, testCase); @@ -260,7 +260,7 @@ describe('HttpTraceContext', () => { carrier[TRACE_PARENT_HEADER] = '00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01'; carrier[TRACE_STATE_HEADER] = 'foo=1 \t , \t bar=2, \t baz=3 '; - const extractedSpanContext = getParentSpanContext( + const extractedSpanContext = getSpanContext( httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); diff --git a/packages/opentelemetry-core/test/context/composite.test.ts b/packages/opentelemetry-core/test/context/composite.test.ts index 9c85ab9eec..e9dfe65f12 100644 --- a/packages/opentelemetry-core/test/context/composite.test.ts +++ b/packages/opentelemetry-core/test/context/composite.test.ts @@ -19,8 +19,8 @@ import { defaultTextMapSetter, TextMapPropagator, SpanContext, - getParentSpanContext, - setExtractedSpanContext, + getSpanContext, + setSpanContext, } from '@opentelemetry/api'; import { Context, ROOT_CONTEXT } from '@opentelemetry/context-base'; import * as assert from 'assert'; @@ -64,7 +64,7 @@ describe('Composite Propagator', () => { traceFlags: 1, traceState: new TraceState('foo=bar'), }; - ctxWithSpanContext = setExtractedSpanContext(ROOT_CONTEXT, spanContext); + ctxWithSpanContext = setSpanContext(ROOT_CONTEXT, spanContext); }); it('should inject context using all configured propagators', () => { @@ -113,7 +113,7 @@ describe('Composite Propagator', () => { const composite = new CompositePropagator({ propagators: [new B3MultiPropagator(), new HttpTraceContext()], }); - const spanContext = getParentSpanContext( + const spanContext = getSpanContext( composite.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); @@ -132,7 +132,7 @@ describe('Composite Propagator', () => { const composite = new CompositePropagator({ propagators: [new ThrowingPropagator(), new HttpTraceContext()], }); - const spanContext = getParentSpanContext( + const spanContext = getSpanContext( composite.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); diff --git a/packages/opentelemetry-core/test/trace/ParentBasedSampler.test.ts b/packages/opentelemetry-core/test/trace/ParentBasedSampler.test.ts index f3af5a2e0c..e6c388ebe7 100644 --- a/packages/opentelemetry-core/test/trace/ParentBasedSampler.test.ts +++ b/packages/opentelemetry-core/test/trace/ParentBasedSampler.test.ts @@ -17,11 +17,7 @@ import * as assert from 'assert'; import * as api from '@opentelemetry/api'; import { AlwaysOnSampler } from '../../src/trace/sampler/AlwaysOnSampler'; import { ParentBasedSampler } from '../../src/trace/sampler/ParentBasedSampler'; -import { - TraceFlags, - SpanKind, - setExtractedSpanContext, -} from '@opentelemetry/api'; +import { TraceFlags, SpanKind, setSpanContext } from '@opentelemetry/api'; import { AlwaysOffSampler } from '../../src/trace/sampler/AlwaysOffSampler'; import { TraceIdRatioBasedSampler } from '../../src'; @@ -62,7 +58,7 @@ describe('ParentBasedSampler', () => { }; assert.deepStrictEqual( sampler.shouldSample( - setExtractedSpanContext(api.ROOT_CONTEXT, spanContext), + setSpanContext(api.ROOT_CONTEXT, spanContext), traceId, spanName, SpanKind.CLIENT, @@ -103,7 +99,7 @@ describe('ParentBasedSampler', () => { }; assert.deepStrictEqual( sampler.shouldSample( - setExtractedSpanContext(api.ROOT_CONTEXT, spanContext), + setSpanContext(api.ROOT_CONTEXT, spanContext), traceId, spanName, SpanKind.CLIENT, diff --git a/packages/opentelemetry-instrumentation-http/src/http.ts b/packages/opentelemetry-instrumentation-http/src/http.ts index 57859d12f3..ffc037b26f 100644 --- a/packages/opentelemetry-instrumentation-http/src/http.ts +++ b/packages/opentelemetry-instrumentation-http/src/http.ts @@ -21,7 +21,7 @@ import { SpanKind, SpanOptions, Status, - setActiveSpan, + setSpan, SpanContext, TraceFlags, ROOT_CONTEXT, @@ -540,7 +540,7 @@ export class HttpInstrumentation extends InstrumentationBase { optionsParsed.headers = {}; } propagation.inject( - setActiveSpan(context.active(), span), + setSpan(context.active(), span), optionsParsed.headers ); diff --git a/packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts b/packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts index 1bcd42616f..38f0a2a8b6 100644 --- a/packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts +++ b/packages/opentelemetry-instrumentation-http/test/functionals/http-enable.test.ts @@ -19,7 +19,7 @@ import { propagation, Span as ISpan, SpanKind, - getActiveSpan, + getSpan, } from '@opentelemetry/api'; import { NoopLogger } from '@opentelemetry/core'; import { NodeTracerProvider } from '@opentelemetry/node'; @@ -695,9 +695,9 @@ describe('HttpInstrumentation', () => { }); it('should not set span as active in context for outgoing request', done => { - assert.deepStrictEqual(getActiveSpan(context.active()), undefined); + assert.deepStrictEqual(getSpan(context.active()), undefined); http.get(`${protocol}://${hostname}:${serverPort}/test`, res => { - assert.deepStrictEqual(getActiveSpan(context.active()), undefined); + assert.deepStrictEqual(getSpan(context.active()), undefined); done(); }); }); diff --git a/packages/opentelemetry-instrumentation-http/test/utils/DummyPropagation.ts b/packages/opentelemetry-instrumentation-http/test/utils/DummyPropagation.ts index 0944e1e199..55d82d25b7 100644 --- a/packages/opentelemetry-instrumentation-http/test/utils/DummyPropagation.ts +++ b/packages/opentelemetry-instrumentation-http/test/utils/DummyPropagation.ts @@ -17,8 +17,8 @@ import { Context, TextMapPropagator, TraceFlags, - getParentSpanContext, - setExtractedSpanContext, + getSpanContext, + setSpanContext, } from '@opentelemetry/api'; import type * as http from 'http'; @@ -33,12 +33,12 @@ export class DummyPropagation implements TextMapPropagator { isRemote: true, }; if (extractedSpanContext.traceId && extractedSpanContext.spanId) { - return setExtractedSpanContext(context, extractedSpanContext); + return setSpanContext(context, extractedSpanContext); } return context; } inject(context: Context, headers: { [custom: string]: string }): void { - const spanContext = getParentSpanContext(context); + const spanContext = getSpanContext(context); if (!spanContext) return; headers[DummyPropagation.TRACE_CONTEXT_KEY] = spanContext.traceId; headers[DummyPropagation.SPAN_CONTEXT_KEY] = spanContext.spanId; diff --git a/packages/opentelemetry-node/test/NodeTracerProvider.test.ts b/packages/opentelemetry-node/test/NodeTracerProvider.test.ts index 5fcc81e1b8..c5de5a4a68 100644 --- a/packages/opentelemetry-node/test/NodeTracerProvider.test.ts +++ b/packages/opentelemetry-node/test/NodeTracerProvider.test.ts @@ -17,8 +17,8 @@ import { context, TraceFlags, - setActiveSpan, - setExtractedSpanContext, + setSpan, + setSpanContext, } from '@opentelemetry/api'; import { AlwaysOnSampler, @@ -168,7 +168,7 @@ describe('NodeTracerProvider', () => { const sampledParent = provider.getTracer('default').startSpan( 'not-sampled-span', {}, - setExtractedSpanContext(ROOT_CONTEXT, { + setSpanContext(ROOT_CONTEXT, { traceId: 'd4cda95b652f4a1592b449d5929fda1b', spanId: '6e0c63257de34c92', traceFlags: TraceFlags.NONE, @@ -183,11 +183,7 @@ describe('NodeTracerProvider', () => { const span = provider .getTracer('default') - .startSpan( - 'child-span', - {}, - setActiveSpan(ROOT_CONTEXT, sampledParent) - ); + .startSpan('child-span', {}, setSpan(ROOT_CONTEXT, sampledParent)); assert.ok(span instanceof Span); assert.strictEqual(span.context().traceFlags, TraceFlags.SAMPLED); assert.strictEqual(span.isRecording(), true); @@ -296,7 +292,7 @@ describe('NodeTracerProvider', () => { ); return done(); }; - const patchedFn = context.bind(fn, setActiveSpan(context.active(), span)); + const patchedFn = context.bind(fn, setSpan(context.active(), span)); return patchedFn(); }); }); diff --git a/packages/opentelemetry-plugin-fetch/src/fetch.ts b/packages/opentelemetry-plugin-fetch/src/fetch.ts index 6d46638ff2..d366c9a356 100644 --- a/packages/opentelemetry-plugin-fetch/src/fetch.ts +++ b/packages/opentelemetry-plugin-fetch/src/fetch.ts @@ -68,7 +68,7 @@ export class FetchPlugin extends core.BasePlugin> { { startTime: corsPreFlightRequest[web.PerformanceTimingNames.FETCH_START], }, - api.setActiveSpan(api.context.active(), span) + api.setSpan(api.context.active(), span) ); web.addSpanNetworkEvents(childSpan, corsPreFlightRequest); childSpan.end( diff --git a/packages/opentelemetry-plugin-http/src/http.ts b/packages/opentelemetry-plugin-http/src/http.ts index ccde0d4a44..a88ce6e348 100644 --- a/packages/opentelemetry-plugin-http/src/http.ts +++ b/packages/opentelemetry-plugin-http/src/http.ts @@ -23,7 +23,7 @@ import { Status, SpanContext, TraceFlags, - setActiveSpan, + setSpan, ROOT_CONTEXT, } from '@opentelemetry/api'; import { BasePlugin, NoRecordingSpan } from '@opentelemetry/core'; @@ -415,7 +415,7 @@ export class HttpPlugin extends BasePlugin { optionsParsed.headers = {}; } propagation.inject( - setActiveSpan(context.active(), span), + setSpan(context.active(), span), optionsParsed.headers ); diff --git a/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts b/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts index c453bbf316..52ed5a4bc3 100644 --- a/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts +++ b/packages/opentelemetry-plugin-http/test/functionals/http-enable.test.ts @@ -19,7 +19,7 @@ import { propagation, Span as ISpan, SpanKind, - getActiveSpan, + getSpan, } from '@opentelemetry/api'; import { NoopLogger } from '@opentelemetry/core'; import { NodeTracerProvider } from '@opentelemetry/node'; @@ -712,9 +712,9 @@ describe('HttpPlugin', () => { }); it('should not set span as active in context for outgoing request', done => { - assert.deepStrictEqual(getActiveSpan(context.active()), undefined); + assert.deepStrictEqual(getSpan(context.active()), undefined); http.get(`${protocol}://${hostname}:${serverPort}/test`, res => { - assert.deepStrictEqual(getActiveSpan(context.active()), undefined); + assert.deepStrictEqual(getSpan(context.active()), undefined); done(); }); }); diff --git a/packages/opentelemetry-plugin-http/test/utils/DummyPropagation.ts b/packages/opentelemetry-plugin-http/test/utils/DummyPropagation.ts index 494062ae8e..d6a700549b 100644 --- a/packages/opentelemetry-plugin-http/test/utils/DummyPropagation.ts +++ b/packages/opentelemetry-plugin-http/test/utils/DummyPropagation.ts @@ -17,8 +17,8 @@ import { Context, TextMapPropagator, TraceFlags, - getParentSpanContext, - setExtractedSpanContext, + getSpanContext, + setSpanContext, } from '@opentelemetry/api'; import * as http from 'http'; @@ -33,12 +33,12 @@ export class DummyPropagation implements TextMapPropagator { isRemote: true, }; if (extractedSpanContext.traceId && extractedSpanContext.spanId) { - return setExtractedSpanContext(context, extractedSpanContext); + return setSpanContext(context, extractedSpanContext); } return context; } inject(context: Context, headers: { [custom: string]: string }): void { - const spanContext = getParentSpanContext(context); + const spanContext = getSpanContext(context); if (!spanContext) return; headers[DummyPropagation.TRACE_CONTEXT_KEY] = spanContext.traceId; headers[DummyPropagation.SPAN_CONTEXT_KEY] = spanContext.spanId; diff --git a/packages/opentelemetry-plugin-https/test/utils/DummyPropagation.ts b/packages/opentelemetry-plugin-https/test/utils/DummyPropagation.ts index ea2a58fb70..4994bf3c94 100644 --- a/packages/opentelemetry-plugin-https/test/utils/DummyPropagation.ts +++ b/packages/opentelemetry-plugin-https/test/utils/DummyPropagation.ts @@ -17,8 +17,8 @@ import { Context, TextMapPropagator, TraceFlags, - setExtractedSpanContext, - getParentSpanContext, + setSpanContext, + getSpanContext, } from '@opentelemetry/api'; import * as http from 'http'; @@ -33,12 +33,12 @@ export class DummyPropagation implements TextMapPropagator { isRemote: true, }; if (extractedSpanContext.traceId && extractedSpanContext.spanId) { - return setExtractedSpanContext(context, extractedSpanContext); + return setSpanContext(context, extractedSpanContext); } return context; } inject(context: Context, headers: { [custom: string]: string }): void { - const spanContext = getParentSpanContext(context); + const spanContext = getSpanContext(context); if (!spanContext) return; headers[DummyPropagation.TRACE_CONTEXT_KEY] = spanContext.traceId; headers[DummyPropagation.SPAN_CONTEXT_KEY] = spanContext.spanId; diff --git a/packages/opentelemetry-propagator-b3/src/B3MultiPropagator.ts b/packages/opentelemetry-propagator-b3/src/B3MultiPropagator.ts index fda32b3545..7f0e414c05 100644 --- a/packages/opentelemetry-propagator-b3/src/B3MultiPropagator.ts +++ b/packages/opentelemetry-propagator-b3/src/B3MultiPropagator.ts @@ -16,11 +16,11 @@ import { Context, - getParentSpanContext, + getSpanContext, isSpanContextValid, isValidSpanId, isValidTraceId, - setExtractedSpanContext, + setSpanContext, TextMapGetter, TextMapPropagator, TextMapSetter, @@ -94,7 +94,7 @@ function getTraceFlags( */ export class B3MultiPropagator implements TextMapPropagator { inject(context: Context, carrier: unknown, setter: TextMapSetter) { - const spanContext = getParentSpanContext(context); + const spanContext = getSpanContext(context); if (!spanContext || !isSpanContextValid(spanContext)) return; const debug = context.getValue(B3_DEBUG_FLAG_KEY); @@ -129,7 +129,7 @@ export class B3MultiPropagator implements TextMapPropagator { isValidSampledValue(traceFlags) ) { context = context.setValue(B3_DEBUG_FLAG_KEY, debug); - return setExtractedSpanContext(context, { + return setSpanContext(context, { traceId, spanId, isRemote: true, diff --git a/packages/opentelemetry-propagator-b3/src/B3SinglePropagator.ts b/packages/opentelemetry-propagator-b3/src/B3SinglePropagator.ts index 5c8a14a78a..91f8d7d00d 100644 --- a/packages/opentelemetry-propagator-b3/src/B3SinglePropagator.ts +++ b/packages/opentelemetry-propagator-b3/src/B3SinglePropagator.ts @@ -16,11 +16,11 @@ import { Context, - getParentSpanContext, + getSpanContext, isSpanContextValid, isValidSpanId, isValidTraceId, - setExtractedSpanContext, + setSpanContext, TextMapGetter, TextMapPropagator, TextMapSetter, @@ -53,7 +53,7 @@ function convertToTraceFlags(samplingState: string | undefined): TraceFlags { */ export class B3SinglePropagator implements TextMapPropagator { inject(context: Context, carrier: unknown, setter: TextMapSetter) { - const spanContext = getParentSpanContext(context); + const spanContext = getSpanContext(context); if (!spanContext || !isSpanContextValid(spanContext)) return; const samplingState = @@ -81,7 +81,7 @@ export class B3SinglePropagator implements TextMapPropagator { context = context.setValue(B3_DEBUG_FLAG_KEY, samplingState); } - return setExtractedSpanContext(context, { + return setSpanContext(context, { traceId, spanId, isRemote: true, diff --git a/packages/opentelemetry-propagator-b3/test/B3MultiPropagator.test.ts b/packages/opentelemetry-propagator-b3/test/B3MultiPropagator.test.ts index f9d76d4e0a..b9f0ae0e0c 100644 --- a/packages/opentelemetry-propagator-b3/test/B3MultiPropagator.test.ts +++ b/packages/opentelemetry-propagator-b3/test/B3MultiPropagator.test.ts @@ -17,8 +17,8 @@ import { defaultTextMapGetter, defaultTextMapSetter, - getParentSpanContext, - setExtractedSpanContext, + getSpanContext, + setSpanContext, SpanContext, TraceFlags, } from '@opentelemetry/api'; @@ -51,7 +51,7 @@ describe('B3MultiPropagator', () => { }; b3Propagator.inject( - setExtractedSpanContext(ROOT_CONTEXT, spanContext), + setSpanContext(ROOT_CONTEXT, spanContext), carrier, defaultTextMapSetter ); @@ -87,7 +87,7 @@ describe('B3MultiPropagator', () => { }; b3Propagator.inject( - setExtractedSpanContext(ROOT_CONTEXT, spanContext), + setSpanContext(ROOT_CONTEXT, spanContext), carrier, defaultTextMapSetter ); @@ -109,7 +109,7 @@ describe('B3MultiPropagator', () => { const contextWithDebug = ROOT_CONTEXT.setValue(B3_DEBUG_FLAG_KEY, '1'); b3Propagator.inject( - setExtractedSpanContext(contextWithDebug, spanContext), + setSpanContext(contextWithDebug, spanContext), carrier, defaultTextMapSetter ); @@ -129,7 +129,7 @@ describe('B3MultiPropagator', () => { traceFlags: TraceFlags.NONE, }; b3Propagator.inject( - setExtractedSpanContext(ROOT_CONTEXT, emptySpanContext), + setSpanContext(ROOT_CONTEXT, emptySpanContext), carrier, defaultTextMapSetter ); @@ -149,7 +149,7 @@ describe('B3MultiPropagator', () => { carrier, defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: 'b7ad6b7169203331', traceId: '0af7651916cd43dd8448eb211c80319c', @@ -170,7 +170,7 @@ describe('B3MultiPropagator', () => { carrier, defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: 'b7ad6b7169203331', @@ -192,7 +192,7 @@ describe('B3MultiPropagator', () => { carrier, defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: 'b7ad6b7169203331', @@ -214,7 +214,7 @@ describe('B3MultiPropagator', () => { carrier, defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: 'b7ad6b7169203331', @@ -238,7 +238,7 @@ describe('B3MultiPropagator', () => { carrier, defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: 'b7ad6b7169203331', @@ -263,7 +263,7 @@ describe('B3MultiPropagator', () => { carrier, defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: 'b7ad6b7169203331', @@ -286,7 +286,7 @@ describe('B3MultiPropagator', () => { carrier, defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: 'b7ad6b7169203331', @@ -309,7 +309,7 @@ describe('B3MultiPropagator', () => { carrier, defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: 'b7ad6b7169203331', @@ -332,7 +332,7 @@ describe('B3MultiPropagator', () => { carrier, defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: 'b7ad6b7169203331', @@ -350,7 +350,7 @@ describe('B3MultiPropagator', () => { it('should return undefined', () => { carrier[X_B3_TRACE_ID] = undefined; carrier[X_B3_SPAN_ID] = 'b7ad6b7169203331'; - const context = getParentSpanContext( + const context = getSpanContext( b3Propagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); assert.deepStrictEqual(context, undefined); @@ -361,7 +361,7 @@ describe('B3MultiPropagator', () => { it('should return undefined', () => { carrier[X_B3_TRACE_ID] = '0af7651916cd43dd8448eb211c80319c'; carrier[X_B3_SPAN_ID] = undefined; - const context = getParentSpanContext( + const context = getSpanContext( b3Propagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); assert.deepStrictEqual(context, undefined); @@ -373,7 +373,7 @@ describe('B3MultiPropagator', () => { carrier[X_B3_TRACE_ID] = '0af7651916cd43dd8448eb211c80319c'; carrier[X_B3_SPAN_ID] = 'b7ad6b7169203331'; carrier[X_B3_SAMPLED] = '2'; - const context = getParentSpanContext( + const context = getSpanContext( b3Propagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); assert.deepStrictEqual(context, undefined); @@ -382,7 +382,7 @@ describe('B3MultiPropagator', () => { describe('AND b3 header is missing', () => { it('should return undefined', () => { - const context = getParentSpanContext( + const context = getSpanContext( b3Propagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); assert.deepStrictEqual(context, undefined); @@ -393,7 +393,7 @@ describe('B3MultiPropagator', () => { it('should return undefined', () => { carrier[X_B3_TRACE_ID] = 'invalid!'; carrier[X_B3_SPAN_ID] = 'b7ad6b7169203331'; - const context = getParentSpanContext( + const context = getSpanContext( b3Propagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); assert.deepStrictEqual(context, undefined); @@ -410,7 +410,7 @@ describe('B3MultiPropagator', () => { carrier, defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: 'b7ad6b7169203331', traceId: '0af7651916cd43dd8448eb211c80319c', @@ -459,7 +459,7 @@ describe('B3MultiPropagator', () => { Object.getOwnPropertyNames(testCases).forEach(testCase => { carrier[X_B3_TRACE_ID] = testCases[testCase]; - const extractedSpanContext = getParentSpanContext( + const extractedSpanContext = getSpanContext( b3Propagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); assert.deepStrictEqual(extractedSpanContext, undefined, testCase); @@ -495,7 +495,7 @@ describe('B3MultiPropagator', () => { carrier, defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: 'b7ad6b7169203331', diff --git a/packages/opentelemetry-propagator-b3/test/B3Propagator.test.ts b/packages/opentelemetry-propagator-b3/test/B3Propagator.test.ts index b010b159b9..eb0aeb303d 100644 --- a/packages/opentelemetry-propagator-b3/test/B3Propagator.test.ts +++ b/packages/opentelemetry-propagator-b3/test/B3Propagator.test.ts @@ -20,8 +20,8 @@ import { defaultTextMapSetter, SpanContext, TraceFlags, - getParentSpanContext, - setExtractedSpanContext, + getSpanContext, + setSpanContext, } from '@opentelemetry/api'; import { ROOT_CONTEXT } from '@opentelemetry/context-base'; import { B3Propagator } from '../src/B3Propagator'; @@ -55,7 +55,7 @@ describe('B3Propagator', () => { }; propagator.inject( - setExtractedSpanContext(ROOT_CONTEXT, spanContext), + setSpanContext(ROOT_CONTEXT, spanContext), carrier, defaultTextMapSetter ); @@ -76,7 +76,7 @@ describe('B3Propagator', () => { }; propagator.inject( - setExtractedSpanContext(ROOT_CONTEXT, spanContext), + setSpanContext(ROOT_CONTEXT, spanContext), carrier, defaultTextMapSetter ); @@ -109,7 +109,7 @@ describe('B3Propagator', () => { defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: 'e457b5a2e4d86bd1', traceId: '80f198ee56343ba864fe8b2a57d3eff7', @@ -125,7 +125,7 @@ describe('B3Propagator', () => { defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: '6e0c63257de34c92', traceId: 'd4cda95b652f4a1592b449d5929fda1b', @@ -141,7 +141,7 @@ describe('B3Propagator', () => { defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: 'e457b5a2e4d86bd1', traceId: '80f198ee56343ba864fe8b2a57d3eff7', diff --git a/packages/opentelemetry-propagator-b3/test/B3SinglePropagator.test.ts b/packages/opentelemetry-propagator-b3/test/B3SinglePropagator.test.ts index a9baa6da54..e02fdae1cb 100644 --- a/packages/opentelemetry-propagator-b3/test/B3SinglePropagator.test.ts +++ b/packages/opentelemetry-propagator-b3/test/B3SinglePropagator.test.ts @@ -19,8 +19,8 @@ import { defaultTextMapSetter, INVALID_SPANID, INVALID_TRACEID, - getParentSpanContext, - setExtractedSpanContext, + getSpanContext, + setSpanContext, SpanContext, TraceFlags, } from '@opentelemetry/api'; @@ -49,7 +49,7 @@ describe('B3SinglePropagator', () => { }; propagator.inject( - setExtractedSpanContext(ROOT_CONTEXT, spanContext), + setSpanContext(ROOT_CONTEXT, spanContext), carrier, defaultTextMapSetter ); @@ -66,7 +66,7 @@ describe('B3SinglePropagator', () => { }; propagator.inject( - setExtractedSpanContext(ROOT_CONTEXT, spanContext), + setSpanContext(ROOT_CONTEXT, spanContext), carrier, defaultTextMapSetter ); @@ -85,7 +85,7 @@ describe('B3SinglePropagator', () => { const context = ROOT_CONTEXT.setValue(B3_DEBUG_FLAG_KEY, 'd'); propagator.inject( - setExtractedSpanContext(context, spanContext), + setSpanContext(context, spanContext), carrier, defaultTextMapSetter ); @@ -102,7 +102,7 @@ describe('B3SinglePropagator', () => { }; propagator.inject( - setExtractedSpanContext(ROOT_CONTEXT, spanContext), + setSpanContext(ROOT_CONTEXT, spanContext), carrier, defaultTextMapSetter ); @@ -118,7 +118,7 @@ describe('B3SinglePropagator', () => { }; propagator.inject( - setExtractedSpanContext(ROOT_CONTEXT, spanContext), + setSpanContext(ROOT_CONTEXT, spanContext), carrier, defaultTextMapSetter ); @@ -140,7 +140,7 @@ describe('B3SinglePropagator', () => { defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: 'e457b5a2e4d86bd1', traceId: '80f198ee56343ba864fe8b2a57d3eff7', @@ -161,7 +161,7 @@ describe('B3SinglePropagator', () => { defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: 'e457b5a2e4d86bd1', traceId: '80f198ee56343ba864fe8b2a57d3eff7', @@ -182,7 +182,7 @@ describe('B3SinglePropagator', () => { defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: 'e457b5a2e4d86bd1', traceId: '80f198ee56343ba864fe8b2a57d3eff7', @@ -202,7 +202,7 @@ describe('B3SinglePropagator', () => { defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: 'e457b5a2e4d86bd1', traceId: '00000000000000004aaba1a52cf8ee09', @@ -223,7 +223,7 @@ describe('B3SinglePropagator', () => { defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(extractedSpanContext, { spanId: 'e457b5a2e4d86bd1', traceId: '80f198ee56343ba864fe8b2a57d3eff7', @@ -244,7 +244,7 @@ describe('B3SinglePropagator', () => { defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(undefined, extractedSpanContext); }); @@ -259,7 +259,7 @@ describe('B3SinglePropagator', () => { defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(undefined, extractedSpanContext); }); @@ -274,7 +274,7 @@ describe('B3SinglePropagator', () => { defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(undefined, extractedSpanContext); }); @@ -289,7 +289,7 @@ describe('B3SinglePropagator', () => { defaultTextMapGetter ); - const extractedSpanContext = getParentSpanContext(context); + const extractedSpanContext = getSpanContext(context); assert.deepStrictEqual(undefined, extractedSpanContext); }); }); diff --git a/packages/opentelemetry-shim-opentracing/src/shim.ts b/packages/opentelemetry-shim-opentracing/src/shim.ts index f24fb4c6a8..3d21b1705f 100644 --- a/packages/opentelemetry-shim-opentracing/src/shim.ts +++ b/packages/opentelemetry-shim-opentracing/src/shim.ts @@ -50,9 +50,9 @@ function translateSpanOptions( function getContextWithParent(options: opentracing.SpanOptions) { if (options.childOf) { if (options.childOf instanceof SpanShim) { - return api.setActiveSpan(api.context.active(), options.childOf.getSpan()); + return api.setSpan(api.context.active(), options.childOf.getSpan()); } else if (options.childOf instanceof SpanContextShim) { - return api.setExtractedSpanContext( + return api.setSpanContext( api.context.active(), options.childOf.getSpanContext() ); @@ -169,7 +169,7 @@ export class TracerShim extends opentracing.Tracer { case opentracing.FORMAT_TEXT_MAP: { api.propagation.inject( api.setBaggage( - api.setExtractedSpanContext(api.ROOT_CONTEXT, oTelSpanContext), + api.setSpanContext(api.ROOT_CONTEXT, oTelSpanContext), oTelSpanBaggage ), carrier @@ -195,7 +195,7 @@ export class TracerShim extends opentracing.Tracer { api.ROOT_CONTEXT, carrier ); - const spanContext = api.getParentSpanContext(context); + const spanContext = api.getSpanContext(context); const baggage = api.getBaggage(context); if (!spanContext) { diff --git a/packages/opentelemetry-tracing/src/Tracer.ts b/packages/opentelemetry-tracing/src/Tracer.ts index db19b66c8a..9cf15e1d3a 100644 --- a/packages/opentelemetry-tracing/src/Tracer.ts +++ b/packages/opentelemetry-tracing/src/Tracer.ts @@ -130,7 +130,7 @@ export class Tracer implements api.Tracer { getCurrentSpan(): api.Span | undefined { const ctx = api.context.active(); // Get the current Span from the context or null if none found. - return api.getActiveSpan(ctx); + return api.getSpan(ctx); } /** @@ -141,7 +141,7 @@ export class Tracer implements api.Tracer { fn: T ): ReturnType { // Set given span to context. - return api.context.with(api.setActiveSpan(api.context.active(), span), fn); + return api.context.with(api.setSpan(api.context.active(), span), fn); } /** @@ -150,9 +150,7 @@ export class Tracer implements api.Tracer { bind(target: T, span?: api.Span): T { return api.context.bind( target, - span - ? api.setActiveSpan(api.context.active(), span) - : api.context.active() + span ? api.setSpan(api.context.active(), span) : api.context.active() ); } @@ -178,5 +176,5 @@ function getParent( context: api.Context ): api.SpanContext | undefined { if (options.root) return undefined; - return api.getParentSpanContext(context); + return api.getSpanContext(context); } diff --git a/packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts b/packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts index fe212d351c..71086c2ddd 100644 --- a/packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts +++ b/packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts @@ -20,8 +20,8 @@ import { TraceFlags, ContextManager, ROOT_CONTEXT, - setActiveSpan, - setExtractedSpanContext, + setSpan, + setSpanContext, } from '@opentelemetry/api'; import { AlwaysOnSampler, @@ -180,7 +180,7 @@ describe('BasicTracerProvider', () => { const span = tracer.startSpan( 'my-span', {}, - setExtractedSpanContext(ROOT_CONTEXT, { + setSpanContext(ROOT_CONTEXT, { traceId: 'd4cda95b652f4a1592b449d5929fda1b', spanId: '6e0c63257de34c92', traceFlags: TraceFlags.SAMPLED, @@ -201,7 +201,7 @@ describe('BasicTracerProvider', () => { const childSpan = tracer.startSpan( 'child-span', {}, - setActiveSpan(ROOT_CONTEXT, span) + setSpan(ROOT_CONTEXT, span) ); const context = childSpan.context(); assert.strictEqual(context.traceId, span.context().traceId); @@ -217,7 +217,7 @@ describe('BasicTracerProvider', () => { const rootSpan = tracer.startSpan( 'root-span', { root: true }, - setActiveSpan(ROOT_CONTEXT, span) + setSpan(ROOT_CONTEXT, span) ); const context = rootSpan.context(); assert.notStrictEqual(context.traceId, overrideParent.context().traceId); @@ -230,7 +230,7 @@ describe('BasicTracerProvider', () => { const span = tracer.startSpan( 'my-span', {}, - setExtractedSpanContext( + setSpanContext( ROOT_CONTEXT, ('invalid-parent' as unknown) as SpanContext ) @@ -244,7 +244,7 @@ describe('BasicTracerProvider', () => { const span = tracer.startSpan( 'my-span', {}, - setExtractedSpanContext(ROOT_CONTEXT, { + setSpanContext(ROOT_CONTEXT, { traceId: '0', spanId: '0', traceFlags: TraceFlags.SAMPLED, @@ -294,7 +294,7 @@ describe('BasicTracerProvider', () => { describe('.getCurrentSpan()', () => { it('should return current span when it exists', () => { context.setGlobalContextManager({ - active: () => setActiveSpan(ROOT_CONTEXT, ('foo' as any) as Span), + active: () => setSpan(ROOT_CONTEXT, ('foo' as any) as Span), disable: () => {}, } as ContextManager); diff --git a/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts b/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts index 0cb9de0e53..3f8c916768 100644 --- a/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts +++ b/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts @@ -20,7 +20,7 @@ import { SimpleSpanProcessor, BasicTracerProvider, } from '../../src'; -import { context, setActiveSpan } from '@opentelemetry/api'; +import { context, setSpan } from '@opentelemetry/api'; import { ExportResult, ExportResultCode } from '@opentelemetry/core'; describe('InMemorySpanExporter', () => { @@ -37,10 +37,10 @@ describe('InMemorySpanExporter', () => { const root = provider.getTracer('default').startSpan('root'); const child = provider .getTracer('default') - .startSpan('child', {}, setActiveSpan(context.active(), root)); + .startSpan('child', {}, setSpan(context.active(), root)); const grandChild = provider .getTracer('default') - .startSpan('grand-child', {}, setActiveSpan(context.active(), child)); + .startSpan('grand-child', {}, setSpan(context.active(), child)); assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); grandChild.end(); @@ -65,7 +65,7 @@ describe('InMemorySpanExporter', () => { provider .getTracer('default') - .startSpan('child', {}, setActiveSpan(context.active(), root)) + .startSpan('child', {}, setSpan(context.active(), root)) .end(); root.end(); assert.strictEqual(memoryExporter.getFinishedSpans().length, 2); @@ -75,7 +75,7 @@ describe('InMemorySpanExporter', () => { // after shutdown no new spans are accepted provider .getTracer('default') - .startSpan('child1', {}, setActiveSpan(context.active(), root)) + .startSpan('child1', {}, setSpan(context.active(), root)) .end(); assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); });