OpenTracing Instrumentation for Apache Thrift


License

License

GroupId

GroupId

io.opentracing.contrib
ArtifactId

ArtifactId

opentracing-thrift
Last Version

Last Version

0.1.4
Release Date

Release Date

Type

Type

jar
Description

Description

OpenTracing Instrumentation for Apache Thrift
OpenTracing Instrumentation for Apache Thrift
Project URL

Project URL

https://github.com/opentracing-contrib/java-thrift
Source Code Management

Source Code Management

http://github.com/opentracing-contrib/java-thrift

Download opentracing-thrift

How to add to project

<!-- https://jarcasting.com/artifacts/io.opentracing.contrib/opentracing-thrift/ -->
<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-thrift</artifactId>
    <version>0.1.4</version>
</dependency>
// https://jarcasting.com/artifacts/io.opentracing.contrib/opentracing-thrift/
implementation 'io.opentracing.contrib:opentracing-thrift:0.1.4'
// https://jarcasting.com/artifacts/io.opentracing.contrib/opentracing-thrift/
implementation ("io.opentracing.contrib:opentracing-thrift:0.1.4")
'io.opentracing.contrib:opentracing-thrift:jar:0.1.4'
<dependency org="io.opentracing.contrib" name="opentracing-thrift" rev="0.1.4">
  <artifact name="opentracing-thrift" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.opentracing.contrib', module='opentracing-thrift', version='0.1.4')
)
libraryDependencies += "io.opentracing.contrib" % "opentracing-thrift" % "0.1.4"
[io.opentracing.contrib/opentracing-thrift "0.1.4"]

Dependencies

compile (1)

Group / Artifact Type Version
io.opentracing : opentracing-util jar 0.33.0

provided (1)

Group / Artifact Type Version
org.apache.thrift : libthrift jar 0.13.0

test (5)

Group / Artifact Type Version
io.opentracing : opentracing-mock jar 0.33.0
org.awaitility : awaitility jar 3.1.6
org.mockito : mockito-core jar 2.28.2
junit : junit jar 4.12
ch.qos.logback : logback-classic jar 1.2.3

Project Modules

There are no modules declared in this project.

Build Status Coverage Status Released Version Apache-2.0 license

OpenTracing Apache Thrift Instrumentation

OpenTracing instrumentation for Apache Thrift

pom.xml

<dependency>
    <groupId>io.opentracing.contrib</groupId>
    <artifactId>opentracing-thrift</artifactId>
    <version>VERSION</version>
</dependency>

Usage

Please don't use FieldID equal 3333. It is a magic number for injected span context.

// Instantiate tracer
Tracer tracer = ...

// Optionally register tracer with GlobalTracer
GlobalTracer.register(tracer);

Synchronous mode

Server

// Decorate TProcessor with SpanProcessor e.g.
TProcessor processor = ...
TProcessor spanProcessor = new SpanProcessor(processor, tracer);
TServerTransport transport = ...
TServer server = new TSimpleServer(new Args(transport).processor(spanProcessor));

Client

// Decorate TProtocol with SpanProtocol e.g.

TTransport transport = ...
TProtocol protocol = new TBinaryProtocol(transport);
TProtocol spanProtocol = new SpanProtocol(protocol, tracer)

Asynchronous mode

Server

// Decorate TProcessor with SpanProcessor
TProcessor processor = ...
TProcessor spanProcessor = new SpanProcessor(processor, tracer);

TNonblockingServerSocket tnbSocketTransport = new TNonblockingServerSocket(8890, 30000);
TNonblockingServer.Args tnbArgs = new TNonblockingServer.Args(tnbSocketTransport);
tnbArgs.processor(spanProcessor);
TServer server = new TNonblockingServer(tnbArgs);

Client

// Decorate TProtocolFactory with SpanProtocol.Factory
TProtocolFactory factory = new TBinaryProtocol.Factory();
SpanProtocol.Factory protocolFactory = new SpanProtocol.Factory(factory, tracer, false);

TNonblockingTransport transport = new TNonblockingSocket("localhost", 8890);
TAsyncClientManager clientManager = new TAsyncClientManager();
AsyncClient asyncClient = new AsyncClient(protocolFactory, clientManager, transport);

// Decorate AsyncMethodCallback with TracingAsyncMethodCallback:
AsyncMethodCallback<T> callback = ...
TracingAsyncMethodCallback<T> tracingCallback = new TracingAsyncMethodCallback(callback, protocolFactory);

asyncClient.callMethod(..., tracingCallback);

Custom Client Span Tags

To customise the tags added to spans on the client side, create a custom implementation of ClientSpanDecorator.

class MyClientSpanDecorator implements ClientSpanDecorator {
    
    @Override
    public void decorate(Span span, TMessage message) {
        // Add custom tags to the span.
    }
    
    @Override
    public void onError(Throwable throwable, Span span) {
        // Add custom tags for when an error is thrown by the thrift call.
    }
}

Then pass this into your SpanProtocol.

TProtocol spanProtocol = new SpanProtocol(protocol, tracer, new MyClientSpanDecorator() );

If no custom ClientSpanDecorator is provided, the DefaultClientSpanDecorator is used. This delegates its methods to the static methods in the SpanDecorator class. The DefaultClientSpanDecorator can be extended if you want to add to the default behaviour.

License

Apache 2.0 License.

io.opentracing.contrib

3rd-Party OpenTracing API Contributions

3rd-party contributions that use OpenTracing. **The repositories in this org are *not* affiliated with the CNCF.**

Versions

Version
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
0.0.11
0.0.10
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1