spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

Trace id is not propagated correctly with reactor in AdaptCachedBodyGlobalFilter

Open schmidti159 opened this issue 1 year ago • 0 comments

Thanks for all the work that you are doing. I already investigated this bug, but I struggle to find the exact root cause and solution.

Describe the bug We use Spring Cloud Gateway (version 4.0.4), Spring Webflux (6.0.13) and project reactor (3.5.11) for a gateway microservice.

We use the DataDog java agent for metrics.

Now, we noticed that sometimes the traces inside Spring Cloud Gateway are not connected correctly: It seems the trace id is not passed on correctly in the context if we have a request with a body.

  • There is one trace with 2 spans (servlet.request from tomcat-server and FilteringWebHandler.handle from spring-webflux-controller).
  • The other trace starts with netty.client.request from netty-client and then continues as expected.

When I disable AdaptCachedBodyGlobalFilter the traces are correct (spring.cloud.gateway.global-filter.adapt-cached-body.enabled: false)

Can it be that somehow in this filter the original context is lost and thus the tracer does not find the old trace id and uses a new one?

I expect the problem to be either in DataBufferUtils#join or ServerWebExchangeUtils#cacheRequestBody, but I am not sure how to change it, so the context is propagated correctly.

schmidti159 avatar Jan 16 '24 13:01 schmidti159