简体   繁体   English

在 Java dropwizard 微服务上使用 jaeger 启用跟踪

[英]Enable tracing using jaeger on Java dropwizard microservices

I have a microservices-based application Running on Kubernetes.我有一个在 Kubernetes 上运行的基于微服务的应用程序。 The microservices are built using dropwizard framework.微服务是使用 dropwizard 框架构建的。

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.基本上,我知道使用 Spring boot 的实现非常简单。 but I'm wondering how it could be in dropwizard based application?但我想知道它在基于 dropwizard 的应用程序中如何? 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-client 使用环境变量配置跟踪器:

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最后,在 dropwizard 应用程序中,您必须像这样注册跟踪器

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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