Skip to content

Commit

Permalink
fix: left pad jaeger trace ids (#743)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan committed Feb 18, 2020
1 parent 3d5879a commit d67cb8c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/opentelemetry-exporter-jaeger/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ const DEFAULT_FLAGS = 0x1;
* @param span Span to be translated
*/
export function spanToThrift(span: ReadableSpan): ThriftSpan {
const traceIdHigh = span.spanContext.traceId.slice(0, 16);
const traceIdLow = span.spanContext.traceId.slice(16);
const traceId = span.spanContext.traceId.padStart(32, '0');
const traceIdHigh = traceId.slice(0, 16);
const traceIdLow = traceId.slice(16);
const parentSpan = span.parentSpanId
? Utils.encodeInt64(span.parentSpanId)
: ThriftUtils.emptyBuffer;
Expand Down
32 changes: 32 additions & 0 deletions packages/opentelemetry-exporter-jaeger/test/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,37 @@ describe('transform', () => {
assert.strictEqual(ref1.spanId.toString('hex'), '3e0c63257de34c92');
assert.strictEqual(ref1.refType, ThriftReferenceType.CHILD_OF);
});

it('should left pad trace ids', () => {
const readableSpan: ReadableSpan = {
name: 'my-span1',
kind: types.SpanKind.CLIENT,
spanContext: {
traceId: '92b449d5929fda1b',
spanId: '6e0c63257de34c92',
},
startTime: [1566156729, 709],
endTime: [1566156731, 709],
status: {
code: types.CanonicalCode.DATA_LOSS,
message: 'data loss',
},
attributes: {},
links: [],
events: [],
duration: [32, 800000000],
};

const thriftSpan = spanToThrift(readableSpan);

assert.strictEqual(
thriftSpan.traceIdLow.toString('hex'),
'92b449d5929fda1b'
);
assert.strictEqual(
thriftSpan.traceIdHigh.toString('hex'),
'0000000000000000'
);
});
});
});

0 comments on commit d67cb8c

Please sign in to comment.