dd-trace 4.23.0 → 4.25.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 +6 -5
- 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
package/MIGRATING.md
CHANGED
|
@@ -4,6 +4,21 @@ This guide describes the steps to upgrade dd-trace from a major version to the
|
|
|
4
4
|
next. If you are having any issues related to migrating, please feel free to
|
|
5
5
|
open an issue or contact our [support](https://www.datadoghq.com/support/) team.
|
|
6
6
|
|
|
7
|
+
## 4.0 to 5.0
|
|
8
|
+
|
|
9
|
+
### Node 16 is no longer supported
|
|
10
|
+
|
|
11
|
+
Node.js 16 has reached EOL in September 2023 and is no longer supported. Generally
|
|
12
|
+
speaking, we highly recommend always keeping Node.js up to date regardless of
|
|
13
|
+
our support policy.
|
|
14
|
+
|
|
15
|
+
### Update `trace<T>` TypeScript declaration
|
|
16
|
+
|
|
17
|
+
The TypeScript declaration for `trace<T>` has been updated to enforce
|
|
18
|
+
that calls to `tracer.trace(name, fn)` must receive a function which takes at least
|
|
19
|
+
the span object. Previously the span was technically optional when it should not have
|
|
20
|
+
been as the span must be handled.
|
|
21
|
+
|
|
7
22
|
## 3.0 to 4.0
|
|
8
23
|
|
|
9
24
|
### Node 14 is no longer supported
|
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# `dd-trace`: Node.js APM Tracer Library
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/dd-trace)
|
|
4
|
+
[](https://www.npmjs.com/package/dd-trace/v/latest-node16)
|
|
5
|
+
[](https://www.npmjs.com/package/dd-trace/v/latest-node14)
|
|
5
6
|
[](https://codecov.io/gh/DataDog/dd-trace-js)
|
|
6
7
|
|
|
7
8
|
<img align="right" src="https://user-images.githubusercontent.com/551402/208212084-1d0c07e2-4135-4c61-b2da-8f2fddbc66ed.png" alt="Bits the dog JavaScript" width="200px"/>
|
|
@@ -28,24 +29,25 @@ Most of the documentation for `dd-trace` is available on these webpages:
|
|
|
28
29
|
| [`v1`](https://github.com/DataDog/dd-trace-js/tree/v1.x) |  | `>= v12` | **End of Life** | 2021-07-13 | 2022-02-25 |
|
|
29
30
|
| [`v2`](https://github.com/DataDog/dd-trace-js/tree/v2.x) |  | `>= v12` | **End of Life** | 2022-01-28 | 2023-08-15 |
|
|
30
31
|
| [`v3`](https://github.com/DataDog/dd-trace-js/tree/v3.x) |  | `>= v14` | **Maintenance** | 2022-08-15 | 2024-05-15 |
|
|
31
|
-
| [`v4`](https://github.com/DataDog/dd-trace-js/tree/v4.x) |  | `>= v16` | **
|
|
32
|
+
| [`v4`](https://github.com/DataDog/dd-trace-js/tree/v4.x) |  | `>= v16` | **Maintenance** | 2023-05-12 | 2025-01-11 |
|
|
33
|
+
| [`v5`](https://github.com/DataDog/dd-trace-js/tree/v5.x) |  | `>= v18` | **Current** | 2024-01-11 | Unknown |
|
|
32
34
|
|
|
33
|
-
We currently maintain
|
|
34
|
-
Features and bug fixes that are merged are released to the `
|
|
35
|
+
We currently maintain three release lines, namely `v5`, `v4` and `v3`.
|
|
36
|
+
Features and bug fixes that are merged are released to the `v5` line and, if appropriate, also the `v4` & `v3` line.
|
|
35
37
|
|
|
36
|
-
For any new projects it is recommended to use the `
|
|
38
|
+
For any new projects it is recommended to use the `v5` release line:
|
|
37
39
|
|
|
38
40
|
```sh
|
|
39
41
|
$ npm install dd-trace
|
|
40
42
|
$ yarn add dd-trace
|
|
41
43
|
```
|
|
42
44
|
|
|
43
|
-
However, existing projects that already use the `v3` release line, or projects that need to support EOL versions of Node.js, may continue to use these release lines.
|
|
45
|
+
However, existing projects that already use the `v4` & `v3` release line, or projects that need to support EOL versions of Node.js, may continue to use these release lines.
|
|
44
46
|
This is done by specifying the version when installing the package.
|
|
45
47
|
|
|
46
48
|
```sh
|
|
47
|
-
$ npm install dd-trace@
|
|
48
|
-
$ yarn add dd-trace@
|
|
49
|
+
$ npm install dd-trace@4
|
|
50
|
+
$ yarn add dd-trace@4
|
|
49
51
|
```
|
|
50
52
|
|
|
51
53
|
Any backwards-breaking functionality that is introduced into the library will result in an increase of the major version of the library and therefore a new release line.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dd-trace",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.25.0",
|
|
4
4
|
"description": "Datadog APM tracing client for JavaScript",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"test:integration:cucumber": "mocha --colors --timeout 30000 \"integration-tests/cucumber/*.spec.js\"",
|
|
37
37
|
"test:integration:cypress": "mocha --colors --timeout 30000 \"integration-tests/cypress/*.spec.js\"",
|
|
38
38
|
"test:integration:playwright": "mocha --colors --timeout 30000 \"integration-tests/playwright/*.spec.js\"",
|
|
39
|
+
"test:integration:profiler": "mocha --colors --timeout 90000 \"integration-tests/profiler/*.spec.js\"",
|
|
39
40
|
"test:integration:serverless": "mocha --colors --timeout 30000 \"integration-tests/serverless/*.spec.js\"",
|
|
40
41
|
"test:integration:plugins": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/integration-test/**/*.spec.js\"",
|
|
41
42
|
"test:unit:plugins": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-instrumentations/test/@($(echo $PLUGINS)).spec.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/**/*.spec.js\" --exclude \"packages/datadog-plugin-@($(echo $PLUGINS))/test/integration-test/**/*.spec.js\"",
|
|
@@ -68,24 +69,24 @@
|
|
|
68
69
|
"node": ">=16"
|
|
69
70
|
},
|
|
70
71
|
"dependencies": {
|
|
71
|
-
"@datadog/native-appsec": "
|
|
72
|
+
"@datadog/native-appsec": "7.0.0",
|
|
72
73
|
"@datadog/native-iast-rewriter": "2.2.2",
|
|
73
74
|
"@datadog/native-iast-taint-tracking": "1.6.4",
|
|
74
75
|
"@datadog/native-metrics": "^2.0.0",
|
|
75
|
-
"@datadog/pprof": "
|
|
76
|
+
"@datadog/pprof": "5.0.0",
|
|
76
77
|
"@datadog/sketches-js": "^2.1.0",
|
|
77
78
|
"@opentelemetry/api": "^1.0.0",
|
|
78
79
|
"@opentelemetry/core": "^1.14.0",
|
|
79
80
|
"crypto-randomuuid": "^1.0.0",
|
|
80
81
|
"dc-polyfill": "^0.1.2",
|
|
81
82
|
"ignore": "^5.2.4",
|
|
82
|
-
"import-in-the-middle": "^1.7.
|
|
83
|
+
"import-in-the-middle": "^1.7.3",
|
|
83
84
|
"int64-buffer": "^0.1.9",
|
|
84
85
|
"ipaddr.js": "^2.1.0",
|
|
85
86
|
"istanbul-lib-coverage": "3.2.0",
|
|
86
87
|
"jest-docblock": "^29.7.0",
|
|
87
88
|
"koalas": "^1.0.2",
|
|
88
|
-
"limiter": "
|
|
89
|
+
"limiter": "1.1.5",
|
|
89
90
|
"lodash.kebabcase": "^4.1.1",
|
|
90
91
|
"lodash.pick": "^4.4.0",
|
|
91
92
|
"lodash.sortby": "^4.7.0",
|
|
@@ -44,6 +44,7 @@ const patched = new WeakSet()
|
|
|
44
44
|
let pickleByFile = {}
|
|
45
45
|
const pickleResultByFile = {}
|
|
46
46
|
let skippableSuites = []
|
|
47
|
+
let itrCorrelationId = ''
|
|
47
48
|
let isForcedToRun = false
|
|
48
49
|
let isUnskippable = false
|
|
49
50
|
|
|
@@ -102,7 +103,7 @@ function wrapRun (pl, isLatestVersion) {
|
|
|
102
103
|
const testSuitePath = getTestSuitePath(testSuiteFullPath, process.cwd())
|
|
103
104
|
isForcedToRun = isUnskippable && skippableSuites.includes(testSuitePath)
|
|
104
105
|
|
|
105
|
-
testSuiteStartCh.publish({ testSuitePath, isUnskippable, isForcedToRun })
|
|
106
|
+
testSuiteStartCh.publish({ testSuitePath, isUnskippable, isForcedToRun, itrCorrelationId })
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
const testSourceLine = this.gherkinDocument &&
|
|
@@ -304,6 +305,7 @@ addHook({
|
|
|
304
305
|
this.pickleIds = picklesToRun
|
|
305
306
|
|
|
306
307
|
skippedSuites = Array.from(filteredPickles.skippedSuites)
|
|
308
|
+
itrCorrelationId = skippableResponse.itrCorrelationId
|
|
307
309
|
}
|
|
308
310
|
|
|
309
311
|
pickleByFile = getPickleByFile(this)
|
|
@@ -53,6 +53,7 @@ let isSuitesSkipped = false
|
|
|
53
53
|
let skippedSuites = []
|
|
54
54
|
const unskippableSuites = []
|
|
55
55
|
let isForcedToRun = false
|
|
56
|
+
let itrCorrelationId = ''
|
|
56
57
|
|
|
57
58
|
function getSuitesByTestFile (root) {
|
|
58
59
|
const suitesByTestFile = {}
|
|
@@ -191,7 +192,12 @@ function mochaHook (Runner) {
|
|
|
191
192
|
const isUnskippable = unskippableSuites.includes(suite.file)
|
|
192
193
|
isForcedToRun = isUnskippable && suitesToSkip.includes(getTestSuitePath(suite.file, process.cwd()))
|
|
193
194
|
asyncResource.runInAsyncScope(() => {
|
|
194
|
-
testSuiteStartCh.publish({
|
|
195
|
+
testSuiteStartCh.publish({
|
|
196
|
+
testSuite: suite.file,
|
|
197
|
+
isUnskippable,
|
|
198
|
+
isForcedToRun,
|
|
199
|
+
itrCorrelationId
|
|
200
|
+
})
|
|
195
201
|
})
|
|
196
202
|
}
|
|
197
203
|
})
|
|
@@ -395,11 +401,12 @@ addHook({
|
|
|
395
401
|
}
|
|
396
402
|
})
|
|
397
403
|
|
|
398
|
-
const onReceivedSkippableSuites = ({ err, skippableSuites }) => {
|
|
404
|
+
const onReceivedSkippableSuites = ({ err, skippableSuites, itrCorrelationId: responseItrCorrelationId }) => {
|
|
399
405
|
if (err) {
|
|
400
406
|
suitesToSkip = []
|
|
401
407
|
} else {
|
|
402
408
|
suitesToSkip = skippableSuites
|
|
409
|
+
itrCorrelationId = responseItrCorrelationId
|
|
403
410
|
}
|
|
404
411
|
// We remove the suites that we skip through ITR
|
|
405
412
|
const filteredSuites = getFilteredSuites(runner.suite.suites)
|
|
@@ -13,7 +13,8 @@ const {
|
|
|
13
13
|
addIntelligentTestRunnerSpanTags,
|
|
14
14
|
TEST_ITR_UNSKIPPABLE,
|
|
15
15
|
TEST_ITR_FORCED_RUN,
|
|
16
|
-
TEST_CODE_OWNERS
|
|
16
|
+
TEST_CODE_OWNERS,
|
|
17
|
+
ITR_CORRELATION_ID
|
|
17
18
|
} = require('../../dd-trace/src/plugins/util/test')
|
|
18
19
|
const { RESOURCE_NAME } = require('../../../ext/tags')
|
|
19
20
|
const { COMPONENT, ERROR_MESSAGE } = require('../../dd-trace/src/constants')
|
|
@@ -74,7 +75,7 @@ class CucumberPlugin extends CiPlugin {
|
|
|
74
75
|
this.tracer._exporter.flush()
|
|
75
76
|
})
|
|
76
77
|
|
|
77
|
-
this.addSub('ci:cucumber:test-suite:start', ({ testSuitePath, isUnskippable, isForcedToRun }) => {
|
|
78
|
+
this.addSub('ci:cucumber:test-suite:start', ({ testSuitePath, isUnskippable, isForcedToRun, itrCorrelationId }) => {
|
|
78
79
|
const testSuiteMetadata = getTestSuiteCommonTags(
|
|
79
80
|
this.command,
|
|
80
81
|
this.frameworkVersion,
|
|
@@ -89,6 +90,9 @@ class CucumberPlugin extends CiPlugin {
|
|
|
89
90
|
this.telemetry.count(TELEMETRY_ITR_FORCED_TO_RUN, { testLevel: 'suite' })
|
|
90
91
|
testSuiteMetadata[TEST_ITR_FORCED_RUN] = 'true'
|
|
91
92
|
}
|
|
93
|
+
if (itrCorrelationId) {
|
|
94
|
+
testSuiteMetadata[ITR_CORRELATION_ID] = itrCorrelationId
|
|
95
|
+
}
|
|
92
96
|
this.testSuiteSpan = this.tracer.startSpan('cucumber.test_suite', {
|
|
93
97
|
childOf: this.testModuleSpan,
|
|
94
98
|
tags: {
|
|
@@ -169,12 +173,12 @@ class CucumberPlugin extends CiPlugin {
|
|
|
169
173
|
}
|
|
170
174
|
|
|
171
175
|
span.finish()
|
|
172
|
-
this.telemetry.ciVisEvent(
|
|
173
|
-
TELEMETRY_EVENT_FINISHED,
|
|
174
|
-
'test',
|
|
175
|
-
{ hasCodeOwners: !!span.context()._tags[TEST_CODE_OWNERS] }
|
|
176
|
-
)
|
|
177
176
|
if (!isStep) {
|
|
177
|
+
this.telemetry.ciVisEvent(
|
|
178
|
+
TELEMETRY_EVENT_FINISHED,
|
|
179
|
+
'test',
|
|
180
|
+
{ hasCodeOwners: !!span.context()._tags[TEST_CODE_OWNERS] }
|
|
181
|
+
)
|
|
178
182
|
finishAllTraceSpans(span)
|
|
179
183
|
}
|
|
180
184
|
})
|
|
@@ -23,7 +23,8 @@ const {
|
|
|
23
23
|
addIntelligentTestRunnerSpanTags,
|
|
24
24
|
TEST_SKIPPED_BY_ITR,
|
|
25
25
|
TEST_ITR_UNSKIPPABLE,
|
|
26
|
-
TEST_ITR_FORCED_RUN
|
|
26
|
+
TEST_ITR_FORCED_RUN,
|
|
27
|
+
ITR_CORRELATION_ID
|
|
27
28
|
} = require('../../dd-trace/src/plugins/util/test')
|
|
28
29
|
const { ORIGIN_KEY, COMPONENT } = require('../../dd-trace/src/constants')
|
|
29
30
|
const log = require('../../dd-trace/src/log')
|
|
@@ -39,6 +40,7 @@ const {
|
|
|
39
40
|
incrementCountMetric,
|
|
40
41
|
distributionMetric
|
|
41
42
|
} = require('../../dd-trace/src/ci-visibility/telemetry')
|
|
43
|
+
const { appClosing: appClosingTelemetry } = require('../../dd-trace/src/telemetry')
|
|
42
44
|
const {
|
|
43
45
|
GIT_REPOSITORY_URL,
|
|
44
46
|
GIT_COMMIT_SHA,
|
|
@@ -137,10 +139,11 @@ function getSkippableTests (isSuitesSkippingEnabled, tracer, testConfiguration)
|
|
|
137
139
|
if (!tracer._tracer._exporter || !tracer._tracer._exporter.getItrConfiguration) {
|
|
138
140
|
return resolve({ err: new Error('CI Visibility was not initialized correctly') })
|
|
139
141
|
}
|
|
140
|
-
tracer._tracer._exporter.getSkippableSuites(testConfiguration, (err, skippableTests) => {
|
|
142
|
+
tracer._tracer._exporter.getSkippableSuites(testConfiguration, (err, skippableTests, correlationId) => {
|
|
141
143
|
resolve({
|
|
142
144
|
err,
|
|
143
|
-
skippableTests
|
|
145
|
+
skippableTests,
|
|
146
|
+
correlationId
|
|
144
147
|
})
|
|
145
148
|
})
|
|
146
149
|
})
|
|
@@ -214,6 +217,7 @@ module.exports = (on, config) => {
|
|
|
214
217
|
let isSuitesSkippingEnabled = false
|
|
215
218
|
let isCodeCoverageEnabled = false
|
|
216
219
|
let testsToSkip = []
|
|
220
|
+
let itrCorrelationId = ''
|
|
217
221
|
const unskippableSuites = []
|
|
218
222
|
let hasForcedToRunSuites = false
|
|
219
223
|
let hasUnskippableSuites = false
|
|
@@ -288,52 +292,54 @@ module.exports = (on, config) => {
|
|
|
288
292
|
isCodeCoverageEnabled = itrConfig.isCodeCoverageEnabled
|
|
289
293
|
}
|
|
290
294
|
|
|
291
|
-
return getSkippableTests(isSuitesSkippingEnabled, tracer, testConfiguration)
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
// `details.specs` are test files
|
|
299
|
-
details.specs.forEach(({ absolute, relative }) => {
|
|
300
|
-
const isUnskippableSuite = isMarkedAsUnskippable({ path: absolute })
|
|
301
|
-
if (isUnskippableSuite) {
|
|
302
|
-
unskippableSuites.push(relative)
|
|
295
|
+
return getSkippableTests(isSuitesSkippingEnabled, tracer, testConfiguration)
|
|
296
|
+
.then(({ err, skippableTests, correlationId }) => {
|
|
297
|
+
if (err) {
|
|
298
|
+
log.error(err)
|
|
299
|
+
} else {
|
|
300
|
+
testsToSkip = skippableTests || []
|
|
301
|
+
itrCorrelationId = correlationId
|
|
303
302
|
}
|
|
304
|
-
})
|
|
305
|
-
|
|
306
|
-
const childOf = getTestParentSpan(tracer)
|
|
307
|
-
rootDir = getRootDir(details)
|
|
308
|
-
|
|
309
|
-
command = getCypressCommand(details)
|
|
310
|
-
frameworkVersion = getCypressVersion(details)
|
|
311
|
-
|
|
312
|
-
const testSessionSpanMetadata = getTestSessionCommonTags(command, frameworkVersion, TEST_FRAMEWORK_NAME)
|
|
313
|
-
const testModuleSpanMetadata = getTestModuleCommonTags(command, frameworkVersion, TEST_FRAMEWORK_NAME)
|
|
314
303
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
304
|
+
// `details.specs` are test files
|
|
305
|
+
details.specs.forEach(({ absolute, relative }) => {
|
|
306
|
+
const isUnskippableSuite = isMarkedAsUnskippable({ path: absolute })
|
|
307
|
+
if (isUnskippableSuite) {
|
|
308
|
+
unskippableSuites.push(relative)
|
|
309
|
+
}
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
const childOf = getTestParentSpan(tracer)
|
|
313
|
+
rootDir = getRootDir(details)
|
|
314
|
+
|
|
315
|
+
command = getCypressCommand(details)
|
|
316
|
+
frameworkVersion = getCypressVersion(details)
|
|
317
|
+
|
|
318
|
+
const testSessionSpanMetadata = getTestSessionCommonTags(command, frameworkVersion, TEST_FRAMEWORK_NAME)
|
|
319
|
+
const testModuleSpanMetadata = getTestModuleCommonTags(command, frameworkVersion, TEST_FRAMEWORK_NAME)
|
|
320
|
+
|
|
321
|
+
testSessionSpan = tracer.startSpan(`${TEST_FRAMEWORK_NAME}.test_session`, {
|
|
322
|
+
childOf,
|
|
323
|
+
tags: {
|
|
324
|
+
[COMPONENT]: TEST_FRAMEWORK_NAME,
|
|
325
|
+
...testEnvironmentMetadata,
|
|
326
|
+
...testSessionSpanMetadata
|
|
327
|
+
}
|
|
328
|
+
})
|
|
329
|
+
ciVisEvent(TELEMETRY_EVENT_CREATED, 'session')
|
|
330
|
+
|
|
331
|
+
testModuleSpan = tracer.startSpan(`${TEST_FRAMEWORK_NAME}.test_module`, {
|
|
332
|
+
childOf: testSessionSpan,
|
|
333
|
+
tags: {
|
|
334
|
+
[COMPONENT]: TEST_FRAMEWORK_NAME,
|
|
335
|
+
...testEnvironmentMetadata,
|
|
336
|
+
...testModuleSpanMetadata
|
|
337
|
+
}
|
|
338
|
+
})
|
|
339
|
+
ciVisEvent(TELEMETRY_EVENT_CREATED, 'module')
|
|
340
|
+
|
|
341
|
+
return details
|
|
332
342
|
})
|
|
333
|
-
ciVisEvent(TELEMETRY_EVENT_CREATED, 'module')
|
|
334
|
-
|
|
335
|
-
return details
|
|
336
|
-
})
|
|
337
343
|
})
|
|
338
344
|
})
|
|
339
345
|
on('after:spec', (spec, { tests, stats }) => {
|
|
@@ -357,6 +363,9 @@ module.exports = (on, config) => {
|
|
|
357
363
|
if (isSkippedByItr) {
|
|
358
364
|
skippedTestSpan.setTag(TEST_SKIPPED_BY_ITR, 'true')
|
|
359
365
|
}
|
|
366
|
+
if (itrCorrelationId) {
|
|
367
|
+
skippedTestSpan.setTag(ITR_CORRELATION_ID, itrCorrelationId)
|
|
368
|
+
}
|
|
360
369
|
skippedTestSpan.finish()
|
|
361
370
|
})
|
|
362
371
|
|
|
@@ -378,6 +387,9 @@ module.exports = (on, config) => {
|
|
|
378
387
|
finishedTest.testSpan.setTag(TEST_STATUS, cypressTestStatus)
|
|
379
388
|
finishedTest.testSpan.setTag('error', latestError)
|
|
380
389
|
}
|
|
390
|
+
if (itrCorrelationId) {
|
|
391
|
+
finishedTest.testSpan.setTag(ITR_CORRELATION_ID, itrCorrelationId)
|
|
392
|
+
}
|
|
381
393
|
finishedTest.testSpan.finish(finishedTest.finishTime)
|
|
382
394
|
})
|
|
383
395
|
|
|
@@ -429,10 +441,12 @@ module.exports = (on, config) => {
|
|
|
429
441
|
}
|
|
430
442
|
if (exporter.flush) {
|
|
431
443
|
exporter.flush(() => {
|
|
444
|
+
appClosingTelemetry()
|
|
432
445
|
resolve(null)
|
|
433
446
|
})
|
|
434
447
|
} else if (exporter._writer) {
|
|
435
448
|
exporter._writer.flush(() => {
|
|
449
|
+
appClosingTelemetry()
|
|
436
450
|
resolve(null)
|
|
437
451
|
})
|
|
438
452
|
}
|
|
@@ -13,7 +13,8 @@ const {
|
|
|
13
13
|
TEST_SOURCE_START,
|
|
14
14
|
TEST_ITR_UNSKIPPABLE,
|
|
15
15
|
TEST_ITR_FORCED_RUN,
|
|
16
|
-
TEST_CODE_OWNERS
|
|
16
|
+
TEST_CODE_OWNERS,
|
|
17
|
+
ITR_CORRELATION_ID
|
|
17
18
|
} = require('../../dd-trace/src/plugins/util/test')
|
|
18
19
|
const { COMPONENT } = require('../../dd-trace/src/constants')
|
|
19
20
|
const id = require('../../dd-trace/src/id')
|
|
@@ -38,6 +39,20 @@ class JestPlugin extends CiPlugin {
|
|
|
38
39
|
return 'jest'
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
// The lists are the same for every test suite, so we can cache them
|
|
43
|
+
getUnskippableSuites (unskippableSuitesList) {
|
|
44
|
+
if (!this.unskippableSuites) {
|
|
45
|
+
this.unskippableSuites = JSON.parse(unskippableSuitesList)
|
|
46
|
+
}
|
|
47
|
+
return this.unskippableSuites
|
|
48
|
+
}
|
|
49
|
+
getForcedToRunSuites (forcedToRunSuitesList) {
|
|
50
|
+
if (!this.forcedToRunSuites) {
|
|
51
|
+
this.forcedToRunSuites = JSON.parse(forcedToRunSuitesList)
|
|
52
|
+
}
|
|
53
|
+
return this.forcedToRunSuites
|
|
54
|
+
}
|
|
55
|
+
|
|
41
56
|
constructor (...args) {
|
|
42
57
|
super(...args)
|
|
43
58
|
|
|
@@ -107,6 +122,7 @@ class JestPlugin extends CiPlugin {
|
|
|
107
122
|
config._ddTestSessionId = this.testSessionSpan.context().toTraceId()
|
|
108
123
|
config._ddTestModuleId = this.testModuleSpan.context().toSpanId()
|
|
109
124
|
config._ddTestCommand = this.testSessionSpan.context()._tags[TEST_COMMAND]
|
|
125
|
+
config._ddItrCorrelationId = this.itrCorrelationId
|
|
110
126
|
})
|
|
111
127
|
})
|
|
112
128
|
|
|
@@ -115,6 +131,7 @@ class JestPlugin extends CiPlugin {
|
|
|
115
131
|
_ddTestSessionId: testSessionId,
|
|
116
132
|
_ddTestCommand: testCommand,
|
|
117
133
|
_ddTestModuleId: testModuleId,
|
|
134
|
+
_ddItrCorrelationId: itrCorrelationId,
|
|
118
135
|
_ddForcedToRun,
|
|
119
136
|
_ddUnskippable,
|
|
120
137
|
_ddTestCodeCoverageEnabled
|
|
@@ -128,13 +145,22 @@ class JestPlugin extends CiPlugin {
|
|
|
128
145
|
const testSuiteMetadata = getTestSuiteCommonTags(testCommand, frameworkVersion, testSuite, 'jest')
|
|
129
146
|
|
|
130
147
|
if (_ddUnskippable) {
|
|
131
|
-
this.
|
|
132
|
-
|
|
148
|
+
const unskippableSuites = this.getUnskippableSuites(_ddUnskippable)
|
|
149
|
+
if (unskippableSuites[testSuite]) {
|
|
150
|
+
this.telemetry.count(TELEMETRY_ITR_UNSKIPPABLE, { testLevel: 'suite' })
|
|
151
|
+
testSuiteMetadata[TEST_ITR_UNSKIPPABLE] = 'true'
|
|
152
|
+
}
|
|
133
153
|
if (_ddForcedToRun) {
|
|
134
|
-
this.
|
|
135
|
-
|
|
154
|
+
const forcedToRunSuites = this.getForcedToRunSuites(_ddForcedToRun)
|
|
155
|
+
if (forcedToRunSuites[testSuite]) {
|
|
156
|
+
this.telemetry.count(TELEMETRY_ITR_FORCED_TO_RUN, { testLevel: 'suite' })
|
|
157
|
+
testSuiteMetadata[TEST_ITR_FORCED_RUN] = 'true'
|
|
158
|
+
}
|
|
136
159
|
}
|
|
137
160
|
}
|
|
161
|
+
if (itrCorrelationId) {
|
|
162
|
+
testSuiteMetadata[ITR_CORRELATION_ID] = itrCorrelationId
|
|
163
|
+
}
|
|
138
164
|
|
|
139
165
|
this.testSuiteSpan = this.tracer.startSpan('jest.test_suite', {
|
|
140
166
|
childOf: testSessionSpanContext,
|
|
@@ -77,30 +77,52 @@ function isMarkedAsUnskippable (test) {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
function getJestSuitesToRun (skippableSuites, originalTests, rootDir) {
|
|
80
|
-
|
|
80
|
+
const unskippableSuites = {}
|
|
81
|
+
const forcedToRunSuites = {}
|
|
82
|
+
|
|
83
|
+
const skippedSuites = []
|
|
84
|
+
const suitesToRun = []
|
|
85
|
+
|
|
86
|
+
for (const test of originalTests) {
|
|
81
87
|
const relativePath = getTestSuitePath(test.path, rootDir)
|
|
82
88
|
const shouldBeSkipped = skippableSuites.includes(relativePath)
|
|
83
|
-
|
|
84
89
|
if (isMarkedAsUnskippable(test)) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (shouldBeSkipped) {
|
|
90
|
-
test.context.config.testEnvironmentOptions['_ddForcedToRun'] = true
|
|
91
|
-
acc.hasForcedToRunSuites = true
|
|
92
|
-
}
|
|
90
|
+
suitesToRun.push(test)
|
|
91
|
+
unskippableSuites[relativePath] = true
|
|
92
|
+
if (shouldBeSkipped) {
|
|
93
|
+
forcedToRunSuites[relativePath] = true
|
|
93
94
|
}
|
|
94
|
-
|
|
95
|
+
continue
|
|
95
96
|
}
|
|
96
|
-
|
|
97
97
|
if (shouldBeSkipped) {
|
|
98
|
-
|
|
98
|
+
skippedSuites.push(relativePath)
|
|
99
99
|
} else {
|
|
100
|
-
|
|
100
|
+
suitesToRun.push(test)
|
|
101
101
|
}
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const hasUnskippableSuites = Object.keys(unskippableSuites).length > 0
|
|
105
|
+
const hasForcedToRunSuites = Object.keys(forcedToRunSuites).length > 0
|
|
106
|
+
|
|
107
|
+
if (originalTests.length) {
|
|
108
|
+
// The config object is shared by all tests, so we can just take the first one
|
|
109
|
+
const [test] = originalTests
|
|
110
|
+
if (test?.context?.config?.testEnvironmentOptions) {
|
|
111
|
+
if (hasUnskippableSuites) {
|
|
112
|
+
test.context.config.testEnvironmentOptions._ddUnskippable = JSON.stringify(unskippableSuites)
|
|
113
|
+
}
|
|
114
|
+
if (hasForcedToRunSuites) {
|
|
115
|
+
test.context.config.testEnvironmentOptions._ddForcedToRun = JSON.stringify(forcedToRunSuites)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
skippedSuites,
|
|
122
|
+
suitesToRun,
|
|
123
|
+
hasUnskippableSuites,
|
|
124
|
+
hasForcedToRunSuites
|
|
125
|
+
}
|
|
104
126
|
}
|
|
105
127
|
|
|
106
128
|
module.exports = { getFormattedJestTestParameters, getJestTestName, getJestSuitesToRun, isMarkedAsUnskippable }
|
|
@@ -14,7 +14,8 @@ const {
|
|
|
14
14
|
TEST_SOURCE_START,
|
|
15
15
|
TEST_ITR_UNSKIPPABLE,
|
|
16
16
|
TEST_ITR_FORCED_RUN,
|
|
17
|
-
TEST_CODE_OWNERS
|
|
17
|
+
TEST_CODE_OWNERS,
|
|
18
|
+
ITR_CORRELATION_ID
|
|
18
19
|
} = require('../../dd-trace/src/plugins/util/test')
|
|
19
20
|
const { COMPONENT } = require('../../dd-trace/src/constants')
|
|
20
21
|
const {
|
|
@@ -66,7 +67,12 @@ class MochaPlugin extends CiPlugin {
|
|
|
66
67
|
this.telemetry.distribution(TELEMETRY_CODE_COVERAGE_NUM_FILES, {}, relativeCoverageFiles.length)
|
|
67
68
|
})
|
|
68
69
|
|
|
69
|
-
this.addSub('ci:mocha:test-suite:start', ({
|
|
70
|
+
this.addSub('ci:mocha:test-suite:start', ({
|
|
71
|
+
testSuite,
|
|
72
|
+
isUnskippable,
|
|
73
|
+
isForcedToRun,
|
|
74
|
+
itrCorrelationId
|
|
75
|
+
}) => {
|
|
70
76
|
const store = storage.getStore()
|
|
71
77
|
const testSuiteMetadata = getTestSuiteCommonTags(
|
|
72
78
|
this.command,
|
|
@@ -95,6 +101,9 @@ class MochaPlugin extends CiPlugin {
|
|
|
95
101
|
if (this.itrConfig?.isCodeCoverageEnabled) {
|
|
96
102
|
this.telemetry.ciVisEvent(TELEMETRY_CODE_COVERAGE_STARTED, 'suite', { library: 'istanbul' })
|
|
97
103
|
}
|
|
104
|
+
if (itrCorrelationId) {
|
|
105
|
+
testSuiteSpan.setTag(ITR_CORRELATION_ID, itrCorrelationId)
|
|
106
|
+
}
|
|
98
107
|
this.enter(testSuiteSpan, store)
|
|
99
108
|
this._testSuites.set(testSuite, testSuiteSpan)
|
|
100
109
|
})
|
|
@@ -17,6 +17,7 @@ const {
|
|
|
17
17
|
TELEMETRY_EVENT_CREATED,
|
|
18
18
|
TELEMETRY_EVENT_FINISHED
|
|
19
19
|
} = require('../../dd-trace/src/ci-visibility/telemetry')
|
|
20
|
+
const { appClosing: appClosingTelemetry } = require('../../dd-trace/src/telemetry')
|
|
20
21
|
|
|
21
22
|
class PlaywrightPlugin extends CiPlugin {
|
|
22
23
|
static get id () {
|
|
@@ -37,6 +38,7 @@ class PlaywrightPlugin extends CiPlugin {
|
|
|
37
38
|
this.testSessionSpan.finish()
|
|
38
39
|
this.telemetry.ciVisEvent(TELEMETRY_EVENT_FINISHED, 'session')
|
|
39
40
|
finishAllTraceSpans(this.testSessionSpan)
|
|
41
|
+
appClosingTelemetry()
|
|
40
42
|
this.tracer._exporter.flush(onDone)
|
|
41
43
|
})
|
|
42
44
|
|
|
@@ -16,5 +16,6 @@ module.exports = {
|
|
|
16
16
|
'UNVALIDATED_REDIRECT_ANALYZER': require('./unvalidated-redirect-analyzer'),
|
|
17
17
|
'WEAK_CIPHER_ANALYZER': require('./weak-cipher-analyzer'),
|
|
18
18
|
'WEAK_HASH_ANALYZER': require('./weak-hash-analyzer'),
|
|
19
|
+
'WEAK_RANDOMNESS_ANALYZER': require('./weak-randomness-analyzer'),
|
|
19
20
|
'XCONTENTTYPE_HEADER_MISSING_ANALYZER': require('./xcontenttype-header-missing-analyzer')
|
|
20
21
|
}
|
|
@@ -48,7 +48,7 @@ class HeaderInjectionAnalyzer extends InjectionAnalyzer {
|
|
|
48
48
|
if (ranges?.length > 0) {
|
|
49
49
|
return !(this.isCookieExclusion(lowerCasedHeaderName, ranges) ||
|
|
50
50
|
this.isSameHeaderExclusion(lowerCasedHeaderName, ranges) ||
|
|
51
|
-
this.
|
|
51
|
+
this.isAccessControlAllowExclusion(lowerCasedHeaderName, ranges))
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
return false
|
|
@@ -84,8 +84,8 @@ class HeaderInjectionAnalyzer extends InjectionAnalyzer {
|
|
|
84
84
|
return false
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
if (name
|
|
87
|
+
isAccessControlAllowExclusion (name, ranges) {
|
|
88
|
+
if (name?.startsWith('access-control-allow-')) {
|
|
89
89
|
return ranges
|
|
90
90
|
.every(range => range.iinfo.type === HTTP_REQUEST_HEADER_VALUE)
|
|
91
91
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const Analyzer = require('./vulnerability-analyzer')
|
|
3
|
+
const { WEAK_RANDOMNESS } = require('../vulnerabilities')
|
|
4
|
+
|
|
5
|
+
class WeakRandomnessAnalyzer extends Analyzer {
|
|
6
|
+
constructor () {
|
|
7
|
+
super(WEAK_RANDOMNESS)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
onConfigure () {
|
|
11
|
+
this.addSub('datadog:random:call', ({ fn }) => this.analyze(fn))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
_isVulnerable (fn) {
|
|
15
|
+
return fn === Math.random
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = new WeakRandomnessAnalyzer()
|