Skip to content

Commit 73212b8

Browse files
authored
fix(B3Propagator): B3 sampled causing gRPC error (open-telemetry#977)
* fix(B3Propagator): B3 sampled causing gRPC error * fix: review comment
1 parent 998f3f6 commit 73212b8

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

Diff for: packages/opentelemetry-core/src/context/propagation/B3Propagator.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ export class B3Propagator implements HttpTextPropagator {
5757
// We set the header only if there is an existing sampling decision.
5858
// Otherwise we will omit it => Absent.
5959
if (spanContext.traceFlags !== undefined) {
60-
setter(carrier, X_B3_SAMPLED, Number(spanContext.traceFlags));
60+
setter(
61+
carrier,
62+
X_B3_SAMPLED,
63+
(TraceFlags.SAMPLED & spanContext.traceFlags) === TraceFlags.SAMPLED
64+
? '1'
65+
: '0'
66+
);
6167
}
6268
}
6369
}

Diff for: packages/opentelemetry-core/test/context/B3Propagator.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('B3Propagator', () => {
6060
'd4cda95b652f4a1592b449d5929fda1b'
6161
);
6262
assert.deepStrictEqual(carrier[X_B3_SPAN_ID], '6e0c63257de34c92');
63-
assert.deepStrictEqual(carrier[X_B3_SAMPLED], TraceFlags.SAMPLED);
63+
assert.deepStrictEqual(carrier[X_B3_SAMPLED], '1');
6464
});
6565

6666
it('should set b3 traceId and spanId headers - ignore tracestate', () => {
@@ -82,7 +82,7 @@ describe('B3Propagator', () => {
8282
'd4cda95b652f4a1592b449d5929fda1b'
8383
);
8484
assert.deepStrictEqual(carrier[X_B3_SPAN_ID], '6e0c63257de34c92');
85-
assert.deepStrictEqual(carrier[X_B3_SAMPLED], TraceFlags.NONE);
85+
assert.deepStrictEqual(carrier[X_B3_SAMPLED], '0');
8686
});
8787

8888
it('should not inject empty spancontext', () => {

Diff for: packages/opentelemetry-core/test/context/composite.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('Composite Propagator', () => {
8080

8181
assert.strictEqual(carrier[X_B3_TRACE_ID], traceId);
8282
assert.strictEqual(carrier[X_B3_SPAN_ID], spanId);
83-
assert.strictEqual(carrier[X_B3_SAMPLED], 1);
83+
assert.strictEqual(carrier[X_B3_SAMPLED], '1');
8484
assert.strictEqual(
8585
carrier[TRACE_PARENT_HEADER],
8686
`00-${traceId}-${spanId}-01`

0 commit comments

Comments
 (0)