Skip to content

Commit

Permalink
updating to core v.0.13.0 (#277)
Browse files Browse the repository at this point in the history
* chore: updating to core version 0.13.0

* chore: updating main packages to v013

* chore: adding link for todo

* chore: updating cases for status code

* chore: removing not needed function

* chore: fixing status for span

* chore: fixing status for span

* chore: cleanup

* chore: fixing tests
  • Loading branch information
obecny authored and jtmalinowski committed Feb 23, 2021
1 parent bddabd3 commit 6a0f205
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 25 deletions.
6 changes: 3 additions & 3 deletions packages/opentelemetry-propagator-jaeger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -52,23 +52,23 @@ 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;

const traceFlags = `0${(spanContext.traceFlags || TraceFlags.NONE).toString(
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
*/

import {
defaultGetter,
defaultSetter,
defaultTextMapGetter,
defaultTextMapSetter,
getParentSpanContext,
ROOT_CONTEXT,
setExtractedSpanContext,
SpanContext,
TextMapGetter,
TraceFlags,
} from '@opentelemetry/api';
import * as assert from 'assert';
Expand Down Expand Up @@ -52,7 +53,7 @@ describe('JaegerHttpTracePropagator', () => {
jaegerHttpTracePropagator.inject(
setExtractedSpanContext(ROOT_CONTEXT, spanContext),
carrier,
defaultSetter
defaultTextMapSetter
);
assert.deepStrictEqual(
carrier[UBER_TRACE_ID_HEADER],
Expand All @@ -70,7 +71,7 @@ describe('JaegerHttpTracePropagator', () => {
customJaegerHttpTracePropagator.inject(
setExtractedSpanContext(ROOT_CONTEXT, spanContext),
carrier,
defaultSetter
defaultTextMapSetter
);
assert.deepStrictEqual(
carrier[customHeader],
Expand All @@ -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, {
Expand All @@ -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, {
Expand All @@ -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, {
Expand All @@ -132,7 +145,7 @@ describe('JaegerHttpTracePropagator', () => {
customJaegerHttpTracePropagator.extract(
ROOT_CONTEXT,
carrier,
defaultGetter
defaultTextMapGetter
)
);

Expand All @@ -150,7 +163,7 @@ describe('JaegerHttpTracePropagator', () => {
jaegerHttpTracePropagator.extract(
ROOT_CONTEXT,
carrier,
defaultGetter
defaultTextMapGetter
)
),
undefined
Expand All @@ -164,7 +177,7 @@ describe('JaegerHttpTracePropagator', () => {
jaegerHttpTracePropagator.extract(
ROOT_CONTEXT,
carrier,
defaultGetter
defaultTextMapGetter
)
),
undefined
Expand All @@ -189,21 +202,36 @@ 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);
assert.ok(ctx2 === ROOT_CONTEXT);
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;
}

0 comments on commit 6a0f205

Please sign in to comment.