Search code examples
springspring-bootspring-cloud-sleuthjfr

Adding info to sleuth tracing messages


I have sleuth defined in my spring boot application. It prints messages as in below example.

  • How can I add more info to be printed from DispatcherServlet?
  • How can I create JFR (Java flight recorder) event with tracing info?
  • Where exactly in DispatcherServlet it creates this message - I'd like to update it via instrumentation

2021-02-06 21:11:37.661 DEBUG [,250addg195246a3,250addg195246a3] 11260 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed 200 OK


Solution

  • Since the question does not contain too many details, I'm assuming a bunch of things here:

    How can I add more info to be printed from DispatcherServlet?

    I guess you are referring to the tracing-info part ([,250addg195246a3,250addg195246a3]). Check this answer to understand how tracing data is injected there, by overriding the logging.pattern.level, you will be able to inject custom things there.

    How can I create JFR (Java flight recorder) event with tracing info?

    You can inject a Tracer and get the current span from it, you can inject the data held by the span.

    Where exactly in DispatcherServlet it creates this message - I'd like to update it via instrumentation

    This depends on what version are you using, you should be able find it by reading/debugging it.