Skip to content

Commit

Permalink
chore: remove explicit parent option (open-telemetry#1612)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan committed Feb 18, 2021
1 parent 203389a commit 7161374
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 34 deletions.
2 changes: 1 addition & 1 deletion api/src/api/global-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ export function makeGetter<T>(
* 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;
11 changes: 7 additions & 4 deletions api/src/trace/NoopTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
) {
Expand Down
19 changes: 3 additions & 16 deletions api/src/trace/SpanOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
13 changes: 0 additions & 13 deletions api/test/noop-implementations/noop-tracer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 7161374

Please sign in to comment.