Skip to content

Commit

Permalink
fix(exporter-jaeger): transform all links to jaeger reference (#2731)
Browse files Browse the repository at this point in the history
Co-authored-by: Valentin Marchaud <contact@vmarchaud.fr>
  • Loading branch information
blumamir and vmarchaud committed Jan 31, 2022
1 parent 3231cdc commit a824578
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
23 changes: 9 additions & 14 deletions packages/opentelemetry-exporter-jaeger/src/transform.ts
Expand Up @@ -108,7 +108,7 @@ export function spanToThrift(span: ReadableSpan): ThriftSpan {
spanId: Utils.encodeInt64(span.spanContext().spanId),
parentSpanId: parentSpan,
operationName: span.name,
references: spanLinksToThriftRefs(span.links, span.parentSpanId),
references: spanLinksToThriftRefs(span.links),
flags: span.spanContext().traceFlags || DEFAULT_FLAGS,
startTime: Utils.encodeInt64(hrTimeToMicroseconds(span.startTime)),
duration: Utils.encodeInt64(hrTimeToMicroseconds(span.duration)),
Expand All @@ -120,21 +120,16 @@ export function spanToThrift(span: ReadableSpan): ThriftSpan {
/** Translate OpenTelemetry {@link Link}s to Jaeger ThriftReference. */
function spanLinksToThriftRefs(
links: Link[],
parentSpanId?: string
): ThriftReference[] {
return links
.map((link): ThriftReference | null => {
if (link.context.spanId === parentSpanId) {
const refType = ThriftReferenceType.FOLLOWS_FROM;
const traceId = link.context.traceId;
const traceIdHigh = Utils.encodeInt64(traceId.slice(0, 16));
const traceIdLow = Utils.encodeInt64(traceId.slice(16));
const spanId = Utils.encodeInt64(link.context.spanId);
return { traceIdLow, traceIdHigh, spanId, refType };
}
return null;
})
.filter(ref => !!ref) as ThriftReference[];
.map((link): ThriftReference => {
const refType = ThriftReferenceType.FOLLOWS_FROM;
const traceId = link.context.traceId;
const traceIdHigh = Utils.encodeInt64(traceId.slice(0, 16));
const traceIdLow = Utils.encodeInt64(traceId.slice(16));
const spanId = Utils.encodeInt64(link.context.spanId);
return { traceIdLow, traceIdHigh, spanId, refType };
});
}

/** Translate OpenTelemetry attribute value to Jaeger TagValue. */
Expand Down
Expand Up @@ -129,7 +129,13 @@ describe('transform', () => {
assert.strictEqual(tag7.key, 'cost');
assert.strictEqual(tag7.vType, 'DOUBLE');
assert.strictEqual(tag7.vDouble, 112.12);
assert.strictEqual(thriftSpan.references.length, 0);

assert.strictEqual(thriftSpan.references.length, 1);
const [reference1] = thriftSpan.references;
assert.strictEqual(reference1.refType, ThriftReferenceType.FOLLOWS_FROM);
assert.strictEqual(reference1.spanId.toString('hex'), readableSpan.links[0].context.spanId);
assert.strictEqual(reference1.traceIdLow.toString('hex'), readableSpan.links[0].context.traceId.substring(16, 32));
assert.strictEqual(reference1.traceIdHigh.toString('hex'), readableSpan.links[0].context.traceId.substring(0, 16));

assert.strictEqual(thriftSpan.logs.length, 1);
const [log1] = thriftSpan.logs;
Expand Down

0 comments on commit a824578

Please sign in to comment.