diff --git a/examples/collector-exporter-node/docker/docker-compose.yaml b/examples/collector-exporter-node/docker/docker-compose.yaml index 3e4355ea23..e93b603c49 100644 --- a/examples/collector-exporter-node/docker/docker-compose.yaml +++ b/examples/collector-exporter-node/docker/docker-compose.yaml @@ -2,7 +2,7 @@ version: "3" services: # Collector collector: - image: otel/opentelemetry-collector:0.12.0 + image: otel/opentelemetry-collector:0.13.0 # image: otel/opentelemetry-collector:latest command: ["--config=/conf/collector-config.yaml", "--log-level=DEBUG"] volumes: diff --git a/packages/opentelemetry-exporter-collector-grpc/test/helper.ts b/packages/opentelemetry-exporter-collector-grpc/test/helper.ts index 3d5abd38de..0607571c9c 100644 --- a/packages/opentelemetry-exporter-collector-grpc/test/helper.ts +++ b/packages/opentelemetry-exporter-collector-grpc/test/helper.ts @@ -34,33 +34,25 @@ const meterProvider = new MeterProvider({ const meter = meterProvider.getMeter('default', '0.0.1'); const traceIdArr = [ - 213, - 253, - 116, - 211, - 199, - 92, - 241, - 237, - 187, - 209, - 239, - 57, - 115, - 141, - 26, - 209, - 222, + 31, + 16, + 8, 220, - 223, - 221, - 253, - 111, - 110, - 252, + 142, + 39, + 14, + 133, + 196, + 10, + 13, + 124, + 57, + 57, + 178, + 120, ]; -const spanIdArr = [229, 237, 116, 239, 110, 181, 127, 174, 31, 107, 157, 222]; -const parentIdArr = [239, 198, 188, 247, 94, 116, 247, 207, 58, 227, 127, 60]; +const spanIdArr = [94, 16, 114, 97, 246, 79, 165, 62]; +const parentIdArr = [120, 168, 145, 80, 152, 134, 67, 136]; export async function mockCounter(): Promise { const name = 'int-counter'; diff --git a/packages/opentelemetry-exporter-collector-proto/test/helper.ts b/packages/opentelemetry-exporter-collector-proto/test/helper.ts index 0217aa130d..0034e3f3ba 100644 --- a/packages/opentelemetry-exporter-collector-proto/test/helper.ts +++ b/packages/opentelemetry-exporter-collector-proto/test/helper.ts @@ -15,6 +15,7 @@ */ import { TraceFlags, ValueType } from '@opentelemetry/api'; +import { hexToBase64 } from '@opentelemetry/core'; import { ReadableSpan } from '@opentelemetry/tracing'; import { Resource } from '@opentelemetry/resources'; import { collectorTypes } from '@opentelemetry/exporter-collector'; @@ -97,11 +98,11 @@ export const mockedReadableSpan: ReadableSpan = { name: 'documentFetch', kind: 0, spanContext: { - traceId: '1f1008dc8e270e85c40a0d7c3939b278', - spanId: '5e107261f64fa53e', + traceId: traceIdHex, + spanId: spanIdHex, traceFlags: TraceFlags.SAMPLED, }, - parentSpanId: '78a8915098864388', + parentSpanId: parentIdHex, startTime: [1574120165, 429803070], endTime: [1574120165, 438688070], ended: true, @@ -110,8 +111,8 @@ export const mockedReadableSpan: ReadableSpan = { links: [ { context: { - traceId: '1f1008dc8e270e85c40a0d7c3939b278', - spanId: '78a8915098864388', + traceId: traceIdHex, + spanId: parentIdHex, }, attributes: { component: 'document-load' }, }, @@ -222,8 +223,8 @@ export function ensureProtoLinksAreCorrect( attributes, [ { - traceId: traceIdHex, - spanId: parentIdHex, + traceId: hexToBase64(traceIdHex), + spanId: hexToBase64(parentIdHex), attributes: [ { key: 'component', @@ -251,11 +252,19 @@ export function ensureProtoSpanIsCorrect( if (span.links) { ensureProtoLinksAreCorrect(span.links); } - assert.deepStrictEqual(span.traceId, traceIdHex, 'traceId is wrong'); - assert.deepStrictEqual(span.spanId, spanIdHex, 'spanId is wrong'); + assert.deepStrictEqual( + span.traceId, + hexToBase64(traceIdHex), + 'traceId is' + ' wrong' + ); + assert.deepStrictEqual( + span.spanId, + hexToBase64(spanIdHex), + 'spanId is' + ' wrong' + ); assert.deepStrictEqual( span.parentSpanId, - parentIdHex, + hexToBase64(parentIdHex), 'parentIdArr is wrong' ); assert.strictEqual(span.name, 'documentFetch', 'name is wrong'); diff --git a/packages/opentelemetry-exporter-collector/src/platform/browser/CollectorTraceExporter.ts b/packages/opentelemetry-exporter-collector/src/platform/browser/CollectorTraceExporter.ts index 0884703cbe..e5826de390 100644 --- a/packages/opentelemetry-exporter-collector/src/platform/browser/CollectorTraceExporter.ts +++ b/packages/opentelemetry-exporter-collector/src/platform/browser/CollectorTraceExporter.ts @@ -35,7 +35,7 @@ export class CollectorTraceExporter convert( spans: ReadableSpan[] ): collectorTypes.opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest { - return toCollectorExportTraceServiceRequest(spans, this); + return toCollectorExportTraceServiceRequest(spans, this, true); } getDefaultUrl(config: CollectorExporterConfigBase) { diff --git a/packages/opentelemetry-exporter-collector/src/platform/node/CollectorTraceExporter.ts b/packages/opentelemetry-exporter-collector/src/platform/node/CollectorTraceExporter.ts index 667c133201..0d5eea66dd 100644 --- a/packages/opentelemetry-exporter-collector/src/platform/node/CollectorTraceExporter.ts +++ b/packages/opentelemetry-exporter-collector/src/platform/node/CollectorTraceExporter.ts @@ -35,7 +35,7 @@ export class CollectorTraceExporter convert( spans: ReadableSpan[] ): collectorTypes.opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest { - return toCollectorExportTraceServiceRequest(spans, this); + return toCollectorExportTraceServiceRequest(spans, this, true); } getDefaultUrl(config: CollectorExporterConfigBase): string { diff --git a/packages/opentelemetry-exporter-collector/src/transform.ts b/packages/opentelemetry-exporter-collector/src/transform.ts index 719ea567a0..ed0d4cdcfa 100644 --- a/packages/opentelemetry-exporter-collector/src/transform.ts +++ b/packages/opentelemetry-exporter-collector/src/transform.ts @@ -133,14 +133,20 @@ export function toCollectorEvents( /** * Converts links * @param span + * @param useHex - if ids should be kept as hex without converting to base64 */ -export function toCollectorLinks( - span: ReadableSpan +function toCollectorLinks( + span: ReadableSpan, + useHex?: boolean ): opentelemetryProto.trace.v1.Span.Link[] { return span.links.map((link: Link) => { const protoLink: opentelemetryProto.trace.v1.Span.Link = { - traceId: link.context.traceId, - spanId: link.context.spanId, + traceId: useHex + ? link.context.traceId + : core.hexToBase64(link.context.traceId), + spanId: useHex + ? link.context.spanId + : core.hexToBase64(link.context.spanId), attributes: toCollectorAttributes(link.attributes || {}), droppedAttributesCount: 0, }; @@ -151,14 +157,24 @@ export function toCollectorLinks( /** * Converts span * @param span + * @param useHex - if ids should be kept as hex without converting to base64 */ export function toCollectorSpan( - span: ReadableSpan + span: ReadableSpan, + useHex?: boolean ): opentelemetryProto.trace.v1.Span { return { - traceId: span.spanContext.traceId, - spanId: span.spanContext.spanId, - parentSpanId: span.parentSpanId ? span.parentSpanId : undefined, + traceId: useHex + ? span.spanContext.traceId + : core.hexToBase64(span.spanContext.traceId), + spanId: useHex + ? span.spanContext.spanId + : core.hexToBase64(span.spanContext.spanId), + parentSpanId: span.parentSpanId + ? useHex + ? span.parentSpanId + : core.hexToBase64(span.parentSpanId) + : undefined, traceState: toCollectorTraceState(span.spanContext.traceState), name: span.name, kind: toCollectorKind(span.kind), @@ -169,7 +185,7 @@ export function toCollectorSpan( events: toCollectorEvents(span.events), droppedEventsCount: 0, status: span.status, - links: toCollectorLinks(span), + links: toCollectorLinks(span, useHex), droppedLinksCount: 0, }; } @@ -224,6 +240,7 @@ export function toCollectorTraceState( * Prepares trace service request to be sent to collector * @param spans spans * @param collectorExporterBase + * @param useHex - if ids should be kept as hex without converting to base64 */ export function toCollectorExportTraceServiceRequest< T extends CollectorExporterConfigBase @@ -233,7 +250,8 @@ export function toCollectorExportTraceServiceRequest< T, ReadableSpan, opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest - > + >, + useHex?: boolean ): opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest { const groupedSpans: Map< Resource, @@ -249,7 +267,11 @@ export function toCollectorExportTraceServiceRequest< ); return { - resourceSpans: toCollectorResourceSpans(groupedSpans, additionalAttributes), + resourceSpans: toCollectorResourceSpans( + groupedSpans, + additionalAttributes, + useHex + ), }; } @@ -283,13 +305,15 @@ export function groupSpansByResourceAndLibrary( * Convert to InstrumentationLibrarySpans * @param instrumentationLibrary * @param spans + * @param useHex - if ids should be kept as hex without converting to base64 */ function toCollectorInstrumentationLibrarySpans( instrumentationLibrary: core.InstrumentationLibrary, - spans: ReadableSpan[] + spans: ReadableSpan[], + useHex?: boolean ): opentelemetryProto.trace.v1.InstrumentationLibrarySpans { return { - spans: spans.map(toCollectorSpan), + spans: spans.map(span => toCollectorSpan(span, useHex)), instrumentationLibrary, }; } @@ -298,10 +322,12 @@ function toCollectorInstrumentationLibrarySpans( * Returns a list of resource spans which will be exported to the collector * @param groupedSpans * @param baseAttributes + * @param useHex - if ids should be kept as hex without converting to base64 */ function toCollectorResourceSpans( groupedSpans: Map>, - baseAttributes: Attributes + baseAttributes: Attributes, + useHex?: boolean ): opentelemetryProto.trace.v1.ResourceSpans[] { return Array.from(groupedSpans, ([resource, libSpans]) => { return { @@ -309,7 +335,11 @@ function toCollectorResourceSpans( instrumentationLibrarySpans: Array.from( libSpans, ([instrumentationLibrary, spans]) => - toCollectorInstrumentationLibrarySpans(instrumentationLibrary, spans) + toCollectorInstrumentationLibrarySpans( + instrumentationLibrary, + spans, + useHex + ) ), }; }); diff --git a/packages/opentelemetry-exporter-collector/test/common/transform.test.ts b/packages/opentelemetry-exporter-collector/test/common/transform.test.ts index a07bd4ec47..f369fb891e 100644 --- a/packages/opentelemetry-exporter-collector/test/common/transform.test.ts +++ b/packages/opentelemetry-exporter-collector/test/common/transform.test.ts @@ -93,8 +93,11 @@ describe('transform', () => { }); describe('toCollectorSpan', () => { - it('should convert span', () => { - ensureSpanIsCorrect(transform.toCollectorSpan(mockedReadableSpan)); + it('should convert span using hex', () => { + ensureSpanIsCorrect(transform.toCollectorSpan(mockedReadableSpan, true)); + }); + it('should convert span using base64', () => { + ensureSpanIsCorrect(transform.toCollectorSpan(mockedReadableSpan), false); }); }); diff --git a/packages/opentelemetry-exporter-collector/test/helper.ts b/packages/opentelemetry-exporter-collector/test/helper.ts index e11257138e..f9f482d29f 100644 --- a/packages/opentelemetry-exporter-collector/test/helper.ts +++ b/packages/opentelemetry-exporter-collector/test/helper.ts @@ -18,7 +18,7 @@ import { TraceFlags, ValueType } from '@opentelemetry/api'; import { ReadableSpan } from '@opentelemetry/tracing'; import { Resource } from '@opentelemetry/resources'; import { MetricRecord, MeterProvider } from '@opentelemetry/metrics'; -import { InstrumentationLibrary } from '@opentelemetry/core'; +import { hexToBase64, InstrumentationLibrary } from '@opentelemetry/core'; import * as assert from 'assert'; import { opentelemetryProto } from '../src/types'; import * as collectorTypes from '../src/types'; @@ -387,14 +387,15 @@ export function ensureAttributesAreCorrect( } export function ensureLinksAreCorrect( - attributes: opentelemetryProto.trace.v1.Span.Link[] + attributes: opentelemetryProto.trace.v1.Span.Link[], + useHex?: boolean ) { assert.deepStrictEqual( attributes, [ { - traceId: traceIdHex, - spanId: parentIdHex, + traceId: useHex ? traceIdHex : hexToBase64(traceIdHex), + spanId: useHex ? parentIdHex : hexToBase64(parentIdHex), attributes: [ { key: 'component', @@ -411,7 +412,8 @@ export function ensureLinksAreCorrect( } export function ensureSpanIsCorrect( - span: collectorTypes.opentelemetryProto.trace.v1.Span + span: collectorTypes.opentelemetryProto.trace.v1.Span, + useHex = true ) { if (span.attributes) { ensureAttributesAreCorrect(span.attributes); @@ -420,13 +422,21 @@ export function ensureSpanIsCorrect( ensureEventsAreCorrect(span.events); } if (span.links) { - ensureLinksAreCorrect(span.links); + ensureLinksAreCorrect(span.links, useHex); } - assert.deepStrictEqual(span.traceId, traceIdHex, 'traceId is wrong'); - assert.deepStrictEqual(span.spanId, spanIdHex, 'spanId is wrong'); + assert.deepStrictEqual( + span.traceId, + useHex ? traceIdHex : hexToBase64(traceIdHex), + 'traceId is' + ' wrong' + ); + assert.deepStrictEqual( + span.spanId, + useHex ? spanIdHex : hexToBase64(spanIdHex), + 'spanId is' + ' wrong' + ); assert.deepStrictEqual( span.parentSpanId, - parentIdHex, + useHex ? parentIdHex : hexToBase64(parentIdHex), 'parentIdArr is wrong' ); assert.strictEqual(span.name, 'documentFetch', 'name is wrong');