Skip to content

Commit

Permalink
chore(todo): add missing span sampling test (#1151)
Browse files Browse the repository at this point in the history
* chore: add missing span sampling test

* chore: add additional sampling test

Co-authored-by: Daniel Dyla <[email protected]>
  • Loading branch information
markwolff and dyladan authored Jun 9, 2020
1 parent a576f3a commit 1af5928
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions packages/opentelemetry-node/test/NodeTracerProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe('NodeTracerProvider', () => {
assert.ok(span);
});

it('should return a default span with no sampling', () => {
it('should return a default span with no sampling (NEVER_SAMPLER)', () => {
provider = new NodeTracerProvider({
sampler: NEVER_SAMPLER,
logger: new NoopLogger(),
Expand All @@ -154,8 +154,46 @@ describe('NodeTracerProvider', () => {
assert.strictEqual(span.isRecording(), false);
});

// @todo: implement
it('should start a Span with always sampling');
it('should start a recording span with always sampling (ALWAYS_SAMPLER)', () => {
provider = new NodeTracerProvider({
sampler: ALWAYS_SAMPLER,
logger: new NoopLogger(),
});
const span = provider.getTracer('default').startSpan('my-span');
assert.ok(span instanceof Span);
assert.strictEqual(span.context().traceFlags, TraceFlags.SAMPLED);
assert.strictEqual(span.isRecording(), true);
});

it('should not sample with ALWAYS_SAMPLER if parent was not sampled', () => {
provider = new NodeTracerProvider({
sampler: ALWAYS_SAMPLER,
logger: new NoopLogger(),
});

const notSampledParent = provider
.getTracer('default')
.startSpan('not-sampled-span', {
parent: {
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
spanId: '6e0c63257de34c92',
traceFlags: TraceFlags.NONE,
},
});
assert.ok(notSampledParent instanceof NoRecordingSpan);
assert.strictEqual(
notSampledParent.context().traceFlags,
TraceFlags.NONE
);
assert.strictEqual(notSampledParent.isRecording(), false);

const span = provider.getTracer('default').startSpan('child-span', {
parent: notSampledParent,
});
assert.ok(span instanceof NoRecordingSpan);
assert.strictEqual(span.context().traceFlags, TraceFlags.NONE);
assert.strictEqual(span.isRecording(), false);
});

it('should set default attributes on span', () => {
const defaultAttributes = {
Expand Down

0 comments on commit 1af5928

Please sign in to comment.