I'm using Spring Cloud Sleuth to provide distributed tracing for my app.
The trace is logged with logback using logback-spring.xml.
This configuration specifies the following logging pattern:
{
"severity": "%level",
"service": "${springAppName:-}",
"trace": "%X{X-B3-TraceId:-}",
"span": "%X{X-B3-SpanId:-}",
"parent": "%X{X-B3-ParentSpanId:-}",
"exportable": "%X{X-Span-Export:-}",
"pid": "${PID:-}",
"thread": "%thread",
"class": "%logger{40}",
"rest": "%message"
}
Does Sleuth automatically calculates span duration and is it possible to add span duration to this logging pattern?
Does Sleuth automatically calculates span duration
Yes it does
and is it possible to add span duration to this logging pattern?
You'd have to override the current logging mechanism to add to MDC the span duration
The problem with span duration is that it's properly calculated once the span is stopped / reported. But I don't really know if that's a problem for you.