-
Notifications
You must be signed in to change notification settings - Fork 326
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
Add datadog tracing to compiled graphql queries #5681
Conversation
5635524
to
120bc60
Compare
Adding the tracing functions is a 2 step process. Step 1 wraps all field resolvers in the schema itself. Step 2 wraps the CompiledQuery to initialize the tracing. The tracing funcitonality itself is heavily inspired by dd-trace-js graphql plugin.
120bc60
to
a20a702
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally, works well. Great work! Two suggestions:
- Comparing the output between this version vs. vanilla DataDog GraphQL plugin, it looks like this version is missing the query doc on the resource column. I think with the query content there is super helpful when we investigate performance issue later:
Great PR, @Dschoordsch! I'm trying to get a better understanding of how it's working. Did the old implementation slow down the app because we were tracing all queries, including cached queries, in |
The previous version required us to use plain |
Makes sense, thanks for the explanation! |
Also add execution hook to add custom tags like the graphql plugin allows.
@tianrunhe I addressed the resource name and added the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good enough! All I want is that when we have this in production and say we see a query/mutation takes much longer than expected to execute, we could dive into:
- What that query/mutation is about? I think now by having the query name, we could look that up in the code. Would be easier to have the entire query there as the vanilla GraphQL plugin, but I think what we have here is good enough and additionally it saves a lot of traffic sent to DataDog.
- Does the query perform badly in general or is it just slow in certain scenario (e.g., a meeting with hundreds of users)? That's my initial request on query variables but I agree with your points on avoiding sending sensitive data to DataDog. Having the
viewerId
there will definitely help us!
GREAT work! Can't wait to see this in production!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish I had more feedback to give, but all the changes are pretty minor. It's really solid work! I'll do some testing with it tomorrow morning
Extra thoughts:
For your consideration: tracer.init({
enabled: process.env.DD_TRACE_ENABLED === 'true',
// might be worthwhile knowing which service it came from
service: `GQLExecutor ${process.env.SERVER_ID}`,
plugins: false
}) |
I tested locally with the dev server as dd agent, this way we don't add unwanted infrastructure to datadog. |
Always initialize dd-trace if DD_TRACE_ENABLED is set. Also pass the correct service name.
import './tracer' | ||
|
||
tracer.init({ | ||
enabled: process.env.DD_TRACE_ENABLED === 'true', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was incorrect, I read the code & apparently enabled
isn't required, dd-trace reads directly from DD_TRACE_ENABLED
. 1 less thing to worry about! https://github.com/DataDog/dd-trace-js/blob/f50ff8817d5ff21b29868ace03558ac25cf5cc18/packages/dd-trace/src/config.js#L91
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's what I've written in my comment. I added it anyways because it's more explicit.
Instead wrap all object type's fields directly. This also ensures wrapping each field only once, removing the need to mark these separately.
Please see also https://github.com/ParabolInc/action-devops/pull/76 |
Adding the tracing functions is a 2 step process. Step 1 wraps all field
resolvers in the schema itself. Step 2 wraps the CompiledQuery to
initialize the tracing.
The tracing funcitonality itself is heavily inspired by dd-trace-js
graphql plugin.
This changeset will only enable tracing for graphql-jit compiled queries. It can be added to subscriptions after #5468.
Resolves: #5333