UNPKG

appdynamics

Version:

Performance Profiler and Monitor

92 lines (80 loc) 3.08 kB
/* 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(process.env.APPDYNAMICS_HTTP_PROBE_DISABLE == 'true' || process.env.APPDYNAMICS_HTTP_PROBE_DISABLE == true) { return; } 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 { if(process.env.APPDYNAMICS_HTTP_ENTRY_PROBE_DISABLE != 'true' && process.env.APPDYNAMICS_HTTP_ENTRY_PROBE_DISABLE != true) { this.entryProbe.attach(obj, moduleName); } if(process.env.APPDYNAMICS_HTTP_EXIT_PROBE_DISABLE != 'true' && process.env.APPDYNAMICS_HTTP_EXIT_PROBE_DISABLE != true) { this.exitProbe.attach(obj, moduleName); } } };