Skip to content

Commit

Permalink
fix(B3Propagator): B3 sampled causing gRPC error (#977)
Browse files Browse the repository at this point in the history
* fix(B3Propagator): B3 sampled causing gRPC error

* fix: review comment
  • Loading branch information
mayurkale22 authored Apr 23, 2020
1 parent 998f3f6 commit 73212b8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ export class B3Propagator implements HttpTextPropagator {
// We set the header only if there is an existing sampling decision.
// Otherwise we will omit it => Absent.
if (spanContext.traceFlags !== undefined) {
setter(carrier, X_B3_SAMPLED, Number(spanContext.traceFlags));
setter(
carrier,
X_B3_SAMPLED,
(TraceFlags.SAMPLED & spanContext.traceFlags) === TraceFlags.SAMPLED
? '1'
: '0'
);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-core/test/context/B3Propagator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('B3Propagator', () => {
'd4cda95b652f4a1592b449d5929fda1b'
);
assert.deepStrictEqual(carrier[X_B3_SPAN_ID], '6e0c63257de34c92');
assert.deepStrictEqual(carrier[X_B3_SAMPLED], TraceFlags.SAMPLED);
assert.deepStrictEqual(carrier[X_B3_SAMPLED], '1');
});

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

it('should not inject empty spancontext', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-core/test/context/composite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('Composite Propagator', () => {

assert.strictEqual(carrier[X_B3_TRACE_ID], traceId);
assert.strictEqual(carrier[X_B3_SPAN_ID], spanId);
assert.strictEqual(carrier[X_B3_SAMPLED], 1);
assert.strictEqual(carrier[X_B3_SAMPLED], '1');
assert.strictEqual(
carrier[TRACE_PARENT_HEADER],
`00-${traceId}-${spanId}-01`
Expand Down

0 comments on commit 73212b8

Please sign in to comment.