Skip to content

Commit

Permalink
feat(http): split disabling of spans from transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Belanger committed Oct 19, 2018
1 parent dd1dbda commit f33940f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
9 changes: 6 additions & 3 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ var DEFAULTS = {
transactionMaxSpans: 500,
transactionSampleRate: 1.0,
serverTimeout: '30s',
disableInstrumentations: []
disableInstrumentations: [],
monitorIncomingHTTPRequests: true
}

var ENV_TABLE = {
Expand Down Expand Up @@ -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 = [
Expand All @@ -99,7 +101,8 @@ var BOOL_OPTS = [
'captureSpanStackTraces',
'errorOnAbortedRequests',
'instrument',
'asyncHooks'
'asyncHooks',
'monitorIncomingHTTPRequests'
]

var NUM_OPTS = [
Expand Down
13 changes: 8 additions & 5 deletions lib/instrumentation/modules/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit f33940f

Please sign in to comment.