chore: improve naming of span related context APIs (#1749)
This commit is contained in:
parent
7e5da4152d
commit
c1d4264a9f
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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) &&
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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[] {
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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)
|
||||
);
|
||||
|
||||
|
|
|
@ -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)
|
||||
);
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -21,7 +21,7 @@ import {
|
|||
SpanKind,
|
||||
SpanOptions,
|
||||
Status,
|
||||
setActiveSpan,
|
||||
setSpan,
|
||||
SpanContext,
|
||||
TraceFlags,
|
||||
ROOT_CONTEXT,
|
||||
|
@ -540,7 +540,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
|
|||
optionsParsed.headers = {};
|
||||
}
|
||||
propagation.inject(
|
||||
setActiveSpan(context.active(), span),
|
||||
setSpan(context.active(), span),
|
||||
optionsParsed.headers
|
||||
);
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -68,7 +68,7 @@ export class FetchPlugin extends core.BasePlugin<Promise<Response>> {
|
|||
{
|
||||
startTime: corsPreFlightRequest[web.PerformanceTimingNames.FETCH_START],
|
||||
},
|
||||
api.setActiveSpan(api.context.active(), span)
|
||||
api.setSpan(api.context.active(), span)
|
||||
);
|
||||
web.addSpanNetworkEvents(childSpan, corsPreFlightRequest);
|
||||
childSpan.end(
|
||||
|
|
|
@ -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<Http> {
|
|||
optionsParsed.headers = {};
|
||||
}
|
||||
propagation.inject(
|
||||
setActiveSpan(context.active(), span),
|
||||
setSpan(context.active(), span),
|
||||
optionsParsed.headers
|
||||
);
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<T> {
|
||||
// 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<T>(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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue