英文:
Enable tracing using jaeger on Java dropwizard microservices
问题
我有一个基于 Kubernetes 运行的微服务应用程序。
这些微服务是使用 dropwizard 框架构建的。
我想要启用追踪功能,以便跟踪请求并拥有一个可以帮助调试的解决方案。
基本上,我知道如何在使用 Spring Boot 的实现中做到这一点,那相当简单明了。
但我想知道在基于 dropwizard 的应用程序中如何实现?实际上,这是否可能?
有人可以分享他在这个主题上的经验吗?
并向我提供如何实现的资源或示例?
请确保我没有在使用服务网格。
英文:
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.
答案1
得分: 2
我使用了这两个依赖项在服务上启用了仪器功能:
implementation "io.opentracing.contrib:opentracing-jaxrs2:1.0.0"
implementation "io.jaegertracing:jaeger-client:1.4.0"
另外,我使用 jaeger-client
来通过环境变量配置跟踪器:
JAEGER_SERVICE_NAME: yourServiceName
获取跟踪器实例:
public static Tracer jaegerTracer() {
return Configuration.fromEnv()
.getTracer();
}
最后,在 Dropwizard 应用程序中,您需要注册跟踪器,如下所示:
GlobalTracer.registerIfAbsent(jaegerTracer());
jersey.register(new ServerTracingDynamicFeature());
env.servlets()
.addFilter("span-finisher", new SpanFinishingFilter())
.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
英文:
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, "/*");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论