Skip to content

Commit

Permalink
fix: respect isRecordingEvents flag (open-telemetry#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 authored Aug 13, 2019
1 parent aab5cc1 commit a27536e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/opentelemetry-basic-tracer/src/BasicTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export class BasicTracer implements types.Tracer {
? TraceOptions.SAMPLED
: TraceOptions.UNSAMPLED;
const spanContext = { traceId, spanId, traceOptions, traceState };

if (!samplingDecision) {
const recordEvents = options.isRecordingEvents || false;
if (!recordEvents && !samplingDecision) {
return new NoRecordingSpan(spanContext);
}

Expand Down
44 changes: 44 additions & 0 deletions packages/opentelemetry-basic-tracer/test/BasicTracer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,50 @@ describe('BasicTracer', () => {
assert.deepStrictEqual(context.traceState, undefined);
});

it('Should create real span when not sampled but recording events true', () => {
const tracer = new BasicTracer({
sampler: NEVER_SAMPLER,
scopeManager: new NoopScopeManager(),
});
const span = tracer.startSpan('my-span', { isRecordingEvents: true });
assert.ok(span instanceof Span);
assert.strictEqual(span.context().traceOptions, TraceOptions.UNSAMPLED);
assert.strictEqual(span.isRecordingEvents(), true);
});

it('Should not create real span when not sampled and recording events false', () => {
const tracer = new BasicTracer({
sampler: NEVER_SAMPLER,
scopeManager: new NoopScopeManager(),
});
const span = tracer.startSpan('my-span', { isRecordingEvents: false });
assert.ok(span instanceof NoRecordingSpan);
assert.strictEqual(span.context().traceOptions, TraceOptions.UNSAMPLED);
assert.strictEqual(span.isRecordingEvents(), false);
});

it('Should not create real span when not sampled and no recording events configured', () => {
const tracer = new BasicTracer({
sampler: NEVER_SAMPLER,
scopeManager: new NoopScopeManager(),
});
const span = tracer.startSpan('my-span');
assert.ok(span instanceof NoRecordingSpan);
assert.strictEqual(span.context().traceOptions, TraceOptions.UNSAMPLED);
assert.strictEqual(span.isRecordingEvents(), false);
});

it('Should create real span when sampled and recording events true', () => {
const tracer = new BasicTracer({
sampler: ALWAYS_SAMPLER,
scopeManager: new NoopScopeManager(),
});
const span = tracer.startSpan('my-span', { isRecordingEvents: true });
assert.ok(span instanceof Span);
assert.strictEqual(span.context().traceOptions, TraceOptions.SAMPLED);
assert.strictEqual(span.isRecordingEvents(), true);
});

// @todo: implement
it('should start a Span with always sampling');

Expand Down

0 comments on commit a27536e

Please sign in to comment.