-
Notifications
You must be signed in to change notification settings - Fork 38.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accessing trace ID within reactive WebFilter #30470
Comments
Have you tried |
@quaff my filter is based on webflux/reactive stack; such call to MDC returns the "00000000000000000000000000000000" so the result of https://github.com/open-telemetry/opentelemetry-java/blob/47ee573f07c9025547d494608863d9314b29df4b/api/all/src/main/java/io/opentelemetry/api/trace/TraceId.java#L51 note: I updated issue summary with a note it is on reactive stack |
Same issue for me with Spring Boot 3 (it's ok with Spring Boot 2) With this attached project , after lauching the test, we can see in the logs that traceId is available only in the REST Controller :
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
class TestFilter(private val tracer: Tracer): WebFilter {
private val logger: Logger = LoggerFactory.getLogger(TestFilter::class.java)
override fun filter(exchange: ServerWebExchange, chain: WebFilterChain): Mono<Void> {
val traceId = tracer.currentSpan()?.context()?.traceId()
logger.info("In filter with $traceId")
return chain.filter(exchange)
.doOnSuccess {
logger.info("Success")
}
.doOnEach {
val context = it.contextView
// Any way to get the traceId from this context ?
logger.info("OnEach")
}
}
} As a workaround, is there a way to get the traceId from the reactor context in a filter ? |
Running your sample app yields the following for me:
Doing the same when the filter is configured at
This can be explained by the fact that the ServerHttpObservationFilter is ordered at I'm closing this issue as this was a problem with the ordering of the |
Affects: 6.0.8 (spring-webflux)
I have a simple filter that should just inject current trace ID to the response:
it works well if my controller returns Mono<List> or Mono but always falls into "fallback" when controller returns Flux;
I am not sure if it is a known limitation now, or some additional configuration / code change is needed on my end?
The text was updated successfully, but these errors were encountered: