From ec9aae2cd390cbab5725ddabb0f1e044b7f41415 Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Wed, 22 Apr 2020 11:18:00 -0700 Subject: [PATCH 1/2] fix(B3Propagator): B3 sampled causing gRPC error --- .../src/context/propagation/B3Propagator.ts | 2 +- packages/opentelemetry-core/test/context/B3Propagator.test.ts | 4 ++-- packages/opentelemetry-core/test/context/composite.test.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/opentelemetry-core/src/context/propagation/B3Propagator.ts b/packages/opentelemetry-core/src/context/propagation/B3Propagator.ts index ce68edc3e2..026c1d3ba4 100644 --- a/packages/opentelemetry-core/src/context/propagation/B3Propagator.ts +++ b/packages/opentelemetry-core/src/context/propagation/B3Propagator.ts @@ -57,7 +57,7 @@ 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, String(spanContext.traceFlags)); } } } diff --git a/packages/opentelemetry-core/test/context/B3Propagator.test.ts b/packages/opentelemetry-core/test/context/B3Propagator.test.ts index 1eb6759c16..f403bc72a0 100644 --- a/packages/opentelemetry-core/test/context/B3Propagator.test.ts +++ b/packages/opentelemetry-core/test/context/B3Propagator.test.ts @@ -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', () => { @@ -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', () => { diff --git a/packages/opentelemetry-core/test/context/composite.test.ts b/packages/opentelemetry-core/test/context/composite.test.ts index 10a21af1f3..080b802154 100644 --- a/packages/opentelemetry-core/test/context/composite.test.ts +++ b/packages/opentelemetry-core/test/context/composite.test.ts @@ -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` From 4f267d5414ec7a6bdc75a412fdfbd1ce304d1df7 Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Wed, 22 Apr 2020 11:30:27 -0700 Subject: [PATCH 2/2] fix: review comment --- .../src/context/propagation/B3Propagator.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/opentelemetry-core/src/context/propagation/B3Propagator.ts b/packages/opentelemetry-core/src/context/propagation/B3Propagator.ts index 026c1d3ba4..9a6f38f67d 100644 --- a/packages/opentelemetry-core/src/context/propagation/B3Propagator.ts +++ b/packages/opentelemetry-core/src/context/propagation/B3Propagator.ts @@ -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, String(spanContext.traceFlags)); + setter( + carrier, + X_B3_SAMPLED, + (TraceFlags.SAMPLED & spanContext.traceFlags) === TraceFlags.SAMPLED + ? '1' + : '0' + ); } } }