Skip to content

Commit

Permalink
fix(propagator-jaeger): 0-pad span-id to match 16-symbol validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Lagutko committed Dec 29, 2021
1 parent eba315b commit a2ac0ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ function deserializeSpanContext(serializedString: string): SpanContext | null {
return null;
}

const [_traceId, spanId, , flags] = headers;
const [_traceId, _spanId, , flags] = headers;

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;

return { traceId, spanId, isRemote: true, traceFlags };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,21 @@ describe('JaegerPropagator', () => {
assert(typeof firstEntry !== 'undefined');
assert(firstEntry.value === 'one');
});

it('should 0-pad span and trace id from header', () => {
carrier[UBER_TRACE_ID_HEADER] = '4cda95b652f4a1592b449d5929fda1b:e0c63257de34c92:0:01';
const extractedSpanContext = trace.getSpanContext(
jaegerPropagator.extract(
ROOT_CONTEXT,
carrier,
defaultTextMapGetter
)
);

assert.ok(extractedSpanContext);
assert.equal(extractedSpanContext.spanId, '0e0c63257de34c92');
assert.equal(extractedSpanContext.traceId, '04cda95b652f4a1592b449d5929fda1b');
});
});

describe('.fields()', () => {
Expand Down

0 comments on commit a2ac0ee

Please sign in to comment.