Skip to content

Commit a27536e

Browse files
authored
fix: respect isRecordingEvents flag (open-telemetry#180)
1 parent aab5cc1 commit a27536e

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

packages/opentelemetry-basic-tracer/src/BasicTracer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ export class BasicTracer implements types.Tracer {
7777
? TraceOptions.SAMPLED
7878
: TraceOptions.UNSAMPLED;
7979
const spanContext = { traceId, spanId, traceOptions, traceState };
80-
81-
if (!samplingDecision) {
80+
const recordEvents = options.isRecordingEvents || false;
81+
if (!recordEvents && !samplingDecision) {
8282
return new NoRecordingSpan(spanContext);
8383
}
8484

packages/opentelemetry-basic-tracer/test/BasicTracer.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,50 @@ describe('BasicTracer', () => {
167167
assert.deepStrictEqual(context.traceState, undefined);
168168
});
169169

170+
it('Should create real span when not sampled but recording events true', () => {
171+
const tracer = new BasicTracer({
172+
sampler: NEVER_SAMPLER,
173+
scopeManager: new NoopScopeManager(),
174+
});
175+
const span = tracer.startSpan('my-span', { isRecordingEvents: true });
176+
assert.ok(span instanceof Span);
177+
assert.strictEqual(span.context().traceOptions, TraceOptions.UNSAMPLED);
178+
assert.strictEqual(span.isRecordingEvents(), true);
179+
});
180+
181+
it('Should not create real span when not sampled and recording events false', () => {
182+
const tracer = new BasicTracer({
183+
sampler: NEVER_SAMPLER,
184+
scopeManager: new NoopScopeManager(),
185+
});
186+
const span = tracer.startSpan('my-span', { isRecordingEvents: false });
187+
assert.ok(span instanceof NoRecordingSpan);
188+
assert.strictEqual(span.context().traceOptions, TraceOptions.UNSAMPLED);
189+
assert.strictEqual(span.isRecordingEvents(), false);
190+
});
191+
192+
it('Should not create real span when not sampled and no recording events configured', () => {
193+
const tracer = new BasicTracer({
194+
sampler: NEVER_SAMPLER,
195+
scopeManager: new NoopScopeManager(),
196+
});
197+
const span = tracer.startSpan('my-span');
198+
assert.ok(span instanceof NoRecordingSpan);
199+
assert.strictEqual(span.context().traceOptions, TraceOptions.UNSAMPLED);
200+
assert.strictEqual(span.isRecordingEvents(), false);
201+
});
202+
203+
it('Should create real span when sampled and recording events true', () => {
204+
const tracer = new BasicTracer({
205+
sampler: ALWAYS_SAMPLER,
206+
scopeManager: new NoopScopeManager(),
207+
});
208+
const span = tracer.startSpan('my-span', { isRecordingEvents: true });
209+
assert.ok(span instanceof Span);
210+
assert.strictEqual(span.context().traceOptions, TraceOptions.SAMPLED);
211+
assert.strictEqual(span.isRecordingEvents(), true);
212+
});
213+
170214
// @todo: implement
171215
it('should start a Span with always sampling');
172216

0 commit comments

Comments
 (0)