Skip to content

lw346/ratpack-opentracing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ratpack OpenTracing support

Download Build Status

Provides utility classes to hook into Ratpack and provide traces via OpenTracing.

To use this library effectively, you will need to instantiate a Tracer implementation.

Usage

To create a Server Span for the duration of the request, and to extract any parent span from the incoming request headers, you will need to add the SpanInitHandler to your chain:

Tracer tracer = ...;
List<ServerSpanDecorator> decorators = singletonList(ServerSpanDecorator.StandardTags);
ServerOperationNameProvider nameProvider = ServerOperationNameProvider.MethodAndPath;

RatpackServer server = RatpackServer.of(
    chain -> chain.all(new SpanInitHandler(tracer, decorators, nameProvider)),
    ...,
    ...
)

In order to support other libraries that expect the active span to be set in a thread-local context, you will need to install the SpanExecInterceptor.

Integrating with Jaeger

public class JaegerModule extends AbstractModule {
    @Override
    public void configure() {
        JaegerTracer tracer = Configuration.fromEnv("my-service")
            .getTracer();

        // Expose the Tracer to other dependencies
        bind(Tracer.class).toInstance(tracer);

        // Install the interceptor and bind our custom handlers
        bind(SpanExecInterceptor.class).toInstance(new SpanExecInterceptor(tracer));
        bind(SpanInitHandler.class).toInstance(new SpanInitHandler(
            tracer,
            singletonList(ServerSpanDecorator.StandardTags),
            ServerOperationNameProvider.MethodAndPath));

        // Ensure that the reporter and sampler are stopped on shutdown
        bind(JaegerTracerService.class).toInstance(new JaegerTracerService(tracer));
    }

    private class JaegerTracerService implements Service {
        private final JaegerTracer tracer;

        public JaegerTracerService(JaegerTracer tracer) {
            this.tracer = tracer;
        }

        public void onStart(StartEvent event) {
            // do nothing
        }

        public void onStop(StopEvent event) {
            tracer.close();
        }
    }
}

About

OpenTracing hooks for Ratpack

Resources

License

Stars

Watchers

Forks

Packages

No packages published