Search code examples
spring-integration

Spring Integration - TracingContext Lost in WebFluxRequestExecutingMessageHandler


This issue is an extension of the SO issue Spring Integration Restore ReactorContext into Imperative Processing

Any exception thrown after the WebFlux call via WebFluxRequestExecutingMessageHandler is missing the Trace information.

Sample depicting the problem available at https://github.com/syedyusufh/simple-handle-reactive.git

This is what is happening.

  1. WebFlux call completed, but there are business errors in response.
  2. Transformer tries to convert the response to Object and then looks for any business errors, if so throws user defined for the same.
  3. This exception thrown first gets logged automatically via WebFluxRequestExecutingMessageHandler where context is lost
  4. Then the exception is forwarded to application defined errorChannel, which creates a new traceId

Exception:

2m2024-06-24T20:27:02.445+04:00  INFO 1436 --- [   scheduling-1] [66799e5608c967d694f450b82077c38c-fadc3f15d16b6b11] c.i.sample.config.TracingConfig          : Request Headers: [Content-Type:"application/json", traceparent:"00-66799e5608c967d694f450b82077c38c-fadc3f15d16b6b11-00"]
2024-06-24T20:27:03.997+04:00  INFO 1436 --- [ctor-http-nio-3] [66799e5608c967d694f450b82077c38c-fadc3f15d16b6b11] c.i.sample.config.TracingConfig          : Response Headers: [Access-Control-Allow-Origin:"*", Alt-Svc:"h3=":443"; ma=2592000", Content-Type:"application/json", Date:"Mon, 24 Jun 2024 16:27:05 GMT", Server:"Caddy", Vary:"Accept-Encoding", Transfer-Encoding:"chunked"]
2024-06-24T20:27:04.089+04:00 ERROR 1436 --- [oundedElastic-1] [                                                 ] .o.WebFluxRequestExecutingMessageHandler : Failed to send async reply: org.springframework.integration.support.MessageBuilder@5e1691b0

Solution

  • any workarounds until then, pls?

    Do not throw that exception back to WebFlux channel adapter's thread. Consider to handle it manually or via ExpressionEvaluatingRequestHandlerAdvice: https://docs.spring.io/spring-integration/reference/handler-advice/classes.html#expression-advice