dd-trace 2.30.1 → 2.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-3rdparty.csv +1 -1
- package/esbuild.js +3 -0
- package/index.d.ts +10 -9
- package/package.json +12 -12
- package/packages/datadog-core/src/storage/async_resource.js +1 -1
- package/packages/datadog-esbuild/index.js +9 -2
- package/packages/datadog-instrumentations/src/body-parser.js +15 -9
- package/packages/datadog-instrumentations/src/cucumber.js +11 -1
- package/packages/datadog-instrumentations/src/express.js +32 -0
- package/packages/datadog-instrumentations/src/helpers/instrument.js +1 -1
- package/packages/datadog-instrumentations/src/helpers/register.js +1 -1
- package/packages/datadog-instrumentations/src/http/server.js +2 -1
- package/packages/datadog-instrumentations/src/jest.js +6 -3
- package/packages/datadog-instrumentations/src/mocha.js +19 -2
- package/packages/datadog-instrumentations/src/playwright.js +5 -2
- package/packages/datadog-plugin-amqp10/src/consumer.js +1 -3
- package/packages/datadog-plugin-amqp10/src/producer.js +1 -3
- package/packages/datadog-plugin-amqplib/src/client.js +4 -3
- package/packages/datadog-plugin-amqplib/src/consumer.js +1 -3
- package/packages/datadog-plugin-amqplib/src/producer.js +1 -3
- package/packages/datadog-plugin-cucumber/src/index.js +6 -4
- package/packages/datadog-plugin-cypress/src/plugin.js +5 -1
- package/packages/datadog-plugin-cypress/src/support.js +4 -0
- package/packages/datadog-plugin-google-cloud-pubsub/src/client.js +4 -3
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +1 -3
- package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +1 -3
- package/packages/datadog-plugin-http/src/client.js +1 -1
- package/packages/datadog-plugin-http/src/server.js +2 -2
- package/packages/datadog-plugin-http2/src/server.js +0 -5
- package/packages/datadog-plugin-jest/src/index.js +10 -5
- package/packages/datadog-plugin-kafkajs/src/consumer.js +1 -4
- package/packages/datadog-plugin-kafkajs/src/producer.js +1 -3
- package/packages/datadog-plugin-mocha/src/index.js +9 -4
- package/packages/datadog-plugin-playwright/src/index.js +6 -5
- package/packages/datadog-plugin-redis/src/index.js +16 -5
- package/packages/datadog-plugin-rhea/src/consumer.js +1 -3
- package/packages/datadog-plugin-rhea/src/producer.js +1 -5
- package/packages/dd-trace/src/appsec/addresses.js +0 -3
- package/packages/dd-trace/src/appsec/blocked_templates.js +2 -9
- package/packages/dd-trace/src/appsec/blocking.js +1 -1
- package/packages/dd-trace/src/appsec/{gateway/channels.js → channels.js} +4 -4
- package/packages/dd-trace/src/appsec/iast/index.js +1 -1
- package/packages/dd-trace/src/appsec/iast/taint-tracking/operations.js +21 -13
- package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +1 -1
- package/packages/dd-trace/src/appsec/iast/telemetry/logs.js +1 -1
- package/packages/dd-trace/src/appsec/index.js +87 -79
- package/packages/dd-trace/src/appsec/recommended.json +448 -121
- package/packages/dd-trace/src/appsec/remote_config/apply_states.js +7 -0
- package/packages/dd-trace/src/appsec/remote_config/capabilities.js +2 -0
- package/packages/dd-trace/src/appsec/remote_config/index.js +30 -11
- package/packages/dd-trace/src/appsec/remote_config/manager.js +33 -12
- package/packages/dd-trace/src/appsec/reporter.js +27 -58
- package/packages/dd-trace/src/appsec/rule_manager.js +160 -32
- package/packages/dd-trace/src/appsec/sdk/user_blocking.js +4 -12
- package/packages/dd-trace/src/appsec/waf/index.js +75 -0
- package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +57 -0
- package/packages/dd-trace/src/appsec/waf/waf_manager.js +66 -0
- package/packages/dd-trace/src/config.js +18 -1
- package/packages/dd-trace/src/dcitm.js +2 -0
- package/packages/dd-trace/src/encode/0.4.js +12 -4
- package/packages/dd-trace/src/encode/tags-processors.js +40 -68
- package/packages/dd-trace/src/exporters/common/request.js +2 -2
- package/packages/dd-trace/src/format.js +2 -1
- package/packages/dd-trace/src/iitm.js +1 -1
- package/packages/dd-trace/src/log/channels.js +11 -12
- package/packages/dd-trace/src/opentracing/propagation/text_map.js +2 -2
- package/packages/dd-trace/src/plugin_manager.js +3 -1
- package/packages/dd-trace/src/plugins/client.js +3 -2
- package/packages/dd-trace/src/plugins/consumer.js +17 -2
- package/packages/dd-trace/src/plugins/inbound.js +7 -0
- package/packages/dd-trace/src/plugins/{outgoing.js → outbound.js} +2 -2
- package/packages/dd-trace/src/plugins/plugin.js +1 -1
- package/packages/dd-trace/src/plugins/producer.js +17 -2
- package/packages/dd-trace/src/plugins/server.js +2 -2
- package/packages/dd-trace/src/plugins/tracing.js +11 -0
- package/packages/dd-trace/src/plugins/util/test.js +19 -1
- package/packages/dd-trace/src/profiling/profilers/cpu.js +1 -1
- package/packages/dd-trace/src/ritm.js +1 -1
- package/packages/dd-trace/src/service-naming/index.js +41 -0
- package/packages/dd-trace/src/service-naming/schemas/definition.js +28 -0
- package/packages/dd-trace/src/service-naming/schemas/index.js +6 -0
- package/packages/dd-trace/src/service-naming/schemas/v0.js +66 -0
- package/packages/dd-trace/src/service-naming/schemas/v1.js +58 -0
- package/packages/dd-trace/src/span_stats.js +1 -1
- package/packages/dd-trace/src/telemetry/dependencies.js +1 -1
- package/packages/dd-trace/src/telemetry/index.js +1 -1
- package/packages/diagnostics_channel/index.js +3 -0
- package/packages/diagnostics_channel/src/index.js +57 -0
- package/packages/dd-trace/src/appsec/callbacks/ddwaf.js +0 -137
- package/packages/dd-trace/src/appsec/callbacks/index.js +0 -7
- package/packages/dd-trace/src/appsec/gateway/als.js +0 -6
- package/packages/dd-trace/src/appsec/gateway/engine/engine.js +0 -140
- package/packages/dd-trace/src/appsec/gateway/engine/index.js +0 -51
- package/packages/dd-trace/src/appsec/gateway/engine/runner.js +0 -42
- package/packages/dd-trace/src/instrumenter.js +0 -203
- package/packages/dd-trace/src/loader.js +0 -131
- package/packages/dd-trace/src/plugins/incoming.js +0 -7
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const shimmer = require('../../datadog-shimmer')
|
|
4
|
-
const log = require('./log')
|
|
5
|
-
const metrics = require('./metrics')
|
|
6
|
-
const Loader = require('./loader')
|
|
7
|
-
const { isTrue } = require('./util')
|
|
8
|
-
const plugins = require('./plugins')
|
|
9
|
-
const Plugin = require('./plugins/plugin')
|
|
10
|
-
const telemetry = require('./telemetry')
|
|
11
|
-
|
|
12
|
-
const disabledPlugins = process.env.DD_TRACE_DISABLED_PLUGINS
|
|
13
|
-
|
|
14
|
-
const collectDisabledPlugins = () => {
|
|
15
|
-
return new Set(disabledPlugins && disabledPlugins.split(',').map(plugin => plugin.trim()))
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function cleanEnv (name) {
|
|
19
|
-
return process.env[`DD_TRACE_${name.toUpperCase()}`.replace(/[^a-z0-9_]/ig, '_')]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function getConfig (name, config = {}) {
|
|
23
|
-
if (!name) {
|
|
24
|
-
return config
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const enabled = cleanEnv(`${name}_ENABLED`)
|
|
28
|
-
if (enabled !== undefined) {
|
|
29
|
-
config.enabled = isTrue(enabled)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return config
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
class Instrumenter {
|
|
36
|
-
constructor (tracer) {
|
|
37
|
-
this._tracer = tracer
|
|
38
|
-
this._loader = new Loader(this)
|
|
39
|
-
this._enabled = false
|
|
40
|
-
this._names = new Set()
|
|
41
|
-
this._plugins = new Map()
|
|
42
|
-
this._instrumented = new Map()
|
|
43
|
-
this._disabledPlugins = collectDisabledPlugins()
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
use (name, config) {
|
|
47
|
-
if (typeof name !== 'string') return
|
|
48
|
-
const plugin = plugins[name.toLowerCase()]
|
|
49
|
-
if (plugin && plugin.prototype instanceof Plugin) return
|
|
50
|
-
if (typeof config === 'boolean') {
|
|
51
|
-
config = { enabled: config }
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
config = getConfig(name, config)
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
this._set(plugin, { name, config })
|
|
58
|
-
telemetry.updateIntegrations()
|
|
59
|
-
} catch (e) {
|
|
60
|
-
log.debug(`Could not find a plugin named "${name}".`)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (this._enabled) {
|
|
64
|
-
this._loader.reload(this._plugins)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
enable (config) {
|
|
69
|
-
config = config || {}
|
|
70
|
-
const serviceMapping = config.serviceMapping
|
|
71
|
-
|
|
72
|
-
this._enabled = true
|
|
73
|
-
|
|
74
|
-
if (config.plugins !== false) {
|
|
75
|
-
Object.keys(plugins)
|
|
76
|
-
.filter(name => !this._plugins.has(plugins[name]))
|
|
77
|
-
.forEach(name => {
|
|
78
|
-
if (plugins[name].prototype instanceof Plugin) return
|
|
79
|
-
const pluginConfig = {}
|
|
80
|
-
if (serviceMapping && serviceMapping[name]) {
|
|
81
|
-
pluginConfig.service = serviceMapping[name]
|
|
82
|
-
}
|
|
83
|
-
this._set(plugins[name], { name, config: getConfig(name, pluginConfig) })
|
|
84
|
-
})
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
this._loader.reload(this._plugins)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
disable () {
|
|
91
|
-
for (const instrumentation of this._instrumented.keys()) {
|
|
92
|
-
this.unpatch(instrumentation)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
this._plugins.clear()
|
|
96
|
-
this._enabled = false
|
|
97
|
-
this._loader.reload(this._plugins)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
wrap (nodules, names, wrapper) {
|
|
101
|
-
shimmer.massWrap(nodules, names, wrapper)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
unwrap (nodules, names, wrapper) {
|
|
105
|
-
shimmer.massUnwrap(nodules, names, wrapper)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
wrapExport (moduleExports, wrapper) {
|
|
109
|
-
return shimmer.wrap(moduleExports, wrapper)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
unwrapExport (moduleExports) {
|
|
113
|
-
return shimmer.unwrap(moduleExports)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
load (plugin, meta) {
|
|
117
|
-
if (!this._enabled) return
|
|
118
|
-
|
|
119
|
-
const instrumentations = [].concat(plugin)
|
|
120
|
-
const enabled = meta.config.enabled !== false
|
|
121
|
-
|
|
122
|
-
metrics.boolean(`datadog.tracer.node.plugin.enabled.by.name`, enabled, `name:${meta.name}`)
|
|
123
|
-
|
|
124
|
-
try {
|
|
125
|
-
instrumentations
|
|
126
|
-
.forEach(instrumentation => {
|
|
127
|
-
this._loader.load(instrumentation, meta.config)
|
|
128
|
-
})
|
|
129
|
-
} catch (e) {
|
|
130
|
-
log.error(e)
|
|
131
|
-
this.unload(plugin)
|
|
132
|
-
log.debug(`Error while trying to patch ${meta.name}. The plugin has been disabled.`)
|
|
133
|
-
|
|
134
|
-
metrics.increment(`datadog.tracer.node.plugin.errors`, true)
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
unload (plugin) {
|
|
139
|
-
[].concat(plugin)
|
|
140
|
-
.forEach(instrumentation => {
|
|
141
|
-
this.unpatch(instrumentation)
|
|
142
|
-
this._instrumented.delete(instrumentation)
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
const meta = this._plugins.get(plugin)
|
|
146
|
-
|
|
147
|
-
if (meta) {
|
|
148
|
-
this._plugins.delete(plugin)
|
|
149
|
-
|
|
150
|
-
metrics.boolean(`datadog.tracer.node.plugin.enabled.by.name`, false, `name:${meta.name}`)
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
patch (instrumentation, moduleExports, config) {
|
|
155
|
-
let instrumented = this._instrumented.get(instrumentation)
|
|
156
|
-
|
|
157
|
-
if (!instrumented) {
|
|
158
|
-
this._instrumented.set(instrumentation, instrumented = new Set())
|
|
159
|
-
telemetry.updateIntegrations()
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (!instrumented.has(this._defaultExport(moduleExports))) {
|
|
163
|
-
try {
|
|
164
|
-
moduleExports = instrumentation.patch.call(this, moduleExports, this._tracer._tracer, config) || moduleExports
|
|
165
|
-
return moduleExports
|
|
166
|
-
} finally {
|
|
167
|
-
// add even on error since `unpatch` will take care of removing it.
|
|
168
|
-
instrumented.add(this._defaultExport(moduleExports))
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
unpatch (instrumentation) {
|
|
174
|
-
const instrumented = this._instrumented.get(instrumentation)
|
|
175
|
-
|
|
176
|
-
if (instrumented) {
|
|
177
|
-
instrumented.forEach(moduleExports => {
|
|
178
|
-
try {
|
|
179
|
-
instrumentation.unpatch.call(this, moduleExports, this._tracer)
|
|
180
|
-
} catch (e) {
|
|
181
|
-
log.error(e)
|
|
182
|
-
}
|
|
183
|
-
})
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
_set (plugin, meta) {
|
|
188
|
-
if (this._disabledPlugins.has(meta.name)) {
|
|
189
|
-
log.debug(`Plugin "${meta.name}" was disabled via configuration option.`)
|
|
190
|
-
} else {
|
|
191
|
-
this._plugins.set(plugin, meta)
|
|
192
|
-
this.load(plugin, meta)
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// ESM modules have a different export between `import` and `require` so we
|
|
197
|
-
// use the default export instead when available.
|
|
198
|
-
_defaultExport (moduleExports) {
|
|
199
|
-
return moduleExports && (moduleExports.default || moduleExports)
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
module.exports = Instrumenter
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const semver = require('semver')
|
|
4
|
-
const Hook = require('../../datadog-instrumentations/src/helpers/hook')
|
|
5
|
-
const parse = require('module-details-from-path')
|
|
6
|
-
const path = require('path')
|
|
7
|
-
const uniq = require('lodash.uniq')
|
|
8
|
-
const log = require('./log')
|
|
9
|
-
const requirePackageJson = require('./require-package-json')
|
|
10
|
-
|
|
11
|
-
const pathSepExpr = new RegExp(`\\${path.sep}`, 'g')
|
|
12
|
-
|
|
13
|
-
class Loader {
|
|
14
|
-
constructor (instrumenter) {
|
|
15
|
-
this._instrumenter = instrumenter
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
reload (plugins) {
|
|
19
|
-
this._plugins = plugins
|
|
20
|
-
this._patched = []
|
|
21
|
-
|
|
22
|
-
const instrumentations = Array.from(this._plugins.keys())
|
|
23
|
-
.reduce((prev, current) => prev.concat(current), [])
|
|
24
|
-
|
|
25
|
-
const instrumentedModules = uniq(instrumentations
|
|
26
|
-
.map(instrumentation => instrumentation.name))
|
|
27
|
-
|
|
28
|
-
this._names = new Set(instrumentations
|
|
29
|
-
.map(instrumentation => filename(instrumentation)))
|
|
30
|
-
|
|
31
|
-
this._hook && this._hook.unhook()
|
|
32
|
-
this._hook = Hook(instrumentedModules, (moduleExports, moduleName, moduleBaseDir) => {
|
|
33
|
-
return this._hookModule(moduleExports, moduleName, moduleBaseDir)
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
load (instrumentation, config) {
|
|
38
|
-
this._getModules(instrumentation).forEach(nodule => {
|
|
39
|
-
this._instrumenter.patch(instrumentation, nodule, config)
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
_getModules (instrumentation) {
|
|
44
|
-
const modules = []
|
|
45
|
-
const ids = Object.keys(require.cache)
|
|
46
|
-
|
|
47
|
-
let pkg
|
|
48
|
-
|
|
49
|
-
for (let i = 0, l = ids.length; i < l; i++) {
|
|
50
|
-
const id = ids[i].replace(pathSepExpr, '/')
|
|
51
|
-
|
|
52
|
-
if (!id.includes(`/node_modules/${instrumentation.name}/`)) continue
|
|
53
|
-
|
|
54
|
-
if (instrumentation.file) {
|
|
55
|
-
if (!id.endsWith(`/node_modules/${filename(instrumentation)}`)) continue
|
|
56
|
-
|
|
57
|
-
const basedir = getBasedir(ids[i])
|
|
58
|
-
|
|
59
|
-
pkg = requirePackageJson(basedir, module)
|
|
60
|
-
} else {
|
|
61
|
-
const basedir = getBasedir(ids[i])
|
|
62
|
-
|
|
63
|
-
pkg = requirePackageJson(basedir, module)
|
|
64
|
-
|
|
65
|
-
const mainFile = path.posix.normalize(pkg.main || 'index.js')
|
|
66
|
-
if (!id.endsWith(`/node_modules/${instrumentation.name}/${mainFile}`)) continue
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (!matchVersion(pkg.version, instrumentation.versions)) continue
|
|
70
|
-
|
|
71
|
-
modules.push(require.cache[ids[i]].exports)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return modules
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
_hookModule (moduleExports, moduleName, moduleBaseDir) {
|
|
78
|
-
moduleName = moduleName.replace(pathSepExpr, '/')
|
|
79
|
-
|
|
80
|
-
if (!this._names.has(moduleName)) {
|
|
81
|
-
return moduleExports
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (moduleBaseDir) {
|
|
85
|
-
moduleBaseDir = moduleBaseDir.replace(pathSepExpr, '/')
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const moduleVersion = getVersion(moduleBaseDir)
|
|
89
|
-
|
|
90
|
-
for (const [plugin, meta] of this._plugins) {
|
|
91
|
-
if (meta.config.enabled === false) {
|
|
92
|
-
continue
|
|
93
|
-
}
|
|
94
|
-
try {
|
|
95
|
-
for (const instrumentation of [].concat(plugin)) {
|
|
96
|
-
if (moduleName !== filename(instrumentation) || !matchVersion(moduleVersion, instrumentation.versions)) {
|
|
97
|
-
continue
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
moduleExports = this._instrumenter.patch(instrumentation, moduleExports, meta.config) || moduleExports
|
|
101
|
-
}
|
|
102
|
-
} catch (e) {
|
|
103
|
-
log.error(e)
|
|
104
|
-
this._instrumenter.unload(plugin)
|
|
105
|
-
log.debug(`Error while trying to patch ${meta.name}. The plugin has been disabled.`)
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return moduleExports
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function getBasedir (id) {
|
|
114
|
-
return parse(id).basedir.replace(pathSepExpr, '/')
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function matchVersion (version, ranges) {
|
|
118
|
-
return !version || (ranges && ranges.some(range => semver.satisfies(semver.coerce(version), range)))
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function getVersion (moduleBaseDir) {
|
|
122
|
-
if (moduleBaseDir) {
|
|
123
|
-
return requirePackageJson(moduleBaseDir, module).version
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function filename (plugin) {
|
|
128
|
-
return [plugin.name, plugin.file].filter(val => val).join('/')
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
module.exports = Loader
|