From 4eb504899de756fc2d223d4e982b19520afc11e6 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Mon, 24 Jan 2022 10:59:01 +0200 Subject: [PATCH 1/3] fix(exporter-jaeger): transform all links to jaeger reference --- .../src/transform.ts | 43 ++++++++----------- .../test/transform.test.ts | 8 +++- tsconfig.json | 20 ++++----- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/packages/opentelemetry-exporter-jaeger/src/transform.ts b/packages/opentelemetry-exporter-jaeger/src/transform.ts index fe7eebfe7b0..e95be340740 100644 --- a/packages/opentelemetry-exporter-jaeger/src/transform.ts +++ b/packages/opentelemetry-exporter-jaeger/src/transform.ts @@ -88,18 +88,16 @@ export function spanToThrift(span: ReadableSpan): ThriftSpan { const spanTags: ThriftTag[] = ThriftUtils.getThriftTags(tags); - const logs = span.events.map( - (event): Log => { - const fields: Tag[] = [{ key: 'event', value: event.name }]; - const attrs = event.attributes; - if (attrs) { - Object.keys(attrs).forEach(attr => - fields.push({ key: attr, value: toTagValue(attrs[attr]) }) - ); - } - return { timestamp: hrTimeToMilliseconds(event.time), fields }; + const logs = span.events.map((event): Log => { + const fields: Tag[] = [{ key: 'event', value: event.name }]; + const attrs = event.attributes; + if (attrs) { + Object.keys(attrs).forEach(attr => + fields.push({ key: attr, value: toTagValue(attrs[attr]) }) + ); } - ); + return { timestamp: hrTimeToMilliseconds(event.time), fields }; + }); const spanLogs: ThriftLog[] = ThriftUtils.getThriftLogs(logs); return { @@ -108,7 +106,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 +118,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; diff --git a/tsconfig.json b/tsconfig.json index 2a2648786c4..e6b6a20a308 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -47,7 +47,7 @@ "path": "packages/exporter-trace-otlp-grpc" }, { - "path": "packages/exporter-trace-otlp-http/tsconfig.all.json" + "path": "packages/exporter-trace-otlp-http" }, { "path": "packages/exporter-trace-otlp-proto" @@ -56,40 +56,40 @@ "path": "packages/opentelemetry-context-async-hooks" }, { - "path": "packages/opentelemetry-context-zone-peer-dep/tsconfig.all.json" + "path": "packages/opentelemetry-context-zone-peer-dep" }, { - "path": "packages/opentelemetry-context-zone/tsconfig.all.json" + "path": "packages/opentelemetry-context-zone" }, { - "path": "packages/opentelemetry-core/tsconfig.all.json" + "path": "packages/opentelemetry-core" }, { "path": "packages/opentelemetry-exporter-jaeger" }, { - "path": "packages/opentelemetry-exporter-zipkin/tsconfig.all.json" + "path": "packages/opentelemetry-exporter-zipkin" }, { - "path": "packages/opentelemetry-propagator-b3/tsconfig.all.json" + "path": "packages/opentelemetry-propagator-b3" }, { "path": "packages/opentelemetry-propagator-jaeger" }, { - "path": "packages/opentelemetry-resources/tsconfig.all.json" + "path": "packages/opentelemetry-resources" }, { - "path": "packages/opentelemetry-sdk-trace-base/tsconfig.all.json" + "path": "packages/opentelemetry-sdk-trace-base" }, { "path": "packages/opentelemetry-sdk-trace-node" }, { - "path": "packages/opentelemetry-sdk-trace-web/tsconfig.all.json" + "path": "packages/opentelemetry-sdk-trace-web" }, { - "path": "packages/opentelemetry-semantic-conventions/tsconfig.all.json" + "path": "packages/opentelemetry-semantic-conventions" }, { "path": "packages/opentelemetry-shim-opentracing" From 46174ae00f33ec6f02fb31e679b8bdfb8087929c Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Mon, 24 Jan 2022 11:33:21 +0200 Subject: [PATCH 2/3] revert(exporter-jaeger): tsconfig --- tsconfig.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index e6b6a20a308..2a2648786c4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -47,7 +47,7 @@ "path": "packages/exporter-trace-otlp-grpc" }, { - "path": "packages/exporter-trace-otlp-http" + "path": "packages/exporter-trace-otlp-http/tsconfig.all.json" }, { "path": "packages/exporter-trace-otlp-proto" @@ -56,40 +56,40 @@ "path": "packages/opentelemetry-context-async-hooks" }, { - "path": "packages/opentelemetry-context-zone-peer-dep" + "path": "packages/opentelemetry-context-zone-peer-dep/tsconfig.all.json" }, { - "path": "packages/opentelemetry-context-zone" + "path": "packages/opentelemetry-context-zone/tsconfig.all.json" }, { - "path": "packages/opentelemetry-core" + "path": "packages/opentelemetry-core/tsconfig.all.json" }, { "path": "packages/opentelemetry-exporter-jaeger" }, { - "path": "packages/opentelemetry-exporter-zipkin" + "path": "packages/opentelemetry-exporter-zipkin/tsconfig.all.json" }, { - "path": "packages/opentelemetry-propagator-b3" + "path": "packages/opentelemetry-propagator-b3/tsconfig.all.json" }, { "path": "packages/opentelemetry-propagator-jaeger" }, { - "path": "packages/opentelemetry-resources" + "path": "packages/opentelemetry-resources/tsconfig.all.json" }, { - "path": "packages/opentelemetry-sdk-trace-base" + "path": "packages/opentelemetry-sdk-trace-base/tsconfig.all.json" }, { "path": "packages/opentelemetry-sdk-trace-node" }, { - "path": "packages/opentelemetry-sdk-trace-web" + "path": "packages/opentelemetry-sdk-trace-web/tsconfig.all.json" }, { - "path": "packages/opentelemetry-semantic-conventions" + "path": "packages/opentelemetry-semantic-conventions/tsconfig.all.json" }, { "path": "packages/opentelemetry-shim-opentracing" From d76403adcc5ad6dcf2697e127fcbb8a58b15fe8d Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Tue, 25 Jan 2022 19:18:53 +0200 Subject: [PATCH 3/3] revert(exporter-jaeger): revert spacing changes --- .../src/transform.ts | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/opentelemetry-exporter-jaeger/src/transform.ts b/packages/opentelemetry-exporter-jaeger/src/transform.ts index e95be340740..855722bfbe3 100644 --- a/packages/opentelemetry-exporter-jaeger/src/transform.ts +++ b/packages/opentelemetry-exporter-jaeger/src/transform.ts @@ -88,16 +88,18 @@ export function spanToThrift(span: ReadableSpan): ThriftSpan { const spanTags: ThriftTag[] = ThriftUtils.getThriftTags(tags); - const logs = span.events.map((event): Log => { - const fields: Tag[] = [{ key: 'event', value: event.name }]; - const attrs = event.attributes; - if (attrs) { - Object.keys(attrs).forEach(attr => - fields.push({ key: attr, value: toTagValue(attrs[attr]) }) - ); + const logs = span.events.map( + (event): Log => { + const fields: Tag[] = [{ key: 'event', value: event.name }]; + const attrs = event.attributes; + if (attrs) { + Object.keys(attrs).forEach(attr => + fields.push({ key: attr, value: toTagValue(attrs[attr]) }) + ); + } + return { timestamp: hrTimeToMilliseconds(event.time), fields }; } - return { timestamp: hrTimeToMilliseconds(event.time), fields }; - }); + ); const spanLogs: ThriftLog[] = ThriftUtils.getThriftLogs(logs); return {