Question: how to propagate Sleuth trace/span ids to logbook Sink.write
jjfraney-cg opened this issue · 1 comments
Can the slf4j.MDC
be available when Logbook's sink.write
is called? How would I do it?
Or is there an alternate solution?
Here are two log lines from the same application. The first contains the trace and span ids from Sleuth in Spring Boot 2.7. The second does not.
2023-09-05 08:03:11.396 INFO [demo,09d91730535e651e,09d91730535e651e] 178236 --- [or-http-epoll-3]
com.example.demo.HelloController : greetings.
2023-09-05 08:03:11.439 TRACE [demo,,] 178236 --- [or-http-epoll-3]
org.zalando.logbook.Logbook : /127.0.0.1:41424 - - [05/Sep/2023:08:03:11 -0400] "GET / HTTP/1.1" 200 27
Sleuth sets slf4j's logging.level.pattern
to output the ids.
%5p [${spring.zipkin.service.name:" + "${spring.application.name:}},%X{traceId:-},%X{spanId:-}]"
%X
is a logging format directive to pull a value from slf4j.MDC
map.
This is my current sink configuration for the above messages:
@Bean
public Sink sink() {
return new CommonsLogFormatSink(new DefaultHttpLogWriter());
}
Hi @jjfraney-cg,
Logbook uses SLF4J internally, and it honors MDC.
I created a very small project to show this. Please take a look at the README, where all steps are detailed.
Hope this helps!