-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Continuation-Local set in express middleware lost inside resolvers #2042
Comments
@magicaltrip I was wondering, if you managed to find a workaround for this issue? |
We could not find a solution to the issue. const server = new ApolloServer({
schema,
context: async ({ req, res }) => {
// Get traceId from headers or create a new Id
return { traceId }
}
}) |
The "work around" here seems like a pretty reasonable use of the context! The |
Hello,
I have an issue using continuation local storage with apollo-server-express.
Why do I need continuation local storage?
I am using Zipkin for instrumenting requests and I need to see the whole tree of requests derived from a Graphl query.
What am I doing?
I use
zipkin-instrumentation-express
andzipkin-instrumentation-fetch
in most express-based services and the context is stored in continuation-local-storage (I am using cls-hooked) and retrieved again successfully. So the parent traces are kept along downstream requests.What is failing?
The problem is that the first request to the API loses context (no variable saved in continuation local is seen in the resolvers) and I cannot see the tree of requests generated from this first call.
Example
Example code is based on the basic example provided in apollo-server-express:
When calling /basic or querying "hello" in the graphql playground I would expect to see the same traces, but this is what I see in Zipkin:
Request to basic has 4 spans (parent and 3 requests) but requests to graphql do not group the request.
As I said the reason is that the continuation-local is not kept inside the resolvers, and therefore the fetch wrapper cannot access then and creates new spans without parent id.
I tried with the default continuation-local-storage and the cls-hooked without success.
I tried both in mi machine with Node v11 and in Docker with Node v9.4 with same result.
I also tried creating namespaces and simple middleware just setting variables in the context and I got the same result.
I know there is tracing for apollo-server but I cannot see the downstream requests. And I also saw the extensions, but I could not find a way to wrap the
resolve
calls in order to set the right context.The text was updated successfully, but these errors were encountered: