Skip to content

Commit b51ea8c

Browse files
logaretmclaude
andcommitted
test(node): Add test verifying startNewTrace respects tracesSampleRate
Ensures TraceFlags.NONE on the remote span context does not cause the sampler to inherit a false sampling decision from the parent. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a02337f commit b51ea8c

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

packages/opentelemetry/test/trace.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,17 @@ describe('startNewTrace', () => {
21572157
});
21582158
});
21592159

2160+
it('allows spans to be sampled based on tracesSampleRate', () => {
2161+
startNewTrace(() => {
2162+
const span = startInactiveSpan({ name: 'sampled-span' });
2163+
// tracesSampleRate is 1 in mockSdkInit, so spans should be sampled
2164+
// This verifies that TraceFlags.NONE on the remote span context does not
2165+
// cause the sampler to inherit a "not sampled" decision from the parent
2166+
expect(spanIsSampled(span)).toBe(true);
2167+
span.end();
2168+
});
2169+
});
2170+
21602171
it('does not leak the new traceId to the outer scope', () => {
21612172
const outerPropagationContext = getCurrentScope().getPropagationContext();
21622173
const outerTraceId = outerPropagationContext.traceId;

0 commit comments

Comments
 (0)