Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(todo): add missing span sampling test #1151

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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