Skip to content

Fix broken compatibility with graphql-yoga v3 #2884

Description

@cloudify

Hi! 👋

This PR fixes an issue with dd-trace not able to track execution spans of graphql resolvers when using graphql-yoga v3.0.0+. The issue was introduced by this commit in graphql-yoga that changed the execution model of graphql queries: previously the executor of the graphql library was used (and that's what dd-trace instruments), while after that change the executor of the @graphql-tools/executor library is used (and dd-trace doesn't instrument it).
This PR adds instrumentation to the new executor.

Here is the diff that solved my problem:

diff --git a/node_modules/dd-trace/packages/datadog-instrumentations/src/graphql.js b/node_modules/dd-trace/packages/datadog-instrumentations/src/graphql.js
index 0bad6fc..933fe5b 100644
--- a/node_modules/dd-trace/packages/datadog-instrumentations/src/graphql.js
+++ b/node_modules/dd-trace/packages/datadog-instrumentations/src/graphql.js
@@ -349,6 +349,11 @@ function finishResolvers ({ fields }) {
   })
 }
 
+addHook({ name: '@graphql-tools/executor', file: 'cjs/execution/execute.js', versions: ['>=0.0.14'] }, execute => {
+    shimmer.wrap(execute, 'execute', wrapExecute(execute))
+    return execute
+  })
+
 addHook({ name: 'graphql', file: 'execution/execute.js', versions: ['>=0.10'] }, execute => {
   shimmer.wrap(execute, 'execute', wrapExecute(execute))
   return execute
diff --git a/node_modules/dd-trace/packages/datadog-instrumentations/src/helpers/hooks.js b/node_modules/dd-trace/packages/datadog-instrumentations/src/helpers/hooks.js
index 840c98d..97080b0 100644
--- a/node_modules/dd-trace/packages/datadog-instrumentations/src/helpers/hooks.js
+++ b/node_modules/dd-trace/packages/datadog-instrumentations/src/helpers/hooks.js
@@ -36,6 +36,7 @@ module.exports = {
   'fs': () => require('../fs'),
   'node:fs': () => require('../fs'),
   'graphql': () => require('../graphql'),
+  '@graphql-tools/executor': () => require('../graphql'),
   'grpc': () => require('../grpc'),
   'hapi': () => require('../hapi'),
   'http': () => require('../http'),

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions