diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e306c715b..b0e23d9807 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,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) @@ -34,6 +35,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 diff --git a/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts b/packages/opentelemetry-propagator-jaeger/src/JaegerPropagator.ts index f41f6adf13..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]{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 }; } diff --git a/packages/opentelemetry-propagator-jaeger/test/JaegerPropagator.test.ts b/packages/opentelemetry-propagator-jaeger/test/JaegerPropagator.test.ts index f0683898bf..1e21e6a218 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';