From f33940fa066911207d28d63f61d3f728f89e4ea3 Mon Sep 17 00:00:00 2001 From: Stephen Belanger Date: Fri, 19 Oct 2018 12:03:31 -0700 Subject: [PATCH] feat(http): split disabling of spans from transactions Fixes #434 --- lib/config.js | 9 ++++++--- lib/instrumentation/modules/http.js | 13 ++++++++----- test/config.js | 3 ++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/config.js b/lib/config.js index 7b2ea021c51..bdd2f904642 100644 --- a/lib/config.js +++ b/lib/config.js @@ -53,7 +53,8 @@ var DEFAULTS = { transactionMaxSpans: 500, transactionSampleRate: 1.0, serverTimeout: '30s', - disableInstrumentations: [] + disableInstrumentations: [], + monitorIncomingHTTPRequests: true } var ENV_TABLE = { @@ -88,7 +89,8 @@ var ENV_TABLE = { transactionSampleRate: 'ELASTIC_APM_TRANSACTION_SAMPLE_RATE', serverTimeout: 'ELASTIC_APM_SERVER_TIMEOUT', disableInstrumentations: 'ELASTIC_APM_DISABLE_INSTRUMENTATIONS', - payloadLogFile: 'ELASTIC_APM_PAYLOAD_LOG_FILE' + payloadLogFile: 'ELASTIC_APM_PAYLOAD_LOG_FILE', + monitorIncomingHTTPRequests: 'ELASTIC_APM_MONITOR_INCOMING_HTTP_REQUESTS' } var BOOL_OPTS = [ @@ -99,7 +101,8 @@ var BOOL_OPTS = [ 'captureSpanStackTraces', 'errorOnAbortedRequests', 'instrument', - 'asyncHooks' + 'asyncHooks', + 'monitorIncomingHTTPRequests' ] var NUM_OPTS = [ diff --git a/lib/instrumentation/modules/http.js b/lib/instrumentation/modules/http.js index 50ee086d0d5..e1168647d4a 100644 --- a/lib/instrumentation/modules/http.js +++ b/lib/instrumentation/modules/http.js @@ -4,16 +4,19 @@ var httpShared = require('../http-shared') var shimmer = require('../shimmer') module.exports = function (http, agent, version, enabled) { + if (agent._conf.monitorIncomingHTTPRequests) { + agent.logger.debug('shimming http.Server.prototype.emit function') + shimmer.wrap(http && http.Server && http.Server.prototype, 'emit', httpShared.instrumentRequest(agent, 'http')) + + agent.logger.debug('shimming http.ServerResponse.prototype.writeHead function') + shimmer.wrap(http && http.ServerResponse && http.ServerResponse.prototype, 'writeHead', wrapWriteHead) + } + if (!enabled) return http - agent.logger.debug('shimming http.Server.prototype.emit function') - shimmer.wrap(http && http.Server && http.Server.prototype, 'emit', httpShared.instrumentRequest(agent, 'http')) agent.logger.debug('shimming http.request function') shimmer.wrap(http, 'request', httpShared.traceOutgoingRequest(agent, 'http')) - agent.logger.debug('shimming http.ServerResponse.prototype.writeHead function') - shimmer.wrap(http && http.ServerResponse && http.ServerResponse.prototype, 'writeHead', wrapWriteHead) - return http function wrapWriteHead (original) { diff --git a/test/config.js b/test/config.js index fbbad17e173..bda5799749f 100644 --- a/test/config.js +++ b/test/config.js @@ -50,7 +50,8 @@ var optionFixtures = [ ['transactionMaxSpans', 'TRANSACTION_MAX_SPANS', 500], ['transactionSampleRate', 'TRANSACTION_SAMPLE_RATE', 1.0], ['serverTimeout', 'SERVER_TIMEOUT', 30], - ['disableInstrumentations', 'DISABLE_INSTRUMENTATIONS', []] + ['disableInstrumentations', 'DISABLE_INSTRUMENTATIONS', []], + ['monitorIncomingHTTPRequests', 'MONITOR_INCOMING_HTTP_REQUESTS', true] ] var falsyValues = [false, 'false']