diff --git a/package-lock.json b/package-lock.json index cf18205ae6..0259c47b73 100644 --- a/package-lock.json +++ b/package-lock.json @@ -99,6 +99,7 @@ "got-v11": "npm:got@^11.8.6", "graphql": "^16.9.0", "graphql-subscriptions": "^3.0.0", + "graphql-subscriptions-v2": "npm:graphql-subscriptions@^2.0.0", "graphql-tag": "^2.12.6", "graphql-ws": "^5.16.0", "husky": "^7.0.4", @@ -40751,6 +40752,19 @@ "graphql": "^15.7.2 || ^16.0.0" } }, + "node_modules/graphql-subscriptions-v2": { + "name": "graphql-subscriptions", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/graphql-subscriptions/-/graphql-subscriptions-2.0.0.tgz", + "integrity": "sha512-s6k2b8mmt9gF9pEfkxsaO1lTxaySfKoEJzEfmwguBbQ//Oq23hIXCfR1hm4kdh5hnR20RdwB+s3BCb+0duHSZA==", + "dev": true, + "dependencies": { + "iterall": "^1.3.0" + }, + "peerDependencies": { + "graphql": "^15.7.2 || ^16.0.0" + } + }, "node_modules/graphql-tag": { "version": "2.12.6", "resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.12.6.tgz", @@ -42538,6 +42552,12 @@ "node": ">=8" } }, + "node_modules/iterall": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/iterall/-/iterall-1.3.0.tgz", + "integrity": "sha512-QZ9qOMdF+QLHxy1QIpUHUU1D5pS2CG2P69LF6L6CPjPYA/XMOmKV3PZpawHoAjHNyB0swdVTRxdYT4tbBbxqwg==", + "dev": true + }, "node_modules/iterator.prototype": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/iterator.prototype/-/iterator.prototype-1.1.2.tgz", diff --git a/package.json b/package.json index 3a014b4b2e..daf9cdc156 100644 --- a/package.json +++ b/package.json @@ -160,6 +160,7 @@ "got": "^14.4.4", "got-v11": "npm:got@^11.8.6", "graphql": "^16.9.0", + "graphql-subscriptions-v2": "npm:graphql-subscriptions@^2.0.0", "graphql-subscriptions": "^3.0.0", "graphql-tag": "^2.12.6", "graphql-ws": "^5.16.0", diff --git a/packages/collector/test/tracing/protocols/graphql/schema.js b/packages/collector/test/tracing/protocols/graphql/schema.js index 021acb1dba..d8f6028cee 100644 --- a/packages/collector/test/tracing/protocols/graphql/schema.js +++ b/packages/collector/test/tracing/protocols/graphql/schema.js @@ -203,10 +203,11 @@ module.exports = function exportSchema() { subscribe: (__, { id }) => { pinoLogger.warn(`subscribe: ${id}`); - // for graphql-subscriptions/releases version 3, asyncIterator is replaced with asyncIterableIterator + // for graphql-subscriptions, asyncIterator is replaced with asyncIterableIterator in v3 if (pubsub?.asyncIterableIterator) { return pubsub.asyncIterableIterator('characterUpdated'); } else { + // v2 or lesser return pubsub.asyncIterator('characterUpdated'); } } diff --git a/packages/core/src/tracing/instrumentation/control_flow/graphqlSubscriptions.js b/packages/core/src/tracing/instrumentation/control_flow/graphqlSubscriptions.js index 0182b1951e..53490c071b 100644 --- a/packages/core/src/tracing/instrumentation/control_flow/graphqlSubscriptions.js +++ b/packages/core/src/tracing/instrumentation/control_flow/graphqlSubscriptions.js @@ -16,7 +16,10 @@ const CLS_CONTEXT_SYMBOL = Symbol('_instana_cls_context'); exports.init = () => { hook.onModuleLoad('graphql-subscriptions', instrumentModule); - hook.onFileLoad(/\/graphql-subscriptions\/dist\/pubsub-async-iterator\.js/, instrumentAsyncIterator); + hook.onFileLoad(/\/graphql-subscriptions\/dist\/pubsub-async-iterator\.js/, instrumentAsyncIterableIterator); + + hook.onModuleLoad('graphql-subscriptions-v2', instrumentModule); + hook.onFileLoad(/\/graphql-subscriptions-v2\/dist\/pubsub-async-iterator\.js/, instrumentAsyncIterator); }; function instrumentModule(graphQlSubscriptions) { @@ -40,6 +43,11 @@ function instrumentAsyncIterator(pubSubAsyncIterator) { shimmer.wrap(pubSubAsyncIterator.PubSubAsyncIterator.prototype, 'pullValue', shimPullValue); } +function instrumentAsyncIterableIterator(pubSubAsyncIterator) { + shimmer.wrap(pubSubAsyncIterator.PubSubAsyncIterableIterator.prototype, 'pushValue', shimPushValue); + shimmer.wrap(pubSubAsyncIterator.PubSubAsyncIterableIterator.prototype, 'pullValue', shimPullValue); +} + function shimPushValue(originalFunction) { return function (event) { if (isActive && event && typeof event === 'object' && cls.ns.active) {