简体   繁体   English

哪个记录 X-B3-SpanId 或 SpanId? X-B3-TraceId 还是 TraceId? (春天的侦探)

[英]Which to log X-B3-SpanId or SpanId? X-B3-TraceId or TraceId? (Spring sleuth)

Spring's sleuth adds to MDC X-B3-SpanId and SpanId. Spring 的侦探增加了 MDC X-B3-SpanId 和 SpanId。 (same for TraceId) (与 TraceId 相同)

{X-B3-SpanId=0000000000000001, X-B3-TraceId=0000000000000002, X-Span-Export=false, spanExportable=false, spanId=0000000000000001, traceId=0000000000000002}

"X-B3-" prefixed values are identical to non-prefixed. “X-B3-”前缀值与非前缀值相同。
If one of them is redundant, I prefer to remove it.如果其中之一是多余的,我更愿意将其删除。 (to reduce verboseness of my logs) (为了减少我的日志的冗长)

Is there any difference between X-B3-SpanId and SpanId? X-B3-SpanId 和 SpanId 之间有什么区别吗? (X-B3-TraceId and Traceid) (X-B3-TraceId 和 Traceid)
Is there good reason to log both?有充分的理由同时记录两者吗?

Diagram in spring docs https://cloud.spring.io/spring-cloud-sleuth/2.1.x/single/spring-cloud-sleuth.html#_propagation show that "X-B3-" prefixed thing lives only in request header for transport, but if I make request without any of those headers, my log's MDC still contains "X-B3-" prefixed values. spring 文档中的图表https://cloud.spring.io/spring-cloud-sleuth/2.1.x/single/spring-cloud-sleuth.html#_propagation显示“X-B3-”前缀的东西只存在于请求头中用于传输,但如果我在没有任何这些标头的情况下发出请求,我的日志的 MDC 仍然包含“X-B3-”前缀值。


Used dependencies:使用的依赖项:

  • org.springframework.boot:spring-boot-starter-log4j2:2.0.3.RELEASE org.springframework.boot:spring-boot-starter-log4j2:2.0.3.RELEASE
  • org.springframework.cloud:spring-cloud-sleuth-core:2.0.3.RELEASE org.springframework.cloud:spring-cloud-sleuth-core:2.0.3.RELEASE

Just plain addition of dependency to gradle.build - no customizations/configurations regarding sleuth.只是简单地添加了对 gradle.build 的依赖 - 没有关于侦探的定制/配置。

*MDC = log4j2's Mapped Diagnostic Contexhttps://logging.apache.org/log4j/2.x/manual/thread-context.html *MDC = log4j2 的映射诊断上下文https://logging.apache.org/log4j/2.x/manual/thread-context.html

Looking at the class Slf4jScopeDecorator is clear that the two values are exactly the same and they maintain the X-B3* prefixed values only for backward compatibility:查看类 Slf4jScopeDecorator 很明显,这两个值完全相同,它们维护 X-B3* 前缀值只是为了向后兼容:

 * Adds {@linkplain MDC} properties "traceId", "parentId", "spanId" and "spanExportable"
 * when a {@link brave.Tracer#currentSpan() span is current}. These can be used in log
 * correlation. Supports backward compatibility of MDC entries by adding legacy "X-B3"
 * entries to MDC context "X-B3-TraceId", "X-B3-ParentSpanId", "X-B3-SpanId" and
 * "X-B3-Sampled"

https://github.com/spring-cloud/spring-cloud-sleuth/blob/master/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/log/Slf4jScopeDecorator.java https://github.com/spring-cloud/spring-cloud-sleuth/blob/master/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/log/Slf4jScopeDecorator.java

So you can use whatever of the two you want but be aware that they consider X-B3* variables legacy所以你可以使用你想要的任何两个,但要注意他们认为 X-B3* 变量是遗留的

暂无
暂无

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

相关问题 X-B3-SpanId常数在哪里定义? - Where is X-B3-SpanId constant defined? 在 Sleuth 的日志中看不到 traceId 和 spanId - Can't see traceId and spanId in log for Sleuth Sleuth Header X-B3-TraceId 值会重新生成,即使作为 Bluemix 中的标头传递给服务请求 - Sleuth Header X-B3-TraceId value get Regenerated even if passed to the Service Request as Header In Bluemix Spring 云侦探 3.0.1 使用 logback 在日志中生成 traceid 和 spanid - Spring cloud sleuth 3.0.1 generate traceid & spanid in logs using logback Sleuth 不会在 Spring Boot 应用程序中打印 spanId、traceId - Sleuth doesnt print spanId,traceId in spring boot application Sleuth traceId 和 spanId 不会传播到 parallelStream 工作线程 - Sleuth traceId and spanId are not propagated to parallelStream worker threads 迁移到 Spring Boot 3 后 TraceId 和 SpanId 不可用 - TraceId and SpanId not available after migrating to Spring Boot 3 traceId 和 spanId 在整个记录器中都是一样的 - traceId and spanId are coming as same throughout the loggers 在使用带有新关键字的 resttemplate 进行 API 调用时,无法将 Sleuth traceid 和 spanid 传递给下游服务 - Not able to pass Sleuth traceid and spanid to downstream services while making API calls using resttemplate with new keyword 如何获取 log4j2 中的 trace id 和 span id,格式为 [traceId, spanId ]? - How to get trace id and span id in the log4j2, in the format [traceId, spanId ]?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM