Skip to content

Commit

Permalink
code review, change the listener convention
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Meunier committed Sep 19, 2024
1 parent 18d6bf6 commit 1e97899
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ public String asString() {
},

/**
* The exchange the listener is plugged to (empty if default exchange).
* The queue the listener is plugged to.
* @since 3.2
*/
EXCHANGE {
DESTINATION_NAME {
@Override
public String asString() {
return "messaging.destination.name";
Expand All @@ -80,16 +80,17 @@ public String asString() {
},

/**
* The routing key the listener is plugged to.
* The delivery tags.
* @since 3.2
*/
ROUTING_KEY {
DELIVERY_TAG {
@Override
public String asString() {
return "messaging.rabbitmq.destination.routing_key";
return "messaging.rabbitmq.message.delivery_tag";
}

}

}

/**
Expand All @@ -105,12 +106,13 @@ public static class DefaultRabbitListenerObservationConvention implements Rabbit

@Override
public KeyValues getLowCardinalityKeyValues(RabbitMessageReceiverContext context) {
final var messageProperties = context.getCarrier().getMessageProperties();
return KeyValues.of(
RabbitListenerObservation.ListenerLowCardinalityTags.LISTENER_ID.asString(), context.getListenerId(),
RabbitListenerObservation.ListenerLowCardinalityTags.EXCHANGE.asString(),
context.getCarrier().getMessageProperties().getReceivedExchange(),
RabbitListenerObservation.ListenerLowCardinalityTags.ROUTING_KEY.asString(),
context.getCarrier().getMessageProperties().getReceivedRoutingKey()
RabbitListenerObservation.ListenerLowCardinalityTags.DESTINATION_NAME.asString(),
messageProperties.getConsumerQueue(),
RabbitListenerObservation.ListenerLowCardinalityTags.DELIVERY_TAG.asString(),
String.valueOf(messageProperties.getDeliveryTag())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public SampleTestRunnerConsumer yourCode() {
.hasTag("messaging.rabbitmq.destination.routing_key", "int.observation.testQ2");
SpanAssert.assertThat(consumerSpans.get(0))
.hasTagWithKey("spring.rabbit.listener.id")
.hasTag("messaging.destination.name", "")
.hasTag("messaging.rabbitmq.destination.routing_key", "int.observation.testQ1");
.hasTag("messaging.destination.name", "int.observation.testQ1")
.hasTag("messaging.rabbitmq.message.delivery_tag", "1");
SpanAssert.assertThat(consumerSpans.get(0))
.hasRemoteServiceNameEqualTo("RabbitMQ");
assertThat(consumerSpans.get(0).getTags().get("spring.rabbit.listener.id")).isIn("obs1", "obs2");
Expand All @@ -97,8 +97,8 @@ public SampleTestRunnerConsumer yourCode() {
assertThat(consumerSpans.get(1).getTags().get("spring.rabbit.listener.id")).isIn("obs1", "obs2");
SpanAssert.assertThat(consumerSpans.get(1))
.hasTagWithKey("spring.rabbit.listener.id")
.hasTag("messaging.destination.name", "")
.hasTag("messaging.rabbitmq.destination.routing_key", "int.observation.testQ2");
.hasTag("messaging.destination.name", "int.observation.testQ2")
.hasTag("messaging.rabbitmq.message.delivery_tag", "1");
assertThat(consumerSpans.get(0).getTags().get("spring.rabbit.listener.id"))
.isNotEqualTo(consumerSpans.get(1).getTags().get("spring.rabbit.listener.id"));

Expand All @@ -120,15 +120,15 @@ public SampleTestRunnerConsumer yourCode() {
.hasTimerWithNameAndTags("spring.rabbit.listener",
KeyValues.of(
KeyValue.of("spring.rabbit.listener.id", "obs1"),
KeyValue.of("messaging.destination.name", ""),
KeyValue.of("messaging.rabbitmq.destination.routing_key", "int.observation.testQ1")
KeyValue.of("messaging.destination.name", "int.observation.testQ1"),
KeyValue.of("messaging.rabbitmq.message.delivery_tag", "1")
)
)
.hasTimerWithNameAndTags("spring.rabbit.listener",
KeyValues.of(
KeyValue.of("spring.rabbit.listener.id", "obs2"),
KeyValue.of("messaging.destination.name", ""),
KeyValue.of("messaging.rabbitmq.destination.routing_key", "int.observation.testQ2")
KeyValue.of("messaging.destination.name", "int.observation.testQ2"),
KeyValue.of("messaging.rabbitmq.message.delivery_tag", "1")
)
);
};
Expand Down

0 comments on commit 1e97899

Please sign in to comment.