Skip to content

Commit cc53a8a

Browse files
authored
add environment variable to disable instrumentations completely (#3234)
1 parent d2b6d48 commit cc53a8a

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"test:appsec:ci": "nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" -- npm run test:appsec",
2020
"test:appsec:plugins": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/appsec/**/*.@($(echo $PLUGINS)).plugin.spec.js\"",
2121
"test:appsec:plugins:ci": "yarn services && nyc --no-clean --include \"packages/dd-trace/test/appsec/**/*.@($(echo $PLUGINS)).plugin.spec.js\" -- npm run test:appsec:plugins",
22-
"test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,encode,exporters,opentelemetry,opentracing,plugins,telemetry}/**/*.spec.js\"",
22+
"test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,config,encode,exporters,opentelemetry,opentracing,plugins,telemetry}/**/*.spec.js\"",
2323
"test:trace:core:ci": "npm run test:trace:core -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/**/*.js\"",
2424
"test:instrumentations": "mocha --colors -r 'packages/dd-trace/test/setup/mocha.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
2525
"test:instrumentations:ci": "nyc --no-clean --include 'packages/datadog-instrumentations/src/**/*.js' -- npm run test:instrumentations",

packages/datadog-instrumentations/src/helpers/register.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,23 @@ const Hook = require('./hook')
77
const requirePackageJson = require('../../../dd-trace/src/require-package-json')
88
const log = require('../../../dd-trace/src/log')
99

10+
const { DD_TRACE_DISABLED_INSTRUMENTATIONS = '' } = process.env
11+
1012
const hooks = require('./hooks')
1113
const instrumentations = require('./instrumentations')
1214
const names = Object.keys(hooks)
1315
const pathSepExpr = new RegExp(`\\${path.sep}`, 'g')
16+
const disabledInstrumentations = new Set(
17+
DD_TRACE_DISABLED_INSTRUMENTATIONS ? DD_TRACE_DISABLED_INSTRUMENTATIONS.split(',') : []
18+
)
1419

1520
const loadChannel = channel('dd-trace:instrumentation:load')
1621

1722
// TODO: make this more efficient
1823

1924
for (const packageName of names) {
25+
if (disabledInstrumentations.has(packageName)) continue
26+
2027
Hook([packageName], (moduleExports, moduleName, moduleBaseDir, moduleVersion) => {
2128
moduleName = moduleName.replace(pathSepExpr, '/')
2229

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict'
2+
3+
process.env.DD_TRACE_DISABLED_INSTRUMENTATIONS = 'express'
4+
5+
require('../setup/tap')
6+
7+
describe('config/disabled_instrumentations', () => {
8+
it('should disable loading instrumentations completely', () => {
9+
const handleBefore = require('express').application.handle
10+
const tracer = require('../../../..')
11+
const handleAfterImport = require('express').application.handle
12+
tracer.init()
13+
const handleAfterInit = require('express').application.handle
14+
15+
expect(handleBefore).to.equal(handleAfterImport)
16+
expect(handleBefore).to.equal(handleAfterInit)
17+
})
18+
})

0 commit comments

Comments
 (0)