From fc823c5c6d340e4d975b02b55a57d9beafc20bb1 Mon Sep 17 00:00:00 2001 From: vladislav-kiva Date: Mon, 27 Jan 2020 18:26:28 +0300 Subject: [PATCH 1/4] feat: decode jaeger header --- .../src/JaegerHttpTraceFormat.ts | 3 ++- .../test/JaegerHttpTraceFormat.test.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTraceFormat.ts b/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTraceFormat.ts index 811c6d9d41..0907bdbe3a 100644 --- a/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTraceFormat.ts +++ b/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTraceFormat.ts @@ -86,7 +86,8 @@ export class JaegerHttpTraceFormat implements HttpTextFormat { * @return {SpanContext} - returns a span context represented by the serializedString. **/ function deserializeSpanContext(serializedString: string): SpanContext | null { - let headers = serializedString.split(':'); + let decoded = decodeURIComponent(serializedString); + let headers = decoded.split(':'); if (headers.length !== 4) { return null; } diff --git a/packages/opentelemetry-propagator-jaeger/test/JaegerHttpTraceFormat.test.ts b/packages/opentelemetry-propagator-jaeger/test/JaegerHttpTraceFormat.test.ts index a81dc92ffa..0a0bd6d228 100644 --- a/packages/opentelemetry-propagator-jaeger/test/JaegerHttpTraceFormat.test.ts +++ b/packages/opentelemetry-propagator-jaeger/test/JaegerHttpTraceFormat.test.ts @@ -88,6 +88,19 @@ describe('JaegerHttpTraceFormat', () => { }); }); + it('should extract context of a sampled span from UTF-8 encoded carrier', () => { + carrier[UBER_TRACE_ID_HEADER] = + 'ac1f3dc3c2c0b06e%3A5ac292c4a11a163e%3Ac086aaa825821068%3A1'; + const extractedSpanContext = jaegerHttpTraceFormat.extract('', carrier); + + assert.deepStrictEqual(extractedSpanContext, { + spanId: '5ac292c4a11a163e', + traceId: 'ac1f3dc3c2c0b06e', + isRemote: true, + traceFlags: TraceFlags.SAMPLED, + }); + }); + it('should use custom header if provided', () => { carrier[customHeader] = 'd4cda95b652f4a1592b449d5929fda1b:6e0c63257de34c92:0:01'; From 7daab7910ec39248ea80d85e912493f35c88e514 Mon Sep 17 00:00:00 2001 From: vladislav-kiva Date: Mon, 27 Jan 2020 18:33:04 +0300 Subject: [PATCH 2/4] fix: gts fix --- .../test/JaegerHttpTraceFormat.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/opentelemetry-propagator-jaeger/test/JaegerHttpTraceFormat.test.ts b/packages/opentelemetry-propagator-jaeger/test/JaegerHttpTraceFormat.test.ts index 0a0bd6d228..02d50f536d 100644 --- a/packages/opentelemetry-propagator-jaeger/test/JaegerHttpTraceFormat.test.ts +++ b/packages/opentelemetry-propagator-jaeger/test/JaegerHttpTraceFormat.test.ts @@ -90,7 +90,7 @@ describe('JaegerHttpTraceFormat', () => { it('should extract context of a sampled span from UTF-8 encoded carrier', () => { carrier[UBER_TRACE_ID_HEADER] = - 'ac1f3dc3c2c0b06e%3A5ac292c4a11a163e%3Ac086aaa825821068%3A1'; + 'ac1f3dc3c2c0b06e%3A5ac292c4a11a163e%3Ac086aaa825821068%3A1'; const extractedSpanContext = jaegerHttpTraceFormat.extract('', carrier); assert.deepStrictEqual(extractedSpanContext, { From cd0ac6b88fdb33dcbcded58d486bf95d5f40d55b Mon Sep 17 00:00:00 2001 From: vladislav-kiva Date: Mon, 27 Jan 2020 18:33:56 +0300 Subject: [PATCH 3/4] fix: use const instead of variables --- .../src/JaegerHttpTraceFormat.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTraceFormat.ts b/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTraceFormat.ts index 0907bdbe3a..bc84816f12 100644 --- a/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTraceFormat.ts +++ b/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTraceFormat.ts @@ -86,8 +86,7 @@ export class JaegerHttpTraceFormat implements HttpTextFormat { * @return {SpanContext} - returns a span context represented by the serializedString. **/ function deserializeSpanContext(serializedString: string): SpanContext | null { - let decoded = decodeURIComponent(serializedString); - let headers = decoded.split(':'); + let headers = decodeURIComponent(serializedString).split(':'); if (headers.length !== 4) { return null; } From 8c6bbacd21f3ce720c7955260d8bfc6d2f3d76e6 Mon Sep 17 00:00:00 2001 From: vladislav-kiva Date: Mon, 27 Jan 2020 18:41:17 +0300 Subject: [PATCH 4/4] fix: use const for headers --- .../src/JaegerHttpTraceFormat.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTraceFormat.ts b/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTraceFormat.ts index bc84816f12..e6d8a4740b 100644 --- a/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTraceFormat.ts +++ b/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTraceFormat.ts @@ -86,7 +86,7 @@ export class JaegerHttpTraceFormat implements HttpTextFormat { * @return {SpanContext} - returns a span context represented by the serializedString. **/ function deserializeSpanContext(serializedString: string): SpanContext | null { - let headers = decodeURIComponent(serializedString).split(':'); + const headers = decodeURIComponent(serializedString).split(':'); if (headers.length !== 4) { return null; }