Right now, as documented users have to set this in their config to get span id and trace ids in logs:
logging.pattern.level=%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]
Besides that it abuses the logging level pattern, it is not a good developer experience.
I would prefer it to be auto-configured in the case a Tracer bean is available. Not sure if this is technically feasible.
We should additionally introduce a logging.pattern.correlation property which can be used.
Comment From: mentallurg
@mhalbritter : I agree that the current for using trace ID and span ID in the logging format is bad and should be improved. But I don't agree that it should be added to the format automatically. It may help in some cases, but it can make logs worse readable in many other cases. Besides, new features should not break the current behaviour whenever possible.
Comment From: welsh
@mentallurg previous behaviour that I experienced was that adding:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
Did add it automatically to the default logging, so it was a surprise that I needed to manually add it back in when migrating to Spring Boot 3.
Comment From: philwebb
A few of us discussed this issue again today and we'd like to default to the following format if tracing is enabled:
When a correlation ID is present we'll use traceId dash spanId as recommended by w3c:
2023-05-22T08:53:19.665-07:00 DEBUG 7704 --- [nio-8080-exec-5] [646b8fef796a9e022e983eb44cb82a2f-fe26c1e3afcf59c5] o.s.web.servlet.DispatcherServlet : Completed 200 OK
If the correlation is missing, we'll pad with spaces:
2023-05-22T08:53:19.665-07:00 DEBUG 7704 --- [nio-8080-exec-5] [ ] o.s.web.servlet.DispatcherServlet : Completed 200 OK```
If one part of the correlation ID is missing, we'll pad with spaces and include the dash. This is considered a bug and we want the logs to look strange:
2023-05-22T08:53:19.665-07:00 DEBUG 7704 --- [nio-8080-exec-5] [646b8fef796a9e022e983eb44cb82a2f- ] o.s.web.servlet.DispatcherServlet : Completed 200 OK
2023-05-22T08:53:19.665-07:00 DEBUG 7704 --- [nio-8080-exec-5] [ -fe26c1e3afcf59c5] o.s.web.servlet.DispatcherServlet : Completed 200 OK
We think showing the application name in the logs is a useful feature outside of correlation IDs. We'll open a new issue to support it and enable it by default when correlation IDs are shown.
We also discussed that it's important that slueth style correlation IDs can be used if the user wishes to do so.