diff --git a/packages/opentelemetry-propagator-jaeger/package.json b/packages/opentelemetry-propagator-jaeger/package.json index 8371c11506a..972f5005900 100644 --- a/packages/opentelemetry-propagator-jaeger/package.json +++ b/packages/opentelemetry-propagator-jaeger/package.json @@ -57,7 +57,7 @@ "karma-mocha": "2.0.1", "karma-spec-reporter": "0.0.32", "karma-webpack": "4.0.2", - "mocha": "6.2.3", + "mocha": "7.2.0", "nyc": "15.1.0", "rimraf": "3.0.2", "sinon": "9.0.2", @@ -70,7 +70,7 @@ "webpack": "4.43.0" }, "dependencies": { - "@opentelemetry/api": "^0.12.0", - "@opentelemetry/core": "^0.12.0" + "@opentelemetry/api": "^0.13.0", + "@opentelemetry/core": "^0.13.0" } } diff --git a/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTracePropagator.ts b/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTracePropagator.ts index 9b3138eb63c..1e69dfefffe 100644 --- a/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTracePropagator.ts +++ b/packages/opentelemetry-propagator-jaeger/src/JaegerHttpTracePropagator.ts @@ -16,13 +16,13 @@ import { Context, - TextMapPropagator, - SpanContext, - TraceFlags, - SetterFunction, - GetterFunction, getParentSpanContext, setExtractedSpanContext, + SpanContext, + TraceFlags, + TextMapGetter, + TextMapPropagator, + TextMapSetter, } from '@opentelemetry/api'; export const UBER_TRACE_ID_HEADER = 'uber-trace-id'; @@ -52,7 +52,7 @@ export class JaegerHttpTracePropagator implements TextMapPropagator { this._jaegerTraceHeader = customTraceHeader || UBER_TRACE_ID_HEADER; } - inject(context: Context, carrier: unknown, setter: SetterFunction) { + inject(context: Context, carrier: unknown, setter: TextMapSetter) { const spanContext = getParentSpanContext(context); if (!spanContext) return; @@ -60,15 +60,15 @@ export class JaegerHttpTracePropagator implements TextMapPropagator { 16 )}`; - setter( + setter.set( carrier, this._jaegerTraceHeader, `${spanContext.traceId}:${spanContext.spanId}:0:${traceFlags}` ); } - extract(context: Context, carrier: unknown, getter: GetterFunction): Context { - const uberTraceIdHeader = getter(carrier, this._jaegerTraceHeader); + extract(context: Context, carrier: unknown, getter: TextMapGetter): Context { + const uberTraceIdHeader = getter.get(carrier, this._jaegerTraceHeader); const uberTraceId = Array.isArray(uberTraceIdHeader) ? uberTraceIdHeader[0] : uberTraceIdHeader; diff --git a/packages/opentelemetry-propagator-jaeger/test/JaegerHttpTracePropagator.test.ts b/packages/opentelemetry-propagator-jaeger/test/JaegerHttpTracePropagator.test.ts index 29503ba4c2a..d7853a9d809 100644 --- a/packages/opentelemetry-propagator-jaeger/test/JaegerHttpTracePropagator.test.ts +++ b/packages/opentelemetry-propagator-jaeger/test/JaegerHttpTracePropagator.test.ts @@ -15,12 +15,13 @@ */ import { - defaultGetter, - defaultSetter, + defaultTextMapGetter, + defaultTextMapSetter, getParentSpanContext, ROOT_CONTEXT, setExtractedSpanContext, SpanContext, + TextMapGetter, TraceFlags, } from '@opentelemetry/api'; import * as assert from 'assert'; @@ -52,7 +53,7 @@ describe('JaegerHttpTracePropagator', () => { jaegerHttpTracePropagator.inject( setExtractedSpanContext(ROOT_CONTEXT, spanContext), carrier, - defaultSetter + defaultTextMapSetter ); assert.deepStrictEqual( carrier[UBER_TRACE_ID_HEADER], @@ -70,7 +71,7 @@ describe('JaegerHttpTracePropagator', () => { customJaegerHttpTracePropagator.inject( setExtractedSpanContext(ROOT_CONTEXT, spanContext), carrier, - defaultSetter + defaultTextMapSetter ); assert.deepStrictEqual( carrier[customHeader], @@ -84,7 +85,11 @@ describe('JaegerHttpTracePropagator', () => { carrier[UBER_TRACE_ID_HEADER] = 'd4cda95b652f4a1592b449d5929fda1b:6e0c63257de34c92:0:01'; const extractedSpanContext = getParentSpanContext( - jaegerHttpTracePropagator.extract(ROOT_CONTEXT, carrier, defaultGetter) + jaegerHttpTracePropagator.extract( + ROOT_CONTEXT, + carrier, + defaultTextMapGetter + ) ); assert.deepStrictEqual(extractedSpanContext, { @@ -99,7 +104,11 @@ describe('JaegerHttpTracePropagator', () => { carrier[UBER_TRACE_ID_HEADER] = '9c41e35aeb6d1272:45fd2a9709dadcf1:a13699e3fb724f40:1'; const extractedSpanContext = getParentSpanContext( - jaegerHttpTracePropagator.extract(ROOT_CONTEXT, carrier, defaultGetter) + jaegerHttpTracePropagator.extract( + ROOT_CONTEXT, + carrier, + defaultTextMapGetter + ) ); assert.deepStrictEqual(extractedSpanContext, { @@ -114,7 +123,11 @@ describe('JaegerHttpTracePropagator', () => { carrier[UBER_TRACE_ID_HEADER] = 'ac1f3dc3c2c0b06e%3A5ac292c4a11a163e%3Ac086aaa825821068%3A1'; const extractedSpanContext = getParentSpanContext( - jaegerHttpTracePropagator.extract(ROOT_CONTEXT, carrier, defaultGetter) + jaegerHttpTracePropagator.extract( + ROOT_CONTEXT, + carrier, + defaultTextMapGetter + ) ); assert.deepStrictEqual(extractedSpanContext, { @@ -132,7 +145,7 @@ describe('JaegerHttpTracePropagator', () => { customJaegerHttpTracePropagator.extract( ROOT_CONTEXT, carrier, - defaultGetter + defaultTextMapGetter ) ); @@ -150,7 +163,7 @@ describe('JaegerHttpTracePropagator', () => { jaegerHttpTracePropagator.extract( ROOT_CONTEXT, carrier, - defaultGetter + defaultTextMapGetter ) ), undefined @@ -164,7 +177,7 @@ describe('JaegerHttpTracePropagator', () => { jaegerHttpTracePropagator.extract( ROOT_CONTEXT, carrier, - defaultGetter + defaultTextMapGetter ) ), undefined @@ -189,17 +202,17 @@ describe('JaegerHttpTracePropagator', () => { const ctx1 = jaegerHttpTracePropagator.extract( ROOT_CONTEXT, carrier, - (c, k) => 1 // not a number + makeGetter(1) // not a number ); const ctx2 = jaegerHttpTracePropagator.extract( ROOT_CONTEXT, carrier, - (c, k) => [] // empty array + makeGetter([]) // empty array ); const ctx3 = jaegerHttpTracePropagator.extract( ROOT_CONTEXT, carrier, - (c, k) => undefined // missing value + makeGetter(undefined) // missing value ); assert.ok(ctx1 === ROOT_CONTEXT); @@ -207,3 +220,18 @@ describe('JaegerHttpTracePropagator', () => { assert.ok(ctx3 === ROOT_CONTEXT); }); }); + +function makeGetter(value: any) { + const getter: TextMapGetter = { + get(carrier, key) { + return value; + }, + keys(carrier) { + if (carrier == null) { + return []; + } + return Object.keys(carrier); + }, + }; + return getter; +}