Reputation: 1246
Spring's sleuth adds to MDC X-B3-SpanId and SpanId. (same for 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.
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-TraceId and 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.
Used dependencies:
Just plain addition of dependency to gradle.build - no customizations/configurations regarding sleuth.
*MDC = log4j2's Mapped Diagnostic Contex https://logging.apache.org/log4j/2.x/manual/thread-context.html
Upvotes: 11
Views: 22546
Reputation: 426
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:
* 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"
So you can use whatever of the two you want but be aware that they consider X-B3* variables legacy
Upvotes: 11