Spring boot 自定义spring boot jaeger自动配置
我正在开发一个POC,能够与JaegerUI集成2个微服务 对serviceA中端点的请求调用serviceB中的端点并返回响应 我使用了以下依赖项: spring.boot.version:2.1.4.RELEASESpring boot 自定义spring boot jaeger自动配置,spring-boot,jaeger,opentracing,Spring Boot,Jaeger,Opentracing,我正在开发一个POC,能够与JaegerUI集成2个微服务 对serviceA中端点的请求调用serviceB中的端点并返回响应 我使用了以下依赖项: spring.boot.version:2.1.4.RELEASE <groupId>io.opentracing.contrib</groupId> <artifactId>opentracing-spring-jaeger-web-starter</artifactId>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-spring-jaeger-web-starter</artifactId>
<version>3.1.1</version>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-spring-cloud-starter</artifactId>
<version>0.4.0</version>
我希望实现以下目标:
对于如何实现上述场景的任何建议,我们将不胜感激 我在学习Opentracing和Jeager,我使用本教程来熟悉基本的可能性: 如果您查看案例1(Hello World),它将解释如何使用“”。 这将回答您的问题1、2和3,因为您可以在跨度和日志中添加您想要的所有信息 下面是存储库中的一个片段(但我建议您在这里查看,因为它有更详细的解释): 在本例中,
helloTo
是一个包含名称的变量,应用程序将向其打招呼。它将创建一个名为hello to的span标记,其中包含来自执行的值
下面是logs案例的一个示例,其中整个helloStr
消息被添加到日志中:
// this goes inside the sayHello method
String helloStr = String.format("Hello, %s!", helloTo);
span.log(ImmutableMap.of("event", "string-format", "value", helloStr));
System.out.println(helloStr);
span.log(ImmutableMap.of("event", "println"));
关于最后一个问题,这会更容易,您可以使用Jaeger UI搜索您想要的跟踪,在左上角有一个字段:
好了
Span setTag(String key, String value);
Span setTag(String key, boolean value);
Span setTag(String key, Number value);
Span日志(映射字段)代码>
例如:
是否可以基于spanId/traceId在JaegerUI中搜索?如果是,如何进行
Jaeger UI的导航栏中有一个搜索框,您可以在其中按跟踪ID搜索跟踪
感谢您的回复。你的回答是相关的。但是,我想使用Spring Boot提供的自动配置跟踪程序实例。我已经弄明白了。基本上,我们可以注入Spring提供的跟踪器,并使用它访问活动跨距。我将添加我自己的答案。
// this goes inside the sayHello method
String helloStr = String.format("Hello, %s!", helloTo);
span.log(ImmutableMap.of("event", "string-format", "value", helloStr));
System.out.println(helloStr);
span.log(ImmutableMap.of("event", "println"));
Span span = tracer.buildSpan("my-span-name").start();
span.setTag("my-tag-name", "my-tag-value");
Span setTag(String key, String value);
Span setTag(String key, boolean value);
Span setTag(String key, Number value);
span.log(
ImmutableMap.Builder<String, Object>()
.put("event", "soft error")
.put("type", "cache timeout")
.put("waited.millis", 1500)
.build()
);
JaegerSpanContext spanContext = (JaegerSpanContext)sprintSpan.context();
long spanId = spanContext.getSpanId();
long traceId = spanContext.getTraceId();