Skip to content

Commit

Permalink
Merge 7511b48 into b442048
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanworner authored Jun 30, 2021
2 parents b442048 + 7511b48 commit 81de1e2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/opentelemetry-propagator-b3/src/B3Propagator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ export class B3Propagator implements TextMapPropagator {
}

extract(context: Context, carrier: unknown, getter: TextMapGetter): Context {
if (getter.get(carrier, B3_CONTEXT_HEADER)) {
const header = getter.get(carrier, B3_CONTEXT_HEADER);
const b3Context = Array.isArray(header) ? header[0] : header;

if (b3Context) {
return this._b3SinglePropagator.extract(context, carrier, getter);
} else {
return this._b3MultiPropagator.extract(context, carrier, getter);
Expand Down
25 changes: 25 additions & 0 deletions packages/opentelemetry-propagator-b3/test/B3Propagator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,31 @@ describe('B3Propagator', () => {
});
});

it('extracts multi header b3 using array getter', () => {
const context = propagator.extract(
ROOT_CONTEXT,
b3MultiCarrier,
{
get(carrier, key) {
if (carrier == null || carrier[key] === undefined) {
return [];
}
return [carrier[key]];
},

keys: defaultTextMapGetter.keys
}
);

const extractedSpanContext = trace.getSpanContext(context);
assert.deepStrictEqual(extractedSpanContext, {
spanId: '6e0c63257de34c92',
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
isRemote: true,
traceFlags: TraceFlags.SAMPLED,
});
});

it('extracts single header over multi', () => {
const context = propagator.extract(
ROOT_CONTEXT,
Expand Down

0 comments on commit 81de1e2

Please sign in to comment.