Skip to content

Commit

Permalink
feat: allow manual instrumentation with instrument: false (#1114)
Browse files Browse the repository at this point in the history
Fixes #858
  • Loading branch information
Qard authored and watson committed Sep 24, 2019
1 parent 9e4bfb7 commit 6202ae3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/configuration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 1 addition & 3 deletions lib/instrumentation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/_mock_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = function (expected, done) {
if (timer) clearTimeout(timer)
timer = setTimeout(function () {
done(client._writes)
}, 100)
}, 200)
}
}

Expand Down
23 changes: 23 additions & 0 deletions test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 6202ae3

Please sign in to comment.