secvision
Version:
Performance Profiler and Monitor
84 lines (73 loc) • 2.67 kB
JavaScript
/*
Copyright (c) AppDynamics, Inc., and its affiliates
2015
All Rights Reserved
*/
'use strict';
var HttpEntryProbe = require('./http-entry-probe').HttpEntryProbe;
var HttpExitProbe = require('./http-exit-probe').HttpExitProbe;
var ApolloEntryProbe = require('./apollo-entry-probe').ApolloEntryProbe;
const apolloPackages = ['apollo-server', '@apollo/server/standalone', '@apollo/server/express4', '@apollo/server'];
function HttpProbe(agent) {
this.agent = agent;
this.packages = ['http', 'https', 'express-graphql', ...apolloPackages, "graphql-http"];
this.entryProbe = new HttpEntryProbe(agent);
this.exitProbe = new HttpExitProbe(agent);
this.apolloEntryProbe = new ApolloEntryProbe(agent);
this.init();
}
exports.HttpProbe = HttpProbe;
HttpProbe.prototype.init = function () {
this.entryProbe.init();
this.exitProbe.init();
this.apolloEntryProbe.init();
};
HttpProbe.prototype.attach = function (obj, moduleName) {
var self = this;
var proxy = this.agent.proxy;
if (obj.__appdynamicsProbeAttached__) return;
obj.__appdynamicsProbeAttached__ = true;
if(moduleName == 'http' || moduleName == 'https') {
// Skipping destroy for graphql-http modules as we do not modify them
self.agent.on('destroy', function () {
if (obj.__appdynamicsProbeAttached__) {
delete obj.__appdynamicsProbeAttached__;
proxy.release(obj.Server.prototype.on);
proxy.release(obj.Server.prototype.addListener);
proxy.release(obj.request);
}
});
}
if (moduleName === 'express-graphql') {
if (self.agent.opts.enableGraphQL) {
this.entryProbe.enableGraphQL(obj);
}
} else if (moduleName === 'apollo-server') {
if(self.agent.opts.enableGraphQL) {
this.apolloEntryProbe.attach(obj, moduleName);
}
} else if (moduleName === '@apollo/server/standalone') {
if(self.agent.opts.enableGraphQL) {
obj.__appdynamicsProbeAttached__ = false;
return this.apolloEntryProbe.attach(obj, moduleName);
}
} else if(moduleName === '@apollo/server/express4') {
if(self.agent.opts.enableGraphQL) {
obj.__appdynamicsProbeAttached__ = false;
return this.apolloEntryProbe.attach(obj, moduleName);
}
} else if(moduleName === '@apollo/server') {
if(self.agent.opts.enableGraphQL) {
obj.__appdynamicsProbeAttached__ = false;
return this.apolloEntryProbe.attach(obj, moduleName);
}
}
else if (moduleName.includes('graphql-http')) {
if(self.agent.opts.enableGraphQL) {
this.entryProbe.enableGraphQLHttp(obj);
}
} else {
this.entryProbe.attach(obj, moduleName);
this.exitProbe.attach(obj, moduleName);
}
};