-
Notifications
You must be signed in to change notification settings - Fork 383
[BUG?]: graphql resolver depth filter depends on path collapsing #7468
Description
Bug Report
I notice while inspecting the code of the graphql instrumentation/plugin that the depth config option has a rather peculiar behaviour. The shouldInstrument function
dd-trace-js/packages/datadog-plugin-graphql/src/resolve.js
Lines 110 to 119 in 5fd961c
| function shouldInstrument (config, path) { | |
| let depth = 0 | |
| for (const item of path) { | |
| if (typeof item === 'string') { | |
| depth += 1 | |
| } | |
| } | |
| return config.depth < 0 || config.depth >= depth | |
| } |
counts the number of non-numeric path segments, i.e. treating a selection on a field returning a list (or list of lists, etc) as a single level. However, with the
collapse config option enabled (which is the default), the numbers in the path get transformed into the string '*' | .map(segment => typeof segment === 'number' ? '*' : segment) |
shouldInstrument: dd-trace-js/packages/datadog-plugin-graphql/src/resolve.js
Lines 81 to 83 in 5fd961c
| const path = getPath(info, this.config) | |
| if (!shouldInstrument(this.config, path)) return |
So when collapsing is turned off, less path segments are counted and more (deeper) resolver calls are instrumented. You can easily test this by
Reproduction Code
You can try this yourself by running the "graphql with a depth >=1 should only instrument up to the specified depth" test. Change
| return agent.load('graphql', { depth: 2 }) |
return agent.load('graphql', { depth: 2, collapse: false })and the test fails because the trace now also contains spans for friends.0.name and friends.1.name.
Question
Is this considered a bug or a feature? Or an oversight? What is the desired behaviour?
I'm about to open a PR with some optimisations in this place, and would like to know if it will need to keep exact compatibility with the current behaviour.