From 184b19f191635fa8d433eddcc6ed3f7d94a35d8a Mon Sep 17 00:00:00 2001 From: Cedric Ziel Date: Mon, 5 Aug 2024 13:04:24 +0200 Subject: [PATCH] fix(amqplib)!: instrumentation produced high cardinality span names (#2366) * fix: amqplib instrumentation produced high cardinality span names This change amends the amqplib instrumentation so it adheres to span name conventions mentioned here https://opentelemetry.io/docs/specs/semconv/messaging/messaging-spans/#span-name * remove wrong import * fix: add test to assert that operation is publish * add test for span name * use correct queue name * fix: lint * Update plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts * Update plugins/node/instrumentation-amqplib/src/amqplib.ts Co-authored-by: Amir Blum * Update plugins/node/instrumentation-amqplib/src/amqplib.ts * Update plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts * Update amqplib-callbacks.test.ts --------- Co-authored-by: Amir Blum --- .../instrumentation-amqplib/src/amqplib.ts | 27 +++++++++---------- .../test/amqplib-callbacks.test.ts | 1 + 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/plugins/node/instrumentation-amqplib/src/amqplib.ts b/plugins/node/instrumentation-amqplib/src/amqplib.ts index 9b27d3d29c..519bf056f1 100644 --- a/plugins/node/instrumentation-amqplib/src/amqplib.ts +++ b/plugins/node/instrumentation-amqplib/src/amqplib.ts @@ -655,21 +655,18 @@ export class AmqplibInstrumentation extends InstrumentationBase ${routingKey} send`, - { - kind: SpanKind.PRODUCER, - attributes: { - ...channel.connection[CONNECTION_ATTRIBUTES], - [SEMATTRS_MESSAGING_DESTINATION]: exchange, - [SEMATTRS_MESSAGING_DESTINATION_KIND]: - MESSAGINGDESTINATIONKINDVALUES_TOPIC, - [SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY]: routingKey, - [SEMATTRS_MESSAGING_MESSAGE_ID]: options?.messageId, - [SEMATTRS_MESSAGING_CONVERSATION_ID]: options?.correlationId, - }, - } - ); + const span = self.tracer.startSpan(`publish ${normalizedExchange}`, { + kind: SpanKind.PRODUCER, + attributes: { + ...channel.connection[CONNECTION_ATTRIBUTES], + [SEMATTRS_MESSAGING_DESTINATION]: exchange, + [SEMATTRS_MESSAGING_DESTINATION_KIND]: + MESSAGINGDESTINATIONKINDVALUES_TOPIC, + [SEMATTRS_MESSAGING_RABBITMQ_ROUTING_KEY]: routingKey, + [SEMATTRS_MESSAGING_MESSAGE_ID]: options?.messageId, + [SEMATTRS_MESSAGING_CONVERSATION_ID]: options?.correlationId, + }, + }); const modifiedOptions = options ?? {}; modifiedOptions.headers = modifiedOptions.headers ?? {}; diff --git a/plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts b/plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts index a323cebee9..1e415cb084 100644 --- a/plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts +++ b/plugins/node/instrumentation-amqplib/test/amqplib-callbacks.test.ts @@ -136,6 +136,7 @@ describe('amqplib instrumentation callback model', () => { const [publishSpan, consumeSpan] = getTestSpans(); // assert publish span + expect(publishSpan.name).toMatch('publish '); expect(publishSpan.kind).toEqual(SpanKind.PRODUCER); expect(publishSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual( 'rabbitmq'