Skip to content

spring-boot-starter-webflux doesn't put traceId in logger MDC #29466

Closed as not planned
@0x006EA1E5

Description

@0x006EA1E5

Affects:
6.0.0-RC4

Expected Behaviour
When using spring-boot-starter-webflux I expect log message written in @RequestMappings methods to have the traceId and spanId in the MDC.

When using spring-boot-starter-web (non-reactive) this is indeed the observed behaviour, but it is not when using spring-boot-starter-webflux, as the logger MDC has no traceId nor spanId properties.

Having the traceId and spanId in the MDC is helpful, as it allows correlation of spans to log messages. This is an established use case, see for example the "jump from trace to logs" feature in Grafana Tempo.

Observed Behaviour
See this repo for example https://github.com/0x006EA1E5/spring-boot-3-reactive-trace-logging

I can see when using spring-boot-starter-web that this functions as expected, as the non-reactive ServerHttpObservationFilter first create, then starts a new Observation, then wraps the rest of the filter chain in a try-with-resources block that opens an Observation.Scope.

However, using spring-boot-starter-webflux, with the reactive ServerHttpObservationFilter, no Observation.Scope is opened, although an Observation is created and start()ed

It seems odd, that although an Observation is created and started, no Observation.Scope is explicitly opened.

I can see that the Observation.Scope is AutoCloseable. Indeed, it appears that if the AutoCloseable is not closed at the end of a request, then the next request maintains the same traceId, which seems obviously wrong.

Therefore, it would seem that the AutoCloseable should be created as a step in the Mono, and closed in a doFinally() handler, but I don't understand this well.

See this thread for more discussion: https://gitter.im/spring-projects/spring-boot?at=636bb545abfb5860bb0aca48

Alternatively, perhaps when an Observation is started, a default Observation.Scope should be started, which should be closed when the Observation is stop()ed?

Metadata

Metadata

Assignees

Labels

status: invalidAn issue that we don't feel is valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions