-
Notifications
You must be signed in to change notification settings - Fork 171
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
How to get the traceId, parentId, spanId of current request to use outside the tracer? #128
Comments
my guess is that when you print the trace ID, one hasn't started yet.
There's a Tracer.scope function which allows you to push an ID onto the
context (such that downstream reuse it).
|
Thanks for the quick reply @adriancole. But is there a way I could make sure I grab the trace without manually pushing an ID? The API that I am testing this on is the where the root traceId is generated. I am currently using the
So the request hits the zipkinExpressMiddleware -> graphql middleware -> outbound request to some user service using axios instrumented with zipkin -> then returns the result of that back to the user. There is also a callback function inside of my graphql middleware to set the context up, which is where the graphql log statement is from. The graphql middleware is declared after the zipkinExpressMiddleware. I also use Eureka and inside of my graphql resolvers I build a axios instance to so that I can fetch the user-service urls from the Eureka registry and build a url. As you can see from the output I get a completely different traceId from what was already set at the zipkinExpressMiddleware. Is there a different way I should accessing this, not Edit: Also I noticed that the traceId that is being sent out from the |
I don't have much experience in this, suffice to say that things untested
aren't going to work well. For example, in the java project brave, we added
tests to ensure that the trace scope was readable from other callbacks.
When I put these tests in I found most tools didn't work. We then fixed
them.
Ex here's a test where we read the current trace id on a user filter stuff
it into a header (just so that we can later test it)
https://github.com/openzipkin/brave/blob/master/instrumentation/http-tests/src/main/java/brave/http/ITServlet25Container.java#L64
https://github.com/openzipkin/brave/blob/master/instrumentation/http-tests/src/main/java/brave/http/ITServlet25Container.java#L79
Is there a way you can help add tests to cover the behavior you are looking
for? For advice on CLS I need to defer to folks with javascript experience.
|
So I've narrowed down the problem to the *Update: I've found an ugly fix for this. Basically I think the problem is related to how I am initializing my graphql middleware. Basically, the
I'm not that familiar with how cls and AsyncListeners work, so open to suggestions here from some Node gurus. |
if you can narrow it to CLS being lost across your middleware, it is
possible you could ask apollo for help? Then you could take that
recommendation into your middleware and solve the problem.
|
Thank you for your help. I will take it up on their end. |
I've ran into a similar issue and wanted to share what helped me work around it. I'm running and express app with both I've noticed that the zipkin trace IDs inside my GraphQL resolvers are not always what I expect them to be 🔥 I then noticed that Apollo uses the I had the zipkin middleware attached BEFORE the apollo server middleware which must have meant that Adding |
So I am currently trying to inject the traceId, parentId, spanId into a custom logger. When I try out the
ConsoleRecorder
I can see that the information is there within the record that is being passed in. But what I want is to not log at the record level, because I want to be able to control what I log.What would be best is if I could have some handle on what the current traceId is within the context so that I can inject these values into a custom logger so that I can use log correlation later, similar to what the Spring Cloud Sleuth project does to the slf4j logger.
I initially thought that the
tracer.id
property had these values, but when I compared it with the output from theConsoleRecorder
, I see that the ids are all different.This some sample console output:
What am I doing wrong? What is the proper place to grab the right id values?
The text was updated successfully, but these errors were encountered: