logback configuration is down below
<appender name="ELK-CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<pattern>
<pattern>
{
"timestamp": "@timestamp",
"severity": "%level",
"service": "${springAppName:-}",
"trace": "%X{traceId:-}",
"span": "%X{spanId:-}",
"pid": "${PID:-}",
"thread": "%thread",
"class": "%logger{40}",
"rest": "%message"
}
</pattern>
</pattern>
</providers>
</encoder>
</appender>
But span or trace is always null ,
{
"timestamp":"@timestamp",
"severity":"INFO",
"service":"springAppName_IS_UNDEFINED",
"trace":"",
"span":"",
"pid":"21524",
"thread":"reactor-http-nio-3",
"class":"elk-logger",
"rest":"test log content"
}
Not sure is there is any configuraiton that i'm missing, Thanks for any advice
I tried %X{X-B3-TraceId:-} ,But still doesn't work
"trace": "%X{X-B3-TraceId:-}",
"span": "%X{X-B3-SpanId:-}",
There are some possible reasons why you can't see Sleuth spanId or traceId in your custom logback configuration.
I hope this helps you solve your problem. If you want to learn more about Sleuth and Logback, you can check out these resources: • Get Current Trace ID in Spring Cloud Sleuth: A tutorial on how to get the current trace ID and span ID using the Tracer object.