OpenTracing Spring RabbitMQ

January 30, 2022 · View on GitHub

maintenance-status No Maintenance Intended Build Status Released Version

OpenTracing Spring RabbitMQ

Provides message tracing for RabbitMQ through Spring AMQP. It can be used with any OpenTracing compatible implementation.

Compatibility table

VersionOpenTracing APISpring Boot version
0.x.x0.31.01.5.x
1.x.x0.31.02.1.x
1.0.20.32.02.1.x
2.0.x0.32.02.1.x
3.0.x0.33.02.1.x

Sent messages

The following methods are instrumented:

ClassMethodInstrumented
AmqpTemplatevoid send(Message message)
AmqpTemplatevoid send(String routingKey, Message message)
AmqpTemplatevoid send(String exchange, String routingKey, Message message)
AmqpTemplatevoid convertAndSend(Object message)
AmqpTemplatevoid convertAndSend(String routingKey, Object message)
AmqpTemplatevoid convertAndSend(String exchange, String routingKey, Object message)
AmqpTemplatevoid convertAndSend(Object message, MessagePostProcessor messagePostProcessor)
AmqpTemplatevoid convertAndSend(String routingKey, Object message, MessagePostProcessor messagePostProcessor)
AmqpTemplatevoid convertAndSend(String exchange, String routingKey, Object message, MessagePostProcessor messagePostProcessor)
AmqpTemplatevoid convertAndSend(String exchange, String routingKey, Object message, @Nullable CorrelationData correlationData)
AmqpTemplateMessage sendAndReceive(Message message)
AmqpTemplateMessage sendAndReceive(String routingKey, Message message)
AmqpTemplateMessage sendAndReceive(String exchange, String routingKey, Message message)
AmqpTemplateObject convertSendAndReceive(Object message)
AmqpTemplateObject convertSendAndReceive(String routingKey, Object message)
AmqpTemplateObject convertSendAndReceive(String exchange, String routingKey, Object message)
AmqpTemplateObject convertSendAndReceive(Object message, MessagePostProcessor messagePostProcessor)
AmqpTemplateObject convertSendAndReceive(String routingKey, Object message, MessagePostProcessor messagePostProcessor)
AmqpTemplateObject convertSendAndReceive(String exchange, String routingKey, Object message, MessagePostProcessor messagePostProcessor)
AmqpTemplate<T> T convertSendAndReceiveAsType(Object message, ParameterizedTypeReference<T> responseType)
AmqpTemplate<T> T convertSendAndReceiveAsType(String routingKey, Object message,ParameterizedTypeReference<T> responseType)
AmqpTemplate<T> T convertSendAndReceiveAsType(String routingKey, Object message, MessagePostProcessor messagePostProcessor, ParameterizedTypeReference<T> responseType)
AmqpTemplate<T> T convertSendAndReceiveAsType(String exchange, String routingKey, Object message,MessagePostProcessor messagePostProcessor, ParameterizedTypeReference<T> responseType)
RabbitTemplateMessage sendAndReceive(final String exchange, final String routingKey, final Message message, @Nullable CorrelationData correlationData)
RabbitTemplateObject convertSendAndReceive(final String exchange, final String routingKey, final Object message, @Nullable CorrelationData correlationData)

Received messages

At startup a RabbitMqReceiveTracingInterceptor, will be added toSimpleMessageListenerContainer or DirectMessageListenerContaineradvice chain, depending on your configuration.

@RabbitListener will also benefit from it.

Span decorator

By default, a RabbitMqSpanDecorator is provided, with the following attributes:

On send span

  • component: rabbitmq
  • exchange: [exchange_name]
  • messageid: [message_id]
  • routingkey: [routing_key]

On receive span

  • component: rabbitmq
  • exchange: [exchange_name]
  • messageid: [message_id]
  • routingkey: [routing_key]
  • consumerqueue: [consumer_queue]

On send reply

Nothing by default.

On error

  • event: error key
  • error.object: exception

Note: you can customize your spans by declaring an overridden RabbitMqSpanDecorator bean.

Usage

This library is embedded in java-spring-cloud

Usage with Jaeger tracer

If you want to use Jaeger as tracer, you can benefit directly from it by importing java-spring-jaeger.

<dependency>
  <groupId>io.opentracing.contrib</groupId>
  <artifactId>opentracing-spring-jaeger-cloud-starter</artifactId>
</dependency>

Usage with Zipkin tracer

If you want to use Zipkin as tracer, you can benefit directly from it by importing java-spring-zipkin.

<dependency>
  <groupId>io.opentracing.contrib</groupId>
  <artifactId>opentracing-spring-zipkin-cloud-starter</artifactId>
</dependency>

Standalone usage

Note: make sure that an io.opentracing.Tracer bean is available. It is not provided by this library.

With Spring Boot

Add the following starter dependency to your pom.xml:

<dependency>
  <groupId>io.opentracing.contrib</groupId>
  <artifactId>opentracing-spring-rabbitmq-starter</artifactId>
</dependency>

With Spring

Add the following dependency to your pom.xml:

<dependency>
  <groupId>io.opentracing.contrib</groupId>
  <artifactId>opentracing-spring-rabbitmq</artifactId>
</dependency>

Jaeger UI example

Alt text

Development

Maven checkstyle plugin is used to maintain consistent code style based on Google Style Guides

./mvnw clean install

Release

Follow instructions in RELEASE