简体   繁体   中英

Enable tracing using jaeger on Java dropwizard microservices

I have a microservices-based application Running on Kubernetes. The microservices are built using dropwizard framework.

I would like to enable tracing in order to track the requests and have a solution that can help debug stuff.

Basically, I know the implementation using Spring boot which is pretty straightforward. but I'm wondering how it could be in dropwizard based application? actually, Is this is possible? Can someone share his experience with this topic? And provide me with resources or examples of how I can do that?

Please make sure that I'm not using a service mesh.

I enabled instrumentation on the services using those two dependencies:

        implementation "io.opentracing.contrib:opentracing-jaxrs2:1.0.0"
        implementation "io.jaegertracing:jaeger-client:1.4.0"

And, I used jaeger-client to configure the tracer using environment variables:

JAEGER_SERVICE_NAME: yourServiceName

Getting a Tracer Instance:

    public static Tracer jaegerTracer() {
        return Configuration.fromEnv()
                .getTracer();
    }

Finally, in the dropwizard application, you have to register the tracer like so

   GlobalTracer.registerIfAbsent(jaegerTracer());
   jersey.register(new ServerTracingDynamicFeature());

  
    env.servlets()
           .addFilter("span-finisher", new SpanFinishingFilter())
           .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM