Skip to content

streamnative/pulsar-tracing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apache Pulsar Client Tracing Instrumentation

Tracing instrumentation for Apache Pulsar client.

OpenTracing Instrumentation

Requirements

  • Java 8
  • Pulsar client >= 2.5.0

Installation

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>

Usage

Interceptors based solution

// 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);

License

Apache 2.0 License.