Skip to content

Commit ecdb03c

Browse files
committed
feat(instrumentations): possibility to disable them
1 parent 5a170f3 commit ecdb03c

7 files changed

Lines changed: 44 additions & 3 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ module.exports = {
6363
],
6464
ignoreOutgoingHosts: [
6565
'google.com'
66+
],
67+
disableInstrumentations: [
68+
'mongodb'
6669
]
6770
}
6871
```

lib/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ function Trace () {
3636
})
3737

3838
Instrumentation.create({
39-
agent: this.agent
39+
agent: this.agent,
40+
config: this.config
4041
})
4142
}
4243

lib/index.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ describe('The trace module', function () {
4545
config: fakeConfig
4646
})
4747
expect(instrumentationCreateStub).to.be.calledWith({
48-
agent: fakeAgent
48+
agent: fakeAgent,
49+
config: fakeConfig
4950
})
5051
expect(configCreateStub).to.be.calledOnce
5152
})

lib/instrumentations/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var Module = require('module')
22
var path = require('path')
33
var fs = require('fs')
4+
var remove = require('lodash.remove')
45
var debug = require('debug')('risingstack/trace:instrumentations')
56

67
var shimmer = require('../utils/shimmer')
@@ -81,6 +82,16 @@ module.exports.create = function (options) {
8182
}
8283
})
8384

85+
options.config.disableInstrumentations.forEach(function (instrumentation) {
86+
remove(INSTRUMENTED_LIBS, function (lib) {
87+
return instrumentation === lib
88+
})
89+
90+
remove(CORE_LIBS, function (lib) {
91+
return instrumentation === lib
92+
})
93+
})
94+
8495
CORE_LIBS.forEach(function (core) {
8596
var fileName = core + '.js'
8697
var filePath = path.join(__dirname, 'core', fileName)
@@ -93,3 +104,6 @@ module.exports.create = function (options) {
93104
}
94105
})
95106
}
107+
108+
module.exports.INSTRUMENTED_LIBS = INSTRUMENTED_LIBS
109+
module.exports.CORE_LIBS = CORE_LIBS

lib/instrumentations/index.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var expect = require('chai').expect
2+
var instrumentor = require('./index')
3+
var Shimmer = require('../utils/shimmer')
4+
5+
describe('The instrumentor module', function () {
6+
it('can be created', function () {
7+
var shimmerStub = this.sandbox.stub(Shimmer, 'wrap')
8+
9+
instrumentor.create({
10+
config: {
11+
disableInstrumentations: ['mongodb', 'http']
12+
}
13+
})
14+
15+
expect(instrumentor.CORE_LIBS.indexOf('http')).to.eql(-1)
16+
expect(instrumentor.INSTRUMENTED_LIBS.indexOf('mongodb')).to.eql(-1)
17+
})
18+
})

lib/utils/configReader.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ ConfigReader.prototype._getEnvVarConfig = function () {
5757
collectorLanguage: process.env.TRACE_COLLECTOR_LANGUAGE,
5858
serviceName: process.env.TRACE_SERVICE_NAME,
5959
configPath: process.env.TRACE_CONFIG_PATH,
60-
apiKey: process.env.TRACE_API_KEY
60+
apiKey: process.env.TRACE_API_KEY,
61+
disableInstrumentations: process.env.TRACE_DISABLE_INSTRUMENTATIONS
62+
? process.env.TRACE_DISABLE_INSTRUMENTATIONS.split(',')
63+
: []
6164
}
6265

6366
var ignoreHeaders

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"lodash.defaults": "4.0.1",
4848
"lodash.flatmap": "4.3.0",
4949
"lodash.isnumber": "3.0.3",
50+
"lodash.remove": "4.5.0",
5051
"node-uuid": "1.4.7",
5152
"qs": "6.2.0",
5253
"semver": "5.1.0",

0 commit comments

Comments
 (0)