Skip to content

Commit

Permalink
fix: use NoRecordingSpan instead of NoopSpan to propagate SpanContext (
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 committed Aug 8, 2019
1 parent 56d4696 commit 10ea2eb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 2 additions & 4 deletions packages/opentelemetry-basic-tracer/src/BasicTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import {
ALWAYS_SAMPLER,
BinaryTraceContext,
HttpTraceContext,
NOOP_SPAN,
randomTraceId,
isValid,
randomSpanId,
NoRecordingSpan,
} from '@opentelemetry/core';
import {
BinaryFormat,
Expand Down Expand Up @@ -79,9 +79,7 @@ export class BasicTracer implements types.Tracer {
const spanContext = { traceId, spanId, traceOptions, traceState };

if (!samplingDecision) {
// TODO: propagate SpanContext, for more information see
// https://github.com/open-telemetry/opentelemetry-js/pull/99#issuecomment-513325536
return NOOP_SPAN;
return new NoRecordingSpan(spanContext);
}

const span = new Span(
Expand Down
11 changes: 8 additions & 3 deletions packages/opentelemetry-basic-tracer/test/BasicTracer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import {
BinaryTraceContext,
HttpTraceContext,
NEVER_SAMPLER,
NOOP_SPAN,
NoopLogger,
TraceState,
NoRecordingSpan,
} from '@opentelemetry/core';
import { BasicTracer } from '../src/BasicTracer';
import { NoopScopeManager } from '@opentelemetry/scope-base';
Expand Down Expand Up @@ -153,13 +153,18 @@ describe('BasicTracer', () => {
assert.deepStrictEqual(context.traceState, undefined);
});

it('should return a default span with no sampling', () => {
it('should return a no recording span when never sampling', () => {
const tracer = new BasicTracer({
sampler: NEVER_SAMPLER,
scopeManager: new NoopScopeManager(),
});
const span = tracer.startSpan('my-span');
assert.deepStrictEqual(span, NOOP_SPAN);
assert.ok(span instanceof NoRecordingSpan);
const context = span.context();
assert.ok(context.traceId.match(/[a-f0-9]{32}/));
assert.ok(context.spanId.match(/[a-f0-9]{16}/));
assert.strictEqual(context.traceOptions, TraceOptions.UNSAMPLED);
assert.deepStrictEqual(context.traceState, undefined);
});

// @todo: implement
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export * from './trace/globaltracer-utils';
export * from './trace/instrumentation/BasePlugin';
export * from './trace/NoopSpan';
export * from './trace/NoopTracer';
export * from './trace/NoRecordingSpan';
export * from './trace/sampler/ProbabilitySampler';
export * from './trace/spancontext-utils';
export * from './trace/TracerDelegate';
Expand Down

0 comments on commit 10ea2eb

Please sign in to comment.