Skip to content

Commit

Permalink
fix(amqplib)!: instrumentation produced high cardinality span names (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>

* 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 <[email protected]>
  • Loading branch information
cedricziel and blumamir authored Aug 5, 2024
1 parent 25e85c7 commit 184b19f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
27 changes: 12 additions & 15 deletions plugins/node/instrumentation-amqplib/src/amqplib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,21 +655,18 @@ export class AmqplibInstrumentation extends InstrumentationBase<AmqplibInstrumen
) {
const normalizedExchange = normalizeExchange(exchange);

const span = self.tracer.startSpan(
`${normalizedExchange} -> ${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 ?? {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ describe('amqplib instrumentation callback model', () => {
const [publishSpan, consumeSpan] = getTestSpans();

// assert publish span
expect(publishSpan.name).toMatch('publish <default>');
expect(publishSpan.kind).toEqual(SpanKind.PRODUCER);
expect(publishSpan.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual(
'rabbitmq'
Expand Down

0 comments on commit 184b19f

Please sign in to comment.