Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(exporter-jaeger): transform all links to jaeger reference #2731

Merged
merged 6 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions packages/opentelemetry-exporter-jaeger/src/transform.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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