diff --git a/api/src/api/global-utils.ts b/api/src/api/global-utils.ts index 87791f2817a..297836e009e 100644 --- a/api/src/api/global-utils.ts +++ b/api/src/api/global-utils.ts @@ -65,4 +65,4 @@ export function makeGetter( * version. If the global API is not compatible with the API package * attempting to get it, a NOOP API implementation will be returned. */ -export const API_BACKWARDS_COMPATIBILITY_VERSION = 1; +export const API_BACKWARDS_COMPATIBILITY_VERSION = 2; diff --git a/api/src/trace/NoopTracer.ts b/api/src/trace/NoopTracer.ts index cdc2cbd43d9..f76a73ee548 100644 --- a/api/src/trace/NoopTracer.ts +++ b/api/src/trace/NoopTracer.ts @@ -30,11 +30,14 @@ export class NoopTracer implements Tracer { // startSpan starts a noop span. startSpan(name: string, options?: SpanOptions, context?: Context): Span { - const parent = options?.parent; + const root = Boolean(options?.root); + if (root) { + return NOOP_SPAN; + } + const parentFromContext = context && getActiveSpan(context)?.context(); - if (isSpanContext(parent) && isSpanContextValid(parent)) { - return new NoopSpan(parent); - } else if ( + + if ( isSpanContext(parentFromContext) && isSpanContextValid(parentFromContext) ) { diff --git a/api/src/trace/SpanOptions.ts b/api/src/trace/SpanOptions.ts index e20f243eacc..3c374044ae0 100644 --- a/api/src/trace/SpanOptions.ts +++ b/api/src/trace/SpanOptions.ts @@ -17,8 +17,6 @@ import { Attributes } from './attributes'; import { Link } from './link'; import { SpanKind } from './span_kind'; -import { Span } from './span'; -import { SpanContext } from './span_context'; /** * Options needed for span creation @@ -36,20 +34,9 @@ export interface SpanOptions { /** {@link Link}s span to other spans */ links?: Link[]; - /** - * This option is NOT RECOMMENDED for normal use and should ONLY be used - * if your application manages context manually without the global context - * manager, or you are trying to override the parent extracted from context. - * - * A parent `SpanContext` (or `Span`, for convenience) that the newly-started - * span will be the child of. This overrides the parent span extracted from - * the currently active context. - * - * A null value here should prevent the SDK from extracting a parent from - * the current context, forcing the new span to be a root span. - */ - parent?: Span | SpanContext | null; - /** A manually specified start time for the created `Span` object. */ startTime?: number; + + /** The new span should be a root span. (Ignore parent from context). */ + root?: boolean; } diff --git a/api/test/noop-implementations/noop-tracer.test.ts b/api/test/noop-implementations/noop-tracer.test.ts index 3f68c8a14c9..bfc06b81335 100644 --- a/api/test/noop-implementations/noop-tracer.test.ts +++ b/api/test/noop-implementations/noop-tracer.test.ts @@ -60,19 +60,6 @@ describe('NoopTracer', () => { return patchedFn(); }); - it('should propagate valid spanContext on the span (from parent)', () => { - const tracer = new NoopTracer(); - const parent: SpanContext = { - traceId: 'd4cda95b652f4a1592b449d5929fda1b', - spanId: '6e0c63257de34c92', - traceFlags: TraceFlags.NONE, - }; - const span = tracer.startSpan('test-1', { parent }); - assert(span.context().traceId === parent.traceId); - assert(span.context().spanId === parent.spanId); - assert(span.context().traceFlags === parent.traceFlags); - }); - it('should propagate valid spanContext on the span (from context)', () => { const tracer = new NoopTracer(); const parent: SpanContext = {