OpenTracing instrumentation for Apache Thrift.
Forked and modified by Spond.
Warning: The tests in this repository have not been updated to work with the changes made by Spond.
pom.xml
<dependency>
<groupId>com.spond</groupId>
<artifactId>opentracing-thrift</artifactId>
<version>VERSION</version>
</dependency>
build.gradle
api 'com.spond:opentracing-thrift:{VERSION}'
This fork has been modified with the ability to publish new versions to a Code Artifact Maven repository.
Publishing a new version to code artifact can be done manually with the Maven command:
./mvnw deploy -DskipTests
This command requires the environment variables CODEARTIFACT_REPO
and CODEARTIFACT_AUTH_TOKEN
to be set.
CODEARTIFACT_REPO
: The address of the code artifact repository to publish toCODEARTIFACT_AUTH_TOKEN
: A valid code artifact auth token with permissions to publish to the provideded repository.
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);
// 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));
// Decorate TProtocol with SpanProtocol e.g.
TTransport transport = ...
TProtocol protocol = new TBinaryProtocol(transport);
TProtocol spanProtocol = new SpanProtocol(protocol, tracer)
// 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);
// 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);
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.