Skip to content

Commit

Permalink
fix: omit SAMPLED header if sampling decision is absent
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 committed Aug 29, 2019
1 parent d4abab6 commit 0c381ae
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions packages/opentelemetry-core/src/context/propagation/B3Format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ export class B3Format implements HttpTextFormat {
carrier[X_B3_TRACE_ID] = spanContext.traceId;
carrier[X_B3_SPAN_ID] = spanContext.spanId;

if (spanContext.traceOptions === undefined) {
carrier[X_B3_SAMPLED] = TraceOptions.SAMPLED;
} else {
carrier[X_B3_SAMPLED] = Number(
spanContext.traceOptions || TraceOptions.UNSAMPLED
);
// We set the header only if there is an existing sampling decision.
// Otherwise we will omit it => Absent.
if (spanContext.traceOptions !== undefined) {
carrier[X_B3_SAMPLED] = Number(spanContext.traceOptions);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-core/test/context/B3Format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('B3Format', () => {
'd4cda95b652f4a1592b449d5929fda1b'
);
assert.deepStrictEqual(carrier[X_B3_SPAN_ID], '6e0c63257de34c92');
assert.deepStrictEqual(carrier[X_B3_SAMPLED], TraceOptions.SAMPLED);
assert.deepStrictEqual(carrier[X_B3_SAMPLED], undefined);
});
});

Expand Down

0 comments on commit 0c381ae

Please sign in to comment.