From 377786b82668050736541d27784c3503932deb96 Mon Sep 17 00:00:00 2001 From: shmilyoo Date: Tue, 19 Apr 2022 14:57:50 +0800 Subject: [PATCH 1/4] fix(propagator-jaeger):extract 1 digit traceFlag(0) return 1 --- .../src/JaegerPropagator.ts | 2 +- .../test/JaegerPropagator.test.ts | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts b/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts index f41f6adf13..d43fc20f47 100644 --- a/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts +++ b/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts @@ -145,7 +145,7 @@ function deserializeSpanContext(serializedString: string): SpanContext | null { const traceId = _traceId.padStart(32, '0'); const spanId = _spanId.padStart(16, '0'); - const traceFlags = flags.match(/^[0-9a-f]{2}$/i) ? parseInt(flags) & 1 : 1; + const traceFlags = flags.match(/^[0-9a-f]{1,2}$/i) ? parseInt(flags) & 1 : 1; return { traceId, spanId, isRemote: true, traceFlags }; } diff --git a/packages/opentelemetry-propagator-jaeger/test/JaegerPropagator.test.ts b/packages/opentelemetry-propagator-jaeger/test/JaegerPropagator.test.ts index f0683898bf..aa9c9cc408 100644 --- a/packages/opentelemetry-propagator-jaeger/test/JaegerPropagator.test.ts +++ b/packages/opentelemetry-propagator-jaeger/test/JaegerPropagator.test.ts @@ -159,7 +159,7 @@ describe('JaegerPropagator', () => { }); }); - it('should extract context of a sampled span from carrier with 1 bit flag', () => { + it('should extract context of a sampled span from carrier with 1 bit flag(1)', () => { carrier[UBER_TRACE_ID_HEADER] = '9c41e35aeb6d1272:45fd2a9709dadcf1:a13699e3fb724f40:1'; const extractedSpanContext = trace.getSpanContext( @@ -174,6 +174,21 @@ describe('JaegerPropagator', () => { }); }); + it("should extract context of a sampled span from carrier with 1 bit flag(0)", () => { + carrier[UBER_TRACE_ID_HEADER] = + "9c41e35aeb6d1272:45fd2a9709dadcf1:a13699e3fb724f40:0"; + const extractedSpanContext = trace.getSpanContext( + jaegerPropagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) + ); + + assert.deepStrictEqual(extractedSpanContext, { + spanId: "45fd2a9709dadcf1", + traceId: "00000000000000009c41e35aeb6d1272", + isRemote: true, + traceFlags: TraceFlags.NONE, + }); + }); + it('should extract context of a sampled span from UTF-8 encoded carrier', () => { carrier[UBER_TRACE_ID_HEADER] = 'ac1f3dc3c2c0b06e%3A5ac292c4a11a163e%3Ac086aaa825821068%3A1'; From fbdf59a44ec52d48fe9670ce56cfb0b51a73e555 Mon Sep 17 00:00:00 2001 From: shmilyoo Date: Wed, 20 Apr 2022 09:05:05 +0800 Subject: [PATCH 2/4] update CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58c9a285f2..362c8c9aff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file. * fix: sanitize attributes inputs [#2881](https://github.com/open-telemetry/opentelemetry-js/pull/2881) @legendecas * fix: support earlier API versions [#2892](https://github.com/open-telemetry/opentelemetry-js/pull/2892) @dyladan +* fix: support extract one digit '0' in jaeger traceFlag [#2905](https://github.com/open-telemetry/opentelemetry-js/issues/2905) @shmilyoo ### :books: (Refine Doc) @@ -22,6 +23,8 @@ All notable changes to this project will be documented in this file. * chore: require changelog entry to merge PR [#2847](https://github.com/open-telemetry/opentelemetry-js/pull/2847) @dyladan * chore: remove peer API check [#2892](https://github.com/open-telemetry/opentelemetry-js/pull/2892) @dyladan * chore: merge lerna subdirectories into a single monorepo [#2892](https://github.com/open-telemetry/opentelemetry-js/pull/2892) @dyladan +* `opentelemetry-propagator-jaeger` + * [#2906](https://github.com/open-telemetry/opentelemetry-js/pull/2906) fix: support extract one digit '0' in jaeger traceFlag ([@shmilyoo](https://github.com/shmilyoo)) ## 1.1.1 From 32242674d92d6a797834790e8f0298988d3ce944 Mon Sep 17 00:00:00 2001 From: shmilyoo Date: Wed, 20 Apr 2022 13:43:49 +0800 Subject: [PATCH 3/4] fix quota --- .../test/JaegerPropagator.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/opentelemetry-propagator-jaeger/test/JaegerPropagator.test.ts b/packages/opentelemetry-propagator-jaeger/test/JaegerPropagator.test.ts index aa9c9cc408..1e21e6a218 100644 --- a/packages/opentelemetry-propagator-jaeger/test/JaegerPropagator.test.ts +++ b/packages/opentelemetry-propagator-jaeger/test/JaegerPropagator.test.ts @@ -174,16 +174,16 @@ describe('JaegerPropagator', () => { }); }); - it("should extract context of a sampled span from carrier with 1 bit flag(0)", () => { + it('should extract context of a sampled span from carrier with 1 bit flag(0)', () => { carrier[UBER_TRACE_ID_HEADER] = - "9c41e35aeb6d1272:45fd2a9709dadcf1:a13699e3fb724f40:0"; + '9c41e35aeb6d1272:45fd2a9709dadcf1:a13699e3fb724f40:0'; const extractedSpanContext = trace.getSpanContext( jaegerPropagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); assert.deepStrictEqual(extractedSpanContext, { - spanId: "45fd2a9709dadcf1", - traceId: "00000000000000009c41e35aeb6d1272", + spanId: '45fd2a9709dadcf1', + traceId: '00000000000000009c41e35aeb6d1272', isRemote: true, traceFlags: TraceFlags.NONE, }); From edddbfcb0a27c786323aff30801c4d825829b9b4 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Thu, 21 Apr 2022 08:48:24 -0400 Subject: [PATCH 4/4] Parse jaeger flags with radix 16 Co-authored-by: legendecas --- .../opentelemetry-propagator-jaeger/src/JaegerPropagator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts b/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts index d43fc20f47..93f08e489c 100644 --- a/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts +++ b/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts @@ -145,7 +145,7 @@ function deserializeSpanContext(serializedString: string): SpanContext | null { const traceId = _traceId.padStart(32, '0'); const spanId = _spanId.padStart(16, '0'); - const traceFlags = flags.match(/^[0-9a-f]{1,2}$/i) ? parseInt(flags) & 1 : 1; + const traceFlags = flags.match(/^[0-9a-f]{1,2}$/i) ? parseInt(flags, 16) & 1 : 1; return { traceId, spanId, isRemote: true, traceFlags }; }