The Solutions:
Solution 1: Ensure the Trace Context is Available
When using filters that log HTTP headers outside of the controllers in Spring Boot 3 with Micrometer tracing, ensure that the @Order
annotation is not used.
Additionally, annotate the filter with @AutoConfiguration(after = ServerHttpObservationFilter.class)
. This guarantees that the filter runs after the trace context is injected by ServerHttpObservationFilter
.
Q&A
Spring Boot tracing and span IDs not propagating outside controller
The extra logging was taking place in a Filter
that was annotated with @Order(Ordered.HIGHEST_PRECEDENCE)
. As a consequence, this filter ran before the ServerHttpObservationFilter
, which is responsible for injecting the trace context.
The solution was to remove the @Order
annotation and adding @AutoConfiguration(after = ServerHttpObservationFilter.class)
to ensure that the logging filter runs after the trace context has been made available.