diff --git a/packages/opentelemetry-exporter-jaeger/src/transform.ts b/packages/opentelemetry-exporter-jaeger/src/transform.ts index fe7eebfe7b0..855722bfbe3 100644 --- a/packages/opentelemetry-exporter-jaeger/src/transform.ts +++ b/packages/opentelemetry-exporter-jaeger/src/transform.ts @@ -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)), @@ -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. */ diff --git a/packages/opentelemetry-exporter-jaeger/test/transform.test.ts b/packages/opentelemetry-exporter-jaeger/test/transform.test.ts index 72fe5985d90..d97b44ccb0b 100644 --- a/packages/opentelemetry-exporter-jaeger/test/transform.test.ts +++ b/packages/opentelemetry-exporter-jaeger/test/transform.test.ts @@ -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;