dd-trace 3.44.0 → 3.46.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/MIGRATING.md +15 -0
- package/README.md +11 -9
- package/package.json +8 -7
- package/packages/datadog-instrumentations/src/cucumber.js +3 -1
- package/packages/datadog-instrumentations/src/jest.js +3 -0
- package/packages/datadog-instrumentations/src/mocha.js +9 -2
- package/packages/datadog-plugin-cucumber/src/index.js +11 -7
- package/packages/datadog-plugin-cypress/src/plugin.js +60 -46
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +2 -0
- package/packages/datadog-plugin-jest/src/index.js +31 -5
- package/packages/datadog-plugin-jest/src/util.js +38 -16
- package/packages/datadog-plugin-mocha/src/index.js +11 -2
- package/packages/datadog-plugin-playwright/src/index.js +2 -0
- package/packages/dd-trace/src/appsec/iast/analyzers/analyzers.js +1 -0
- package/packages/dd-trace/src/appsec/iast/analyzers/header-injection-analyzer.js +3 -3
- package/packages/dd-trace/src/appsec/iast/analyzers/weak-randomness-analyzer.js +19 -0
- package/packages/dd-trace/src/appsec/iast/taint-tracking/csi-methods.js +1 -0
- package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +12 -1
- package/packages/dd-trace/src/appsec/iast/vulnerabilities.js +1 -0
- package/packages/dd-trace/src/appsec/remote_config/manager.js +9 -8
- package/packages/dd-trace/src/appsec/reporter.js +2 -1
- package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +4 -2
- package/packages/dd-trace/src/config.js +11 -7
- package/packages/dd-trace/src/encode/agentless-ci-visibility.js +25 -2
- package/packages/dd-trace/src/plugins/ci_plugin.js +9 -3
- package/packages/dd-trace/src/plugins/util/test.js +2 -0
- package/packages/dd-trace/src/profiling/config.js +32 -3
- package/packages/dd-trace/src/profiling/exporters/file.js +2 -1
- package/packages/dd-trace/src/profiling/profiler.js +18 -14
- package/packages/dd-trace/src/profiling/profilers/events.js +10 -4
- package/packages/dd-trace/src/profiling/profilers/shared.js +6 -0
- package/packages/dd-trace/src/profiling/profilers/space.js +17 -2
- package/packages/dd-trace/src/profiling/profilers/wall.js +34 -21
- package/packages/dd-trace/src/telemetry/index.js +8 -3
- package/packages/dd-trace/src/telemetry/send-data.js +35 -16
- package/scripts/st.js +105 -0
|
@@ -7,7 +7,7 @@ const { HTTP_METHOD, HTTP_ROUTE, RESOURCE_NAME, SPAN_TYPE } = require('../../../
|
|
|
7
7
|
const { WEB } = require('../../../../../ext/types')
|
|
8
8
|
const runtimeMetrics = require('../../runtime_metrics')
|
|
9
9
|
const telemetryMetrics = require('../../telemetry/metrics')
|
|
10
|
-
const { END_TIMESTAMP_LABEL, getThreadLabels } = require('./shared')
|
|
10
|
+
const { END_TIMESTAMP_LABEL, getNonJSThreadsLabels, getThreadLabels } = require('./shared')
|
|
11
11
|
|
|
12
12
|
const beforeCh = dc.channel('dd-trace:storage:before')
|
|
13
13
|
const enterCh = dc.channel('dd-trace:storage:enter')
|
|
@@ -78,13 +78,15 @@ class NativeWallProfiler {
|
|
|
78
78
|
this._codeHotspotsEnabled = !!options.codeHotspotsEnabled
|
|
79
79
|
this._endpointCollectionEnabled = !!options.endpointCollectionEnabled
|
|
80
80
|
this._timelineEnabled = !!options.timelineEnabled
|
|
81
|
+
this._cpuProfilingEnabled = !!options.cpuProfilingEnabled
|
|
81
82
|
// We need to capture span data into the sample context for either code hotspots
|
|
82
83
|
// or endpoint collection.
|
|
83
84
|
this._captureSpanData = this._codeHotspotsEnabled || this._endpointCollectionEnabled
|
|
84
85
|
// We need to run the pprof wall profiler with sample contexts if we're either
|
|
85
86
|
// capturing span data or timeline is enabled (so we need sample timestamps, and for now
|
|
86
|
-
// timestamps require the sample contexts feature in the pprof wall profiler
|
|
87
|
-
|
|
87
|
+
// timestamps require the sample contexts feature in the pprof wall profiler), or
|
|
88
|
+
// cpu profiling is enabled.
|
|
89
|
+
this._withContexts = this._captureSpanData || this._timelineEnabled || this._cpuProfilingEnabled
|
|
88
90
|
this._v8ProfilerBugWorkaroundEnabled = !!options.v8ProfilerBugWorkaroundEnabled
|
|
89
91
|
this._mapper = undefined
|
|
90
92
|
this._pprof = undefined
|
|
@@ -131,7 +133,8 @@ class NativeWallProfiler {
|
|
|
131
133
|
sourceMapper: this._mapper,
|
|
132
134
|
withContexts: this._withContexts,
|
|
133
135
|
lineNumbers: false,
|
|
134
|
-
workaroundV8Bug: this._v8ProfilerBugWorkaroundEnabled
|
|
136
|
+
workaroundV8Bug: this._v8ProfilerBugWorkaroundEnabled,
|
|
137
|
+
collectCpuTime: this._cpuProfilingEnabled
|
|
135
138
|
})
|
|
136
139
|
|
|
137
140
|
if (this._withContexts) {
|
|
@@ -220,22 +223,42 @@ class NativeWallProfiler {
|
|
|
220
223
|
|
|
221
224
|
_stop (restart) {
|
|
222
225
|
if (!this._started) return
|
|
226
|
+
|
|
223
227
|
if (this._captureSpanData) {
|
|
224
228
|
// update last sample context if needed
|
|
225
229
|
this._enter()
|
|
226
230
|
this._lastSampleCount = 0
|
|
227
231
|
}
|
|
228
232
|
const profile = this._pprof.time.stop(restart, this._generateLabels)
|
|
233
|
+
|
|
229
234
|
if (restart) {
|
|
230
235
|
const v8BugDetected = this._pprof.time.v8ProfilerStuckEventLoopDetected()
|
|
231
236
|
if (v8BugDetected !== 0) {
|
|
232
237
|
this._reportV8bug(v8BugDetected === 1)
|
|
233
238
|
}
|
|
239
|
+
} else {
|
|
240
|
+
if (this._captureSpanData) {
|
|
241
|
+
beforeCh.unsubscribe(this._enter)
|
|
242
|
+
enterCh.unsubscribe(this._enter)
|
|
243
|
+
spanFinishCh.unsubscribe(this._spanFinished)
|
|
244
|
+
this._profilerState = undefined
|
|
245
|
+
this._lastSpan = undefined
|
|
246
|
+
this._lastStartedSpans = undefined
|
|
247
|
+
this._lastWebTags = undefined
|
|
248
|
+
}
|
|
249
|
+
this._started = false
|
|
234
250
|
}
|
|
251
|
+
|
|
235
252
|
return profile
|
|
236
253
|
}
|
|
237
254
|
|
|
238
|
-
_generateLabels (context) {
|
|
255
|
+
_generateLabels ({ node, context }) {
|
|
256
|
+
// check for special node that represents CPU time all non-JS threads.
|
|
257
|
+
// In that case only return a special thread name label since we cannot associate any timestamp/span/endpoint to it.
|
|
258
|
+
if (node.name === this._pprof.time.constants.NON_JS_THREADS_FUNCTION_NAME) {
|
|
259
|
+
return getNonJSThreadsLabels()
|
|
260
|
+
}
|
|
261
|
+
|
|
239
262
|
if (context == null) {
|
|
240
263
|
// generateLabels is also called for samples without context.
|
|
241
264
|
// In that case just return thread labels.
|
|
@@ -267,8 +290,8 @@ class NativeWallProfiler {
|
|
|
267
290
|
return labels
|
|
268
291
|
}
|
|
269
292
|
|
|
270
|
-
profile () {
|
|
271
|
-
return this._stop(
|
|
293
|
+
profile (restart) {
|
|
294
|
+
return this._stop(restart)
|
|
272
295
|
}
|
|
273
296
|
|
|
274
297
|
encode (profile) {
|
|
@@ -276,21 +299,11 @@ class NativeWallProfiler {
|
|
|
276
299
|
}
|
|
277
300
|
|
|
278
301
|
stop () {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const profile = this._stop(false)
|
|
282
|
-
if (this._captureSpanData) {
|
|
283
|
-
beforeCh.unsubscribe(this._enter)
|
|
284
|
-
enterCh.unsubscribe(this._enter)
|
|
285
|
-
spanFinishCh.unsubscribe(this._spanFinished)
|
|
286
|
-
this._profilerState = undefined
|
|
287
|
-
this._lastSpan = undefined
|
|
288
|
-
this._lastStartedSpans = undefined
|
|
289
|
-
this._lastWebTags = undefined
|
|
290
|
-
}
|
|
302
|
+
this._stop(false)
|
|
303
|
+
}
|
|
291
304
|
|
|
292
|
-
|
|
293
|
-
return
|
|
305
|
+
isStarted () {
|
|
306
|
+
return this._started
|
|
294
307
|
}
|
|
295
308
|
}
|
|
296
309
|
|
|
@@ -140,8 +140,7 @@ function appStarted (config) {
|
|
|
140
140
|
return app
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
function
|
|
144
|
-
process.removeListener('beforeExit', onBeforeExit)
|
|
143
|
+
function appClosing () {
|
|
145
144
|
const { reqType, payload } = createPayload('app-closing')
|
|
146
145
|
sendData(config, application, host, reqType, payload)
|
|
147
146
|
// we flush before shutting down. Only in CI Visibility
|
|
@@ -150,6 +149,11 @@ function onBeforeExit () {
|
|
|
150
149
|
}
|
|
151
150
|
}
|
|
152
151
|
|
|
152
|
+
function onBeforeExit () {
|
|
153
|
+
process.removeListener('beforeExit', onBeforeExit)
|
|
154
|
+
appClosing()
|
|
155
|
+
}
|
|
156
|
+
|
|
153
157
|
function createAppObject (config) {
|
|
154
158
|
return {
|
|
155
159
|
service_name: config.service,
|
|
@@ -339,5 +343,6 @@ module.exports = {
|
|
|
339
343
|
start,
|
|
340
344
|
stop,
|
|
341
345
|
updateIntegrations,
|
|
342
|
-
updateConfig
|
|
346
|
+
updateConfig,
|
|
347
|
+
appClosing
|
|
343
348
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
const request = require('../exporters/common/request')
|
|
3
3
|
const log = require('../log')
|
|
4
|
+
const { isTrue } = require('../util')
|
|
5
|
+
|
|
4
6
|
let agentTelemetry = true
|
|
5
7
|
|
|
6
8
|
function getHeaders (config, application, reqType) {
|
|
@@ -15,9 +17,22 @@ function getHeaders (config, application, reqType) {
|
|
|
15
17
|
if (debug) {
|
|
16
18
|
headers['dd-telemetry-debug-enabled'] = 'true'
|
|
17
19
|
}
|
|
20
|
+
if (config.apiKey) {
|
|
21
|
+
headers['dd-api-key'] = config.apiKey
|
|
22
|
+
}
|
|
18
23
|
return headers
|
|
19
24
|
}
|
|
20
25
|
|
|
26
|
+
function getAgentlessTelemetryEndpoint (site) {
|
|
27
|
+
if (site === 'datad0g.com') { // staging
|
|
28
|
+
return 'https://all-http-intake.logs.datad0g.com'
|
|
29
|
+
}
|
|
30
|
+
if (site === 'datadoghq.eu') {
|
|
31
|
+
return 'https://instrumentation-telemetry-intake.eu1.datadoghq.com'
|
|
32
|
+
}
|
|
33
|
+
return `https://instrumentation-telemetry-intake.${site}`
|
|
34
|
+
}
|
|
35
|
+
|
|
21
36
|
let seqId = 0
|
|
22
37
|
|
|
23
38
|
function getPayload (payload) {
|
|
@@ -35,17 +50,32 @@ function sendData (config, application, host, reqType, payload = {}, cb = () =>
|
|
|
35
50
|
const {
|
|
36
51
|
hostname,
|
|
37
52
|
port,
|
|
38
|
-
|
|
53
|
+
isCiVisibility
|
|
39
54
|
} = config
|
|
40
55
|
|
|
56
|
+
let url = config.url
|
|
57
|
+
|
|
58
|
+
const isCiVisibilityAgentlessMode = isCiVisibility && isTrue(process.env.DD_CIVISIBILITY_AGENTLESS_ENABLED)
|
|
59
|
+
|
|
60
|
+
if (isCiVisibilityAgentlessMode) {
|
|
61
|
+
try {
|
|
62
|
+
url = url || new URL(getAgentlessTelemetryEndpoint(config.site))
|
|
63
|
+
} catch (err) {
|
|
64
|
+
log.error(err)
|
|
65
|
+
// No point to do the request if the URL is invalid
|
|
66
|
+
return cb(err, { payload, reqType })
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
41
70
|
const options = {
|
|
42
71
|
url,
|
|
43
72
|
hostname,
|
|
44
73
|
port,
|
|
45
74
|
method: 'POST',
|
|
46
|
-
path: '/telemetry/proxy/api/v2/apmtelemetry',
|
|
75
|
+
path: isCiVisibilityAgentlessMode ? '/api/v2/apmtelemetry' : '/telemetry/proxy/api/v2/apmtelemetry',
|
|
47
76
|
headers: getHeaders(config, application, reqType)
|
|
48
77
|
}
|
|
78
|
+
|
|
49
79
|
const data = JSON.stringify({
|
|
50
80
|
api_version: 'v2',
|
|
51
81
|
naming_schema_version: config.spanAttributeSchema ? config.spanAttributeSchema : '',
|
|
@@ -65,24 +95,13 @@ function sendData (config, application, host, reqType, payload = {}, cb = () =>
|
|
|
65
95
|
agentTelemetry = false
|
|
66
96
|
}
|
|
67
97
|
// figure out which data center to send to
|
|
68
|
-
|
|
69
|
-
const dataCenters = [
|
|
70
|
-
'datadoghq.com',
|
|
71
|
-
'us3.datadoghq.com',
|
|
72
|
-
'us5.datadoghq.com',
|
|
73
|
-
'ap1.datadoghq.com',
|
|
74
|
-
'eu1.datadoghq.com'
|
|
75
|
-
]
|
|
76
|
-
if (config.site === 'datad0g.com') { // staging
|
|
77
|
-
backendUrl = 'https://all-http-intake.logs.datad0g.com/api/v2/apmtelemetry'
|
|
78
|
-
} else if (dataCenters.includes(config.site)) {
|
|
79
|
-
backendUrl = 'https://instrumentation-telemetry-intake.' + config.site + '/api/v2/apmtelemetry'
|
|
80
|
-
}
|
|
98
|
+
const backendUrl = getAgentlessTelemetryEndpoint(config.site)
|
|
81
99
|
const backendHeader = { ...options.headers, 'DD-API-KEY': process.env.DD_API_KEY }
|
|
82
100
|
const backendOptions = {
|
|
83
101
|
...options,
|
|
84
102
|
url: backendUrl,
|
|
85
|
-
headers: backendHeader
|
|
103
|
+
headers: backendHeader,
|
|
104
|
+
path: '/api/v2/apmtelemetry'
|
|
86
105
|
}
|
|
87
106
|
if (backendUrl) {
|
|
88
107
|
request(data, backendOptions, (error) => { log.error(error) })
|
package/scripts/st.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable no-console, no-fallthrough */
|
|
3
|
+
'use strict'
|
|
4
|
+
|
|
5
|
+
const path = require('path')
|
|
6
|
+
const { writeFileSync } = require('fs')
|
|
7
|
+
const { execSync } = require('child_process')
|
|
8
|
+
|
|
9
|
+
const ddtracePath = path.join(__dirname, '..')
|
|
10
|
+
const defaultTestPath = process.env.DD_ST_PATH || path.join(ddtracePath, '..', 'system-tests')
|
|
11
|
+
|
|
12
|
+
const { buildAll, npm, testDir, testArgs } = parseArgs()
|
|
13
|
+
|
|
14
|
+
const binariesPath = path.join(testDir, 'binaries')
|
|
15
|
+
|
|
16
|
+
if (npm) {
|
|
17
|
+
console.log('Using NPM package:', npm)
|
|
18
|
+
|
|
19
|
+
writeFileSync(path.join(binariesPath, 'nodejs-load-from-npm'), npm)
|
|
20
|
+
} else {
|
|
21
|
+
console.log('Using local repo')
|
|
22
|
+
|
|
23
|
+
const packName = execSync(`npm pack ${ddtracePath}`, {
|
|
24
|
+
cwd: binariesPath,
|
|
25
|
+
stdio: [null, null, 'inherit'],
|
|
26
|
+
encoding: 'utf8'
|
|
27
|
+
}).slice(0, -1) // remove trailing newline
|
|
28
|
+
|
|
29
|
+
writeFileSync(path.join(binariesPath, 'nodejs-load-from-npm'), `/binaries/${packName}`)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
execSync(`./build.sh ${buildAll ? '' : '-i weblog'} && ./run.sh ${testArgs}`, {
|
|
34
|
+
cwd: testDir,
|
|
35
|
+
stdio: [null, 'inherit', 'inherit']
|
|
36
|
+
})
|
|
37
|
+
} catch (err) {
|
|
38
|
+
process.exit(err.status || 1)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function parseArgs () {
|
|
42
|
+
const args = {
|
|
43
|
+
buildAll: false,
|
|
44
|
+
npm: null,
|
|
45
|
+
testDir: defaultTestPath,
|
|
46
|
+
testArgs: ''
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
for (let i = 2; i < process.argv.length; i++) {
|
|
50
|
+
switch (process.argv[i]) {
|
|
51
|
+
case '-b':
|
|
52
|
+
case '--build-all':
|
|
53
|
+
args.buildAll = true
|
|
54
|
+
break
|
|
55
|
+
|
|
56
|
+
case '-h':
|
|
57
|
+
case '--help':
|
|
58
|
+
helpAndExit()
|
|
59
|
+
break
|
|
60
|
+
|
|
61
|
+
case '-n':
|
|
62
|
+
case '--npm': {
|
|
63
|
+
const arg = process.argv[i + 1]
|
|
64
|
+
if (!arg || arg[0] === '-') {
|
|
65
|
+
args.npm = 'dd-trace'
|
|
66
|
+
} else {
|
|
67
|
+
args.npm = arg
|
|
68
|
+
i++
|
|
69
|
+
}
|
|
70
|
+
break
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
case '-t':
|
|
74
|
+
case '--test-dir': {
|
|
75
|
+
const arg = process.argv[++i]
|
|
76
|
+
if (!arg || arg[0] === '-') helpAndExit()
|
|
77
|
+
args.testDir = arg
|
|
78
|
+
break
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
case '--':
|
|
82
|
+
args.testArgs = process.argv.slice(i + 1).join(' ')
|
|
83
|
+
return args
|
|
84
|
+
|
|
85
|
+
default:
|
|
86
|
+
console.log('Unknown option:', process.argv[i], '\n')
|
|
87
|
+
helpAndExit()
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return args
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function helpAndExit () {
|
|
95
|
+
console.log('Usage: node st.js [options...] [-- test-args]')
|
|
96
|
+
console.log('Options:')
|
|
97
|
+
console.log(' -b, --build-all Rebuild all images (default: only build weblog)')
|
|
98
|
+
console.log(' -h, --help Print this message')
|
|
99
|
+
console.log(' -n, --npm [package] Build a remote package instead of the local repo (default: "dd-trace")')
|
|
100
|
+
console.log(' Can be a package name (e.g. "dd-trace@4.2.0") or a git URL (e.g.')
|
|
101
|
+
console.log(' "git+https://github.com/DataDog/dd-trace-js.git#mybranch")')
|
|
102
|
+
console.log(' -t, --test-dir <path> Specify the system-tests directory (default: "dd-trace/../system-tests/")')
|
|
103
|
+
console.log(' -- <test-args> Passed to system-tests run.sh (e.g. "-- SCENARIO_NAME tests/path_to_test.py")')
|
|
104
|
+
process.exit()
|
|
105
|
+
}
|