Tracing instrumentation for Apache Pulsar client.
- Java 8
- Pulsar client >= 2.5.0
Add Pulsar client and OpenTracing instrumentation for the Pulsar client.
<dependency>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-client</artifactId>
<version>VERSION</version>
</dependency>
<dependency>
<groupId>io.streamnative</groupId>
<artifactId>opentracing-pulsar-client</artifactId>
<version>VERSION</version>
</dependency>
// Instantiate tracer
Tracer tracer = ...
// Optionally register tracer with GlobalTracer
GlobalTracer.register(tracer);
Producer
// Instantiate Producer with tracing interceptor.
Producer<String> producer = client
.newProducer(Schema.STRING)
.intercept(new TracingProducerInterceptor())
.topic("your-topic")
.create();
// Send messages.
producer.send("Hello OpenTracing!");
Consumer
// Instantiate Consumer with tracing interceptor.
Consumer<String> consumer = client.newConsumer(Schema.STRING)
.topic("your-topic")
.intercept(new TracingConsumerInterceptor<>())
.subscriptionName("your-sub")
.subscribe();
// Receive messages.
Message<String> message = consumer.receive();
// To retrieve SpanContext from the message(Consumer side).
SpanContext spanContext = TracingPulsarUtils.extractSpanContext(message, tracer);