Skip to content

Commit

Permalink
fix(propagator-jaeger):extract 1 digit traceFlag(0) return 1
Browse files Browse the repository at this point in the history
  • Loading branch information
shmilyoo committed Apr 19, 2022
1 parent f924669 commit 377786b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function deserializeSpanContext(serializedString: string): SpanContext | null {

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;
const traceFlags = flags.match(/^[0-9a-f]{1,2}$/i) ? parseInt(flags) & 1 : 1;

return { traceId, spanId, isRemote: true, traceFlags };
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('JaegerPropagator', () => {
});
});

it('should extract context of a sampled span from carrier with 1 bit flag', () => {
it('should extract context of a sampled span from carrier with 1 bit flag(1)', () => {
carrier[UBER_TRACE_ID_HEADER] =
'9c41e35aeb6d1272:45fd2a9709dadcf1:a13699e3fb724f40:1';
const extractedSpanContext = trace.getSpanContext(
Expand All @@ -174,6 +174,21 @@ describe('JaegerPropagator', () => {
});
});

it("should extract context of a sampled span from carrier with 1 bit flag(0)", () => {
carrier[UBER_TRACE_ID_HEADER] =
"9c41e35aeb6d1272:45fd2a9709dadcf1:a13699e3fb724f40:0";
const extractedSpanContext = trace.getSpanContext(
jaegerPropagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
);

assert.deepStrictEqual(extractedSpanContext, {
spanId: "45fd2a9709dadcf1",
traceId: "00000000000000009c41e35aeb6d1272",
isRemote: true,
traceFlags: TraceFlags.NONE,
});
});

it('should extract context of a sampled span from UTF-8 encoded carrier', () => {
carrier[UBER_TRACE_ID_HEADER] =
'ac1f3dc3c2c0b06e%3A5ac292c4a11a163e%3Ac086aaa825821068%3A1';
Expand Down

0 comments on commit 377786b

Please sign in to comment.