diff --git a/docs/configuration.asciidoc b/docs/configuration.asciidoc index e72f2ff51f..8c53aacbfa 100644 --- a/docs/configuration.asciidoc +++ b/docs/configuration.asciidoc @@ -119,7 +119,7 @@ You must use the query bar to filter for a specific environment in versions prio * *Default:* `true` * *Env:* `ELASTIC_APM_INSTRUMENT` -A boolean specifying if the agent should collect performance metrics for the app. +A boolean specifying if the agent should automatically apply instrumentation to supported modules when they are loaded. Note that both `active` and `instrument` needs to be `true` for instrumentation to be running. diff --git a/lib/instrumentation/index.js b/lib/instrumentation/index.js index 006e39a8e9..4989e25cd5 100644 --- a/lib/instrumentation/index.js +++ b/lib/instrumentation/index.js @@ -130,9 +130,7 @@ Instrumentation.prototype.clearPatches = function (modules) { Instrumentation.modules = Object.freeze(MODULES) Instrumentation.prototype.start = function () { - if (!this._agent._conf.instrument) return if (this._started) return - this._started = true if (this._agent._conf.asyncHooks && semver.gte(process.version, '8.2.0')) { @@ -164,7 +162,7 @@ Instrumentation.prototype._startHook = function () { this._agent.logger.debug('adding hook to Node.js module loader') this._hook = hook(this._patches.keys, function (exports, name, basedir) { - var enabled = !disabled.has(name) + var enabled = self._agent._conf.instrument && !disabled.has(name) var pkg, version if (basedir) { diff --git a/test/_mock_http_client.js b/test/_mock_http_client.js index 77a5a56ea9..3366549942 100644 --- a/test/_mock_http_client.js +++ b/test/_mock_http_client.js @@ -50,7 +50,7 @@ module.exports = function (expected, done) { if (timer) clearTimeout(timer) timer = setTimeout(function () { done(client._writes) - }, 100) + }, 200) } } diff --git a/test/config.js b/test/config.js index 20a9cf7194..bb20b7916a 100644 --- a/test/config.js +++ b/test/config.js @@ -804,6 +804,29 @@ test('globalLabels should be received by transport', function (t) { }) }) +test('instrument: false allows manual instrumentation', function (t) { + var trans + var opts = { + metricsInterval: 0, + instrument: false + } + + var server = APMServer(opts, { expect: 'transaction' }) + .on('listening', function () { + trans = this.agent.startTransaction('trans') + trans.end() + this.agent.flush() + }) + .on('data-transaction', (data) => { + assertEncodedTransaction(t, trans, data) + t.end() + }) + + t.on('end', function () { + server.destroy() + }) +}) + function assertEncodedTransaction (t, trans, result) { t.comment('transaction') t.equal(result.id, trans.id, 'id matches')