Skip to content

Commit

Permalink
chore: incorporated v3 and v2 separately
Browse files Browse the repository at this point in the history
  • Loading branch information
abhilash-sivan committed Nov 13, 2024
1 parent 17f0dbf commit bc62393
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion packages/collector/test/tracing/protocols/graphql/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit bc62393

Please sign in to comment.