dd-trace 3.9.2 → 3.10.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 -0
- package/README.md +108 -43
- package/ci/init.js +6 -1
- package/ext/exporters.d.ts +2 -1
- package/ext/exporters.js +2 -1
- package/index.d.ts +6 -1
- package/package.json +3 -2
- package/packages/datadog-instrumentations/src/http/server.js +4 -1
- package/packages/datadog-instrumentations/src/jest.js +26 -9
- package/packages/datadog-instrumentations/src/mocha.js +12 -3
- package/packages/datadog-instrumentations/src/opensearch.js +1 -1
- package/packages/datadog-instrumentations/src/router.js +1 -1
- package/packages/datadog-plugin-cucumber/src/index.js +1 -1
- package/packages/datadog-plugin-http/src/server.js +2 -1
- package/packages/datadog-plugin-jest/src/index.js +21 -25
- package/packages/datadog-plugin-mocha/src/index.js +11 -18
- package/packages/datadog-plugin-mongodb-core/src/index.js +3 -3
- package/packages/dd-trace/src/appsec/callbacks/ddwaf.js +4 -0
- package/packages/dd-trace/src/appsec/index.js +6 -1
- package/packages/dd-trace/src/appsec/remote_config/index.js +23 -2
- package/packages/dd-trace/src/appsec/remote_config/manager.js +1 -1
- package/packages/dd-trace/src/appsec/rule_manager.js +58 -1
- package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +62 -0
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +8 -1
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +11 -59
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +9 -1
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +196 -0
- package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +20 -7
- package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-itr-configuration.js +22 -19
- package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +22 -18
- package/packages/dd-trace/src/config.js +10 -8
- package/packages/dd-trace/src/exporter.js +3 -0
- package/packages/dd-trace/src/exporters/agent/index.js +4 -0
- package/packages/dd-trace/src/exporters/common/agent-info-exporter.js +82 -0
- package/packages/dd-trace/src/plugin_manager.js +0 -8
- package/packages/dd-trace/src/plugins/ci_plugin.js +9 -50
- package/packages/dd-trace/src/plugins/util/ci.js +35 -2
- package/packages/dd-trace/src/plugins/util/test.js +4 -0
- package/packages/dd-trace/src/plugins/util/web.js +1 -2
- package/packages/dd-trace/src/profiling/exporters/agent.js +4 -0
- package/packages/dd-trace/src/proxy.js +3 -17
- package/packages/dd-trace/src/ritm.js +18 -13
- package/packages/dd-trace/src/telemetry/dependencies.js +11 -1
package/LICENSE-3rdparty.csv
CHANGED
|
@@ -38,6 +38,7 @@ dev,dotenv,BSD-2-Clause,Copyright 2015 Scott Motte
|
|
|
38
38
|
dev,eslint,MIT,Copyright JS Foundation and other contributors https://js.foundation
|
|
39
39
|
dev,eslint-config-standard,MIT,Copyright Feross Aboukhadijeh
|
|
40
40
|
dev,eslint-plugin-import,MIT,Copyright 2015 Ben Mosher
|
|
41
|
+
dev,eslint-plugin-mocha,MIT,Copyright 2014 Mathias Schreck
|
|
41
42
|
dev,eslint-plugin-node,MIT,Copyright 2015 Toru Nagashima
|
|
42
43
|
dev,eslint-plugin-promise,ISC,jden and other contributors
|
|
43
44
|
dev,eslint-plugin-standard,MIT,Copyright 2015 Jamund Ferguson
|
package/README.md
CHANGED
|
@@ -1,76 +1,139 @@
|
|
|
1
|
-
# dd-trace
|
|
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-node12)
|
|
5
|
+
[](https://www.npmjs.com/package/dd-trace/v/dev)
|
|
6
6
|
[](https://codecov.io/gh/DataDog/dd-trace-js)
|
|
7
7
|
|
|
8
|
-
|
|
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"/>
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
`dd-trace` is an npm package that you can install in your Node.js application to capture APM (Application Performance Monitoring) data. In Datadog terminology this library is called a Tracer. This data is then sent off to a process which collects and aggregates the data, called an Agent. Finally the data is sent off to the Datadog servers where it's stored and made available for querying in a myriad of ways, such as displaying in a dashboard or triggering alerts.
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+

|
|
13
13
|
|
|
14
|
-
For a basic product overview, check out our [setup documentation](https://docs.datadoghq.com/tracing/languages/nodejs/).
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
## Documentation
|
|
16
|
+
|
|
17
|
+
Most of the documentation for `dd-trace` is available on these webpages:
|
|
18
|
+
|
|
19
|
+
- [Tracing Node.js Applications](https://docs.datadoghq.com/tracing/languages/nodejs/) - most project documentation, including setup instructions
|
|
20
|
+
- [Configuring the NodeJS Tracing Library](https://docs.datadoghq.com/tracing/trace_collection/library_config/nodejs) - environment variables and config options
|
|
21
|
+
- [API Documentation](https://datadog.github.io/dd-trace-js) - method signatures, plugin list, and some usage examples
|
|
22
|
+
- [APM Terms and Concepts](https://docs.datadoghq.com/tracing/visualization/) - a glossary of concepts applicable across all languages
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## Version Release Lines and Maintenance
|
|
26
|
+
|
|
27
|
+
| Release Line | Latest Version | Status |Initial Release | End of Life |
|
|
28
|
+
| :--: | :--: | :---: | :---: | :---: |
|
|
29
|
+
| [`v1`](https://github.com/DataDog/dd-trace-js/tree/v1.x) |  | **End of Life** | 2021-07-13 | 2022-02-25 |
|
|
30
|
+
| [`v2`](https://github.com/DataDog/dd-trace-js/tree/v2.x) |  | **Maintenance** | 2022-01-28 | 2023-08-15 |
|
|
31
|
+
| [`v3`](https://github.com/DataDog/dd-trace-js/tree/v3.x) |  | **Current** | 2022-08-15 | Unknown |
|
|
32
|
+
|
|
33
|
+
We currently maintain two release lines, namely `v2` and `v3`.
|
|
34
|
+
Features and bug fixes that are merged are released to the `v3` line and, if appropriate, also the `v2` line.
|
|
35
|
+
|
|
36
|
+
For any new projects it is recommended to use the `v3` release line:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
$ npm install dd-trace
|
|
40
|
+
$ yarn add dd-trace
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
However, existing projects that already use the `v2` release line, or projects that need to support Node.js v12, may use the `v2` release line.
|
|
44
|
+
This is done by specifying the version when installing the package.
|
|
45
|
+
Note that we also publish to npm using a `latest-node12` tag that can also be used for install:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
$ npm install dd-trace@2
|
|
49
|
+
$ yarn add dd-trace@2
|
|
50
|
+
$ npm install dd-trace@latest-node12
|
|
51
|
+
$ yarn add dd-trace@latest-node12
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
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.
|
|
55
|
+
Such releases are kept to a minimum to reduce the pain of upgrading the library.
|
|
56
|
+
|
|
57
|
+
When a new release line is introduced the previous release line then enters maintenance mode where it will receive updates for the next year.
|
|
58
|
+
Once that year is up the release line enters End of Life and will not receive new updates.
|
|
59
|
+
The library also follows the Node.js LTS lifecycle wherein new release lines drop compatibility with Node.js versions that reach end of life (with the maintenance release line still receiving updates for a year).
|
|
60
|
+
|
|
61
|
+
For more information about library versioning and compatibility, see the [NodeJS Compatibility Requirements](https://docs.datadoghq.com/tracing/trace_collection/compatibility/nodejs/#releases) page.
|
|
62
|
+
|
|
63
|
+
Changes associated with each individual release are documented on the [GitHub Releases](https://github.com/DataDog/dd-trace-js/releases) screen.
|
|
17
64
|
|
|
18
|
-
For descriptions of terminology used in APM, take a look at the [official documentation](https://docs.datadoghq.com/tracing/visualization/).
|
|
19
65
|
|
|
20
66
|
## Development
|
|
21
67
|
|
|
22
68
|
Before contributing to this open source project, read our [CONTRIBUTING.md](https://github.com/DataDog/dd-trace-js/blob/master/CONTRIBUTING.md).
|
|
23
69
|
|
|
24
|
-
## Security Vulnerabilities
|
|
25
70
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
### Requirements
|
|
71
|
+
## Requirements
|
|
29
72
|
|
|
30
73
|
Since this project supports multiple Node versions, using a version
|
|
31
74
|
manager such as [nvm](https://github.com/creationix/nvm) is recommended.
|
|
32
75
|
|
|
33
76
|
We use [yarn](https://yarnpkg.com/) for its workspace functionality, so make sure to install that as well.
|
|
34
77
|
|
|
35
|
-
To
|
|
78
|
+
To install dependencies once you have Node and yarn installed, run:
|
|
36
79
|
|
|
37
80
|
```sh
|
|
38
81
|
$ yarn
|
|
39
82
|
```
|
|
40
83
|
|
|
41
|
-
### Testing
|
|
42
84
|
|
|
43
|
-
|
|
85
|
+
## Testing
|
|
86
|
+
|
|
87
|
+
Before running _plugin_ tests, the data stores need to be running.
|
|
44
88
|
The easiest way to start all of them is to use the provided
|
|
45
89
|
docker-compose configuration:
|
|
46
90
|
|
|
47
91
|
```sh
|
|
48
92
|
$ docker-compose up -d -V --remove-orphans --force-recreate
|
|
93
|
+
$ yarn services
|
|
49
94
|
```
|
|
50
95
|
|
|
51
|
-
#### Unit Tests
|
|
52
96
|
|
|
53
|
-
|
|
97
|
+
### Unit Tests
|
|
98
|
+
|
|
99
|
+
There are several types of unit tests, for various types of components. The
|
|
100
|
+
following commands may be useful:
|
|
54
101
|
|
|
55
102
|
```sh
|
|
56
|
-
|
|
103
|
+
# Tracer core tests (i.e. testing `packages/dd-trace`)
|
|
104
|
+
$ yarn test:trace:core
|
|
105
|
+
# "Core" library tests (i.e. testing `packages/datadog-core`
|
|
106
|
+
$ yarn test:core
|
|
107
|
+
# Instrumentations tests (i.e. testing `packages/datadog-instrumentations`
|
|
108
|
+
$ yarn test:instrumentations
|
|
57
109
|
```
|
|
58
110
|
|
|
59
|
-
|
|
111
|
+
Several other components have test commands as well. See `package.json` for
|
|
112
|
+
details.
|
|
113
|
+
|
|
114
|
+
To test _plugins_ (i.e. components in `packages/datadog-plugin-XXXX`
|
|
115
|
+
directories, set the `PLUGINS` environment variable to the plugin you're
|
|
116
|
+
interested in, and use `yarn test:plugins`. If you need to test multiple
|
|
117
|
+
plugins you may separate then with a pipe (`|`) delimiter. Here's an
|
|
118
|
+
example testing the `express` and `bluebird` plugins:
|
|
60
119
|
|
|
61
120
|
```sh
|
|
62
|
-
|
|
121
|
+
PLUGINS="express|bluebird" yarn test:plugins
|
|
63
122
|
```
|
|
64
123
|
|
|
65
|
-
|
|
124
|
+
|
|
125
|
+
### Memory Leaks
|
|
66
126
|
|
|
67
127
|
To run the memory leak tests, use:
|
|
68
128
|
|
|
69
129
|
```sh
|
|
70
|
-
$ yarn leak
|
|
130
|
+
$ yarn leak:core
|
|
131
|
+
|
|
132
|
+
# or
|
|
133
|
+
|
|
134
|
+
$ yarn leak:plugins
|
|
71
135
|
```
|
|
72
136
|
|
|
73
|
-
Please note that memory leak tests only run on Node `>=8`.
|
|
74
137
|
|
|
75
138
|
### Linting
|
|
76
139
|
|
|
@@ -83,29 +146,31 @@ To run the linter, use:
|
|
|
83
146
|
$ yarn lint
|
|
84
147
|
```
|
|
85
148
|
|
|
86
|
-
### Continuous Integration
|
|
87
149
|
|
|
88
|
-
|
|
89
|
-
locally, you can use the CircleCI Command Line Interface as described here:
|
|
90
|
-
https://circleci.com/docs/2.0/local-jobs/
|
|
150
|
+
### Benchmarks
|
|
91
151
|
|
|
92
|
-
|
|
152
|
+
Our microbenchmarks live in `benchmark/sirun`. Each directory in there
|
|
153
|
+
corresponds to a specific benchmark test and its variants, which are used to
|
|
154
|
+
track regressions and improvements over time.
|
|
155
|
+
|
|
156
|
+
In addition to those, when two or more approaches must be compared, please write
|
|
157
|
+
a benchmark in the `benchmark/index.js` module so that we can keep track of the
|
|
158
|
+
most efficient algorithm. To run your benchmark, use:
|
|
93
159
|
|
|
94
160
|
```sh
|
|
95
|
-
$
|
|
96
|
-
$ circleci build --job node-leaks
|
|
97
|
-
$ circleci build --job node-core-8
|
|
98
|
-
$ circleci build --job node-core-10
|
|
99
|
-
$ circleci build --job node-core-12
|
|
100
|
-
$ circleci build --job node-core-latest
|
|
161
|
+
$ yarn bench
|
|
101
162
|
```
|
|
102
163
|
|
|
103
|
-
### Benchmarks
|
|
104
164
|
|
|
105
|
-
|
|
106
|
-
in the `benchmark/index.js` module so that we can keep track of the
|
|
107
|
-
most efficient algorithm. To run your benchmark, just:
|
|
165
|
+
## Serverless / Lambda
|
|
108
166
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
167
|
+
Note that there is a separate Lambda project, [datadog-lambda-js](https://github.com/DataDog/datadog-lambda-js), that is responsible for enabling metrics and distributed tracing when your application runs on Lambda.
|
|
168
|
+
That project does depend on the `dd-trace` package but also adds a lot of Lambda-related niceties.
|
|
169
|
+
If you find any issues specific to Lambda integrations then the issues may get solved quicker if they're added to that repository.
|
|
170
|
+
That said, even if your application runs on Lambda, any core instrumentation issues not related to Lambda itself may be better served by opening an issue in this repository.
|
|
171
|
+
Regardless of where you open the issue, someone at Datadog will try to help.
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
## Security Vulnerabilities
|
|
175
|
+
|
|
176
|
+
If you have found a security issue, please contact the security team directly at [security@datadoghq.com](mailto:security@datadoghq.com).
|
package/ci/init.js
CHANGED
|
@@ -7,7 +7,8 @@ const options = {
|
|
|
7
7
|
startupLogs: false,
|
|
8
8
|
tags: {
|
|
9
9
|
[ORIGIN_KEY]: 'ciapp-test'
|
|
10
|
-
}
|
|
10
|
+
},
|
|
11
|
+
isCiVisibility: true
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
let shouldInit = true
|
|
@@ -25,6 +26,10 @@ but neither DD_API_KEY nor DATADOG_API_KEY are set in your environment, \
|
|
|
25
26
|
so dd-trace will not be initialized.`)
|
|
26
27
|
shouldInit = false
|
|
27
28
|
}
|
|
29
|
+
} else {
|
|
30
|
+
options.experimental = {
|
|
31
|
+
exporter: 'agent_proxy'
|
|
32
|
+
}
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
if (shouldInit) {
|
package/ext/exporters.d.ts
CHANGED
package/ext/exporters.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -1254,7 +1254,12 @@ declare namespace plugins {
|
|
|
1254
1254
|
* This plugin automatically instruments the
|
|
1255
1255
|
* [mongodb-core](https://github.com/mongodb-js/mongodb-core) module.
|
|
1256
1256
|
*/
|
|
1257
|
-
interface mongodb_core extends Instrumentation {
|
|
1257
|
+
interface mongodb_core extends Instrumentation {
|
|
1258
|
+
/**
|
|
1259
|
+
* Whether to include the query contents in the resource name.
|
|
1260
|
+
*/
|
|
1261
|
+
queryInResourceName?: boolean;
|
|
1262
|
+
}
|
|
1258
1263
|
|
|
1259
1264
|
/**
|
|
1260
1265
|
* This plugin automatically instruments the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dd-trace",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.0",
|
|
4
4
|
"description": "Datadog APM tracing client for JavaScript",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@datadog/native-appsec": "2.0.0",
|
|
62
|
-
"@datadog/native-iast-rewriter": "1.0.
|
|
62
|
+
"@datadog/native-iast-rewriter": "1.0.1",
|
|
63
63
|
"@datadog/native-iast-taint-tracking": "1.0.0",
|
|
64
64
|
"@datadog/native-metrics": "^1.5.0",
|
|
65
65
|
"@datadog/pprof": "^1.1.1",
|
|
@@ -99,6 +99,7 @@
|
|
|
99
99
|
"eslint": "^8.23.0",
|
|
100
100
|
"eslint-config-standard": "^11.0.0-beta.0",
|
|
101
101
|
"eslint-plugin-import": "^2.8.0",
|
|
102
|
+
"eslint-plugin-mocha": "^10.1.0",
|
|
102
103
|
"eslint-plugin-node": "^5.2.1",
|
|
103
104
|
"eslint-plugin-promise": "^3.6.0",
|
|
104
105
|
"eslint-plugin-standard": "^3.0.1",
|
|
@@ -11,6 +11,8 @@ const exitServerCh = channel('apm:http:server:request:exit')
|
|
|
11
11
|
const errorServerCh = channel('apm:http:server:request:error')
|
|
12
12
|
const finishServerCh = channel('apm:http:server:request:finish')
|
|
13
13
|
|
|
14
|
+
const requestFinishedSet = new WeakSet()
|
|
15
|
+
|
|
14
16
|
addHook({ name: 'https' }, http => {
|
|
15
17
|
// http.ServerResponse not present on https
|
|
16
18
|
shimmer.wrap(http.Server.prototype, 'emit', wrapEmit)
|
|
@@ -29,8 +31,9 @@ function wrapResponseEmit (emit) {
|
|
|
29
31
|
return emit.apply(this, arguments)
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
if (
|
|
34
|
+
if (['finish', 'close'].includes(eventName) && !requestFinishedSet.has(this)) {
|
|
33
35
|
finishServerCh.publish({ req: this.req })
|
|
36
|
+
requestFinishedSet.add(this)
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
return emit.apply(this, arguments)
|
|
@@ -19,7 +19,7 @@ const testRunFinishCh = channel('ci:jest:test:finish')
|
|
|
19
19
|
const testErrCh = channel('ci:jest:test:err')
|
|
20
20
|
|
|
21
21
|
const skippableSuitesCh = channel('ci:jest:test-suite:skippable')
|
|
22
|
-
const
|
|
22
|
+
const jestItrConfigurationCh = channel('ci:jest:itr-configuration')
|
|
23
23
|
|
|
24
24
|
let skippableSuites = []
|
|
25
25
|
let isCodeCoverageEnabled = false
|
|
@@ -176,18 +176,21 @@ function cliWrapper (cli) {
|
|
|
176
176
|
const configurationPromise = new Promise((resolve) => {
|
|
177
177
|
onDone = resolve
|
|
178
178
|
})
|
|
179
|
+
if (!jestItrConfigurationCh.hasSubscribers) {
|
|
180
|
+
return runCLI.apply(this, arguments)
|
|
181
|
+
}
|
|
179
182
|
|
|
180
183
|
sessionAsyncResource.runInAsyncScope(() => {
|
|
181
|
-
|
|
184
|
+
jestItrConfigurationCh.publish({ onDone })
|
|
182
185
|
})
|
|
183
186
|
|
|
184
187
|
try {
|
|
185
|
-
const { err,
|
|
188
|
+
const { err, itrConfig } = await configurationPromise
|
|
186
189
|
if (err) {
|
|
187
190
|
log.error(err)
|
|
188
191
|
}
|
|
189
|
-
isCodeCoverageEnabled =
|
|
190
|
-
isSuitesSkippingEnabled =
|
|
192
|
+
isCodeCoverageEnabled = itrConfig.isCodeCoverageEnabled
|
|
193
|
+
isSuitesSkippingEnabled = itrConfig.isSuitesSkippingEnabled
|
|
191
194
|
} catch (e) {
|
|
192
195
|
log.error(e)
|
|
193
196
|
}
|
|
@@ -213,7 +216,7 @@ function cliWrapper (cli) {
|
|
|
213
216
|
}
|
|
214
217
|
}
|
|
215
218
|
|
|
216
|
-
const
|
|
219
|
+
const isSuitesSkipped = !!skippableSuites.length
|
|
217
220
|
|
|
218
221
|
const processArgv = process.argv.slice(2).join(' ')
|
|
219
222
|
sessionAsyncResource.runInAsyncScope(() => {
|
|
@@ -226,13 +229,20 @@ function cliWrapper (cli) {
|
|
|
226
229
|
|
|
227
230
|
let testCodeCoverageLinesTotal
|
|
228
231
|
try {
|
|
229
|
-
|
|
232
|
+
const { pct, total } = coverageMap.getCoverageSummary().lines
|
|
233
|
+
testCodeCoverageLinesTotal = total !== 0 ? pct : 0
|
|
230
234
|
} catch (e) {
|
|
231
235
|
// ignore errors
|
|
232
236
|
}
|
|
233
237
|
|
|
234
238
|
sessionAsyncResource.runInAsyncScope(() => {
|
|
235
|
-
testSessionFinishCh.publish({
|
|
239
|
+
testSessionFinishCh.publish({
|
|
240
|
+
status: success ? 'pass' : 'fail',
|
|
241
|
+
isSuitesSkipped,
|
|
242
|
+
isSuitesSkippingEnabled,
|
|
243
|
+
isCodeCoverageEnabled,
|
|
244
|
+
testCodeCoverageLinesTotal
|
|
245
|
+
})
|
|
236
246
|
})
|
|
237
247
|
|
|
238
248
|
return result
|
|
@@ -304,6 +314,11 @@ function jestAdapterWrapper (jestAdapter) {
|
|
|
304
314
|
const coverageFiles = getCoveredFilenamesFromCoverage(environment.global.__coverage__)
|
|
305
315
|
.map(filename => getTestSuitePath(filename, environment.rootDir))
|
|
306
316
|
|
|
317
|
+
/**
|
|
318
|
+
* Child processes do not each request ITR configuration, so the jest's parent process
|
|
319
|
+
* needs to pass them the configuration. This is done via _ddTestCodeCoverageEnabled, which
|
|
320
|
+
* controls whether coverage is reported.
|
|
321
|
+
*/
|
|
307
322
|
if (coverageFiles &&
|
|
308
323
|
environment.testEnvironmentOptions &&
|
|
309
324
|
environment.testEnvironmentOptions._ddTestCodeCoverageEnabled) {
|
|
@@ -351,9 +366,11 @@ function configureTestEnvironment (readConfigsResult) {
|
|
|
351
366
|
if (isSuitesSkippingEnabled) {
|
|
352
367
|
// If suite skipping is enabled, the code coverage results are not going to be relevant,
|
|
353
368
|
// so we do not show them.
|
|
369
|
+
// Also, we might skip every test, so we need to pass `passWithNoTests`
|
|
354
370
|
const globalConfig = {
|
|
355
371
|
...readConfigsResult.globalConfig,
|
|
356
|
-
coverageReporters: ['none']
|
|
372
|
+
coverageReporters: ['none'],
|
|
373
|
+
passWithNoTests: true
|
|
357
374
|
}
|
|
358
375
|
readConfigsResult.globalConfig = globalConfig
|
|
359
376
|
}
|
|
@@ -17,7 +17,7 @@ const skipCh = channel('ci:mocha:test:skip')
|
|
|
17
17
|
const testFinishCh = channel('ci:mocha:test:finish')
|
|
18
18
|
const parameterizedTestCh = channel('ci:mocha:test:parameterize')
|
|
19
19
|
|
|
20
|
-
const
|
|
20
|
+
const itrConfigurationCh = channel('ci:mocha:itr-configuration')
|
|
21
21
|
const skippableSuitesCh = channel('ci:mocha:test-suite:skippable')
|
|
22
22
|
|
|
23
23
|
const testSessionStartCh = channel('ci:mocha:session:start')
|
|
@@ -111,7 +111,10 @@ function mochaHook (Runner) {
|
|
|
111
111
|
status = 'fail'
|
|
112
112
|
}
|
|
113
113
|
testFileToSuiteAr.clear()
|
|
114
|
-
|
|
114
|
+
|
|
115
|
+
const isSuitesSkipped = !!suitesToSkip.length
|
|
116
|
+
|
|
117
|
+
testSessionFinishCh.publish({ status, isSuitesSkipped })
|
|
115
118
|
// restore the original coverage
|
|
116
119
|
global.__coverage__ = fromCoverageMapToCoverage(originalCoverageMap)
|
|
117
120
|
}))
|
|
@@ -317,6 +320,9 @@ addHook({
|
|
|
317
320
|
* If ITR is disabled, `onDone` is called immediately on the subscriber
|
|
318
321
|
*/
|
|
319
322
|
shimmer.wrap(Mocha.prototype, 'run', run => function () {
|
|
323
|
+
if (!itrConfigurationCh.hasSubscribers) {
|
|
324
|
+
return run.apply(this, arguments)
|
|
325
|
+
}
|
|
320
326
|
const onReceivedSkippableSuites = ({ err, skippableSuites }) => {
|
|
321
327
|
if (err) {
|
|
322
328
|
log.error(err)
|
|
@@ -332,6 +338,9 @@ addHook({
|
|
|
332
338
|
log.error(err)
|
|
333
339
|
return run.apply(this, arguments)
|
|
334
340
|
}
|
|
341
|
+
if (!skippableSuitesCh.hasSubscribers) {
|
|
342
|
+
return run.apply(this, arguments)
|
|
343
|
+
}
|
|
335
344
|
|
|
336
345
|
skippableSuitesCh.publish({
|
|
337
346
|
onDone: mochaRunAsyncResource.bind(onReceivedSkippableSuites)
|
|
@@ -339,7 +348,7 @@ addHook({
|
|
|
339
348
|
}
|
|
340
349
|
|
|
341
350
|
mochaRunAsyncResource.runInAsyncScope(() => {
|
|
342
|
-
|
|
351
|
+
itrConfigurationCh.publish({
|
|
343
352
|
onDone: mochaRunAsyncResource.bind(onReceivedConfiguration)
|
|
344
353
|
})
|
|
345
354
|
})
|
|
@@ -4,7 +4,7 @@ const { addHook } = require('./helpers/instrument')
|
|
|
4
4
|
const shimmer = require('../../datadog-shimmer')
|
|
5
5
|
const { createWrapRequest } = require('./elasticsearch')
|
|
6
6
|
|
|
7
|
-
addHook({ name: '@opensearch-project/opensearch', file: 'lib/Transport.js', versions: ['1
|
|
7
|
+
addHook({ name: '@opensearch-project/opensearch', file: 'lib/Transport.js', versions: ['>=1'] }, Transport => {
|
|
8
8
|
shimmer.wrap(Transport.prototype, 'request', createWrapRequest('opensearch'))
|
|
9
9
|
return Transport
|
|
10
10
|
})
|
|
@@ -21,7 +21,7 @@ class CucumberPlugin extends CiPlugin {
|
|
|
21
21
|
super(...args)
|
|
22
22
|
|
|
23
23
|
this.addSub('ci:cucumber:session:finish', () => {
|
|
24
|
-
this.tracer._exporter.
|
|
24
|
+
this.tracer._exporter.flush()
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
this.addSub('ci:cucumber:run:start', ({ testName, fullTestSuite }) => {
|
|
@@ -42,7 +42,8 @@ class HttpServerPlugin extends Plugin {
|
|
|
42
42
|
})
|
|
43
43
|
|
|
44
44
|
this.addSub('apm:http:server:request:exit', ({ req }) => {
|
|
45
|
-
this.
|
|
45
|
+
const span = this._parentStore && this._parentStore.span
|
|
46
|
+
this.enter(span, this._parentStore)
|
|
46
47
|
this._parentStore = undefined
|
|
47
48
|
})
|
|
48
49
|
|
|
@@ -15,6 +15,8 @@ const {
|
|
|
15
15
|
TEST_SUITE_ID,
|
|
16
16
|
TEST_COMMAND,
|
|
17
17
|
TEST_ITR_TESTS_SKIPPED,
|
|
18
|
+
TEST_SESSION_ITR_CODE_COVERAGE_ENABLED,
|
|
19
|
+
TEST_SESSION_ITR_SKIPPING_ENABLED,
|
|
18
20
|
TEST_CODE_COVERAGE_LINES_TOTAL
|
|
19
21
|
} = require('../../dd-trace/src/plugins/util/test')
|
|
20
22
|
const { COMPONENT } = require('../../dd-trace/src/constants')
|
|
@@ -33,7 +35,7 @@ class JestPlugin extends CiPlugin {
|
|
|
33
35
|
// Used to handle the end of a jest worker to be able to flush
|
|
34
36
|
const handler = ([message]) => {
|
|
35
37
|
if (message === CHILD_MESSAGE_END) {
|
|
36
|
-
this.tracer._exporter.
|
|
38
|
+
this.tracer._exporter.flush(() => {
|
|
37
39
|
// eslint-disable-next-line
|
|
38
40
|
// https://github.com/facebook/jest/blob/24ed3b5ecb419c023ee6fdbc838f07cc028fc007/packages/jest-worker/src/workers/processChild.ts#L118-L133
|
|
39
41
|
// Only after the flush is done we clean up open handles
|
|
@@ -48,9 +50,6 @@ class JestPlugin extends CiPlugin {
|
|
|
48
50
|
this.codeOwnersEntries = getCodeOwnersFileEntries()
|
|
49
51
|
|
|
50
52
|
this.addSub('ci:jest:session:start', (command) => {
|
|
51
|
-
if (!this.config.isAgentlessEnabled) {
|
|
52
|
-
return
|
|
53
|
-
}
|
|
54
53
|
const store = storage.getStore()
|
|
55
54
|
const childOf = getTestParentSpan(this.tracer)
|
|
56
55
|
const testSessionSpanMetadata = getTestSessionCommonTags(command, this.tracer._version)
|
|
@@ -66,30 +65,32 @@ class JestPlugin extends CiPlugin {
|
|
|
66
65
|
this.enter(testSessionSpan, store)
|
|
67
66
|
})
|
|
68
67
|
|
|
69
|
-
this.addSub('ci:jest:session:finish', ({
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
this.addSub('ci:jest:session:finish', ({
|
|
69
|
+
status,
|
|
70
|
+
isSuitesSkipped,
|
|
71
|
+
isSuitesSkippingEnabled,
|
|
72
|
+
isCodeCoverageEnabled,
|
|
73
|
+
testCodeCoverageLinesTotal
|
|
74
|
+
}) => {
|
|
73
75
|
const testSessionSpan = storage.getStore().span
|
|
76
|
+
|
|
74
77
|
testSessionSpan.setTag(TEST_STATUS, status)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
testSessionSpan.setTag(TEST_ITR_TESTS_SKIPPED, isSuitesSkipped ? 'true' : 'false')
|
|
79
|
+
testSessionSpan.setTag(TEST_SESSION_ITR_SKIPPING_ENABLED, isSuitesSkippingEnabled ? 'true' : 'false')
|
|
80
|
+
testSessionSpan.setTag(TEST_SESSION_ITR_CODE_COVERAGE_ENABLED, isCodeCoverageEnabled ? 'true' : 'false')
|
|
81
|
+
|
|
78
82
|
if (testCodeCoverageLinesTotal !== undefined) {
|
|
79
83
|
testSessionSpan.setTag(TEST_CODE_COVERAGE_LINES_TOTAL, testCodeCoverageLinesTotal)
|
|
80
84
|
}
|
|
81
85
|
testSessionSpan.finish()
|
|
82
86
|
finishAllTraceSpans(testSessionSpan)
|
|
83
|
-
this.tracer._exporter.
|
|
87
|
+
this.tracer._exporter.flush()
|
|
84
88
|
})
|
|
85
89
|
|
|
86
90
|
// Test suites can be run in a different process from jest's main one.
|
|
87
91
|
// This subscriber changes the configuration objects from jest to inject the trace id
|
|
88
92
|
// of the test session to the processes that run the test suites.
|
|
89
93
|
this.addSub('ci:jest:session:configuration', configs => {
|
|
90
|
-
if (!this.config.isAgentlessEnabled) {
|
|
91
|
-
return
|
|
92
|
-
}
|
|
93
94
|
const testSessionSpan = storage.getStore().span
|
|
94
95
|
configs.forEach(config => {
|
|
95
96
|
config._ddTestSessionId = testSessionSpan.context()._traceId.toString(10)
|
|
@@ -98,10 +99,6 @@ class JestPlugin extends CiPlugin {
|
|
|
98
99
|
})
|
|
99
100
|
|
|
100
101
|
this.addSub('ci:jest:test-suite:start', ({ testSuite, testEnvironmentOptions }) => {
|
|
101
|
-
if (!this.config.isAgentlessEnabled) {
|
|
102
|
-
return
|
|
103
|
-
}
|
|
104
|
-
|
|
105
102
|
const { _ddTestSessionId: testSessionId, _ddTestCommand: testCommand } = testEnvironmentOptions
|
|
106
103
|
|
|
107
104
|
const store = storage.getStore()
|
|
@@ -125,9 +122,6 @@ class JestPlugin extends CiPlugin {
|
|
|
125
122
|
})
|
|
126
123
|
|
|
127
124
|
this.addSub('ci:jest:test-suite:finish', ({ status, errorMessage }) => {
|
|
128
|
-
if (!this.config.isAgentlessEnabled) {
|
|
129
|
-
return
|
|
130
|
-
}
|
|
131
125
|
const testSuiteSpan = storage.getStore().span
|
|
132
126
|
testSuiteSpan.setTag(TEST_STATUS, status)
|
|
133
127
|
if (errorMessage) {
|
|
@@ -139,10 +133,12 @@ class JestPlugin extends CiPlugin {
|
|
|
139
133
|
finishAllTraceSpans(testSuiteSpan)
|
|
140
134
|
})
|
|
141
135
|
|
|
136
|
+
/**
|
|
137
|
+
* This can't use `this.itrConfig` like `ci:mocha:test-suite:code-coverage`
|
|
138
|
+
* because this subscription happens in a different process from the one
|
|
139
|
+
* fetching the ITR config.
|
|
140
|
+
*/
|
|
142
141
|
this.addSub('ci:jest:test-suite:code-coverage', (coverageFiles) => {
|
|
143
|
-
if (!this.config.isAgentlessEnabled || !this.config.isIntelligentTestRunnerEnabled) {
|
|
144
|
-
return
|
|
145
|
-
}
|
|
146
142
|
const testSuiteSpan = storage.getStore().span
|
|
147
143
|
this.tracer._exporter.exportCoverage({ span: testSuiteSpan, coverageFiles })
|
|
148
144
|
})
|