How do I pass MDC Context while using virtual threads in DGS and Spring Boot? #1873
-
I'm getting a 'request_id' in request header and I want to put it in the MDC context. I've set up an AOP Aspect using DGS annotations like @DgsData, @DgsQuery, etc to capture request-id header from ‘dfe’ and put them into MDC. But, I'm having trouble with async resolvers such as below: Resolver:
Dataloader:
I'm facing an issue where the MDC context isn't flowing correctly because the resolver and the 'load' method are running on different threads. How can I set MDC in data loader? Is there a way to ensure that the load method runs on a caller method thread or custom thread pool. The other option I'm thinking about making another Aspect for the 'load' method, but I'm not sure if it's a foolproof solution |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
@paulbakker @srinivasankavitha any suggestions? |
Beta Was this translation helpful? Give feedback.
-
So the short answer is that you'll need to propagate the context that's on thread locals some way. The best option is probably to leverage MicroMeter Context, which Spring Boot is now standardizing on. To integrate that with DGS you'll have to provide an I'm also starting to realize that we should probably do something better out of the box. I'll think about that some more, but it will technically be about the same thing. Let me know what you find, that will be helpful input to decide on what to do out of the box. |
Beta Was this translation helpful? Give feedback.
-
@govi20 I experimented some more and was able to fix this nicely. See PR here: #1875 |
Beta Was this translation helpful? Give feedback.
So the short answer is that you'll need to propagate the context that's on thread locals some way. The best option is probably to leverage MicroMeter Context, which Spring Boot is now standardizing on. To integrate that with DGS you'll have to provide an
ExecutorService
as a bean, where that bean is configured to be context propagation enabled.We're doing exactly that at Netflix, since our Spring Boot extensions take care of that.
Doing something like that manually will unblock this for you.
I'm also starting to realize that we should probably do something better out of the box. I'll think about that some more, but it will technically be about the same thing.
Also, I'm wondering if you h…