dd-trace 3.9.3 → 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.
Files changed (43) hide show
  1. package/LICENSE-3rdparty.csv +1 -0
  2. package/README.md +108 -43
  3. package/ci/init.js +6 -1
  4. package/ext/exporters.d.ts +2 -1
  5. package/ext/exporters.js +2 -1
  6. package/index.d.ts +6 -1
  7. package/package.json +3 -2
  8. package/packages/datadog-instrumentations/src/http/server.js +4 -1
  9. package/packages/datadog-instrumentations/src/jest.js +24 -10
  10. package/packages/datadog-instrumentations/src/mocha.js +7 -4
  11. package/packages/datadog-instrumentations/src/opensearch.js +1 -1
  12. package/packages/datadog-instrumentations/src/router.js +1 -1
  13. package/packages/datadog-plugin-cucumber/src/index.js +1 -1
  14. package/packages/datadog-plugin-http/src/server.js +2 -1
  15. package/packages/datadog-plugin-jest/src/index.js +21 -25
  16. package/packages/datadog-plugin-mocha/src/index.js +11 -18
  17. package/packages/datadog-plugin-mongodb-core/src/index.js +3 -3
  18. package/packages/dd-trace/src/appsec/callbacks/ddwaf.js +4 -0
  19. package/packages/dd-trace/src/appsec/index.js +6 -1
  20. package/packages/dd-trace/src/appsec/remote_config/index.js +23 -2
  21. package/packages/dd-trace/src/appsec/remote_config/manager.js +1 -1
  22. package/packages/dd-trace/src/appsec/rule_manager.js +58 -1
  23. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +62 -0
  24. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +8 -1
  25. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +11 -59
  26. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +9 -1
  27. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +196 -0
  28. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +20 -7
  29. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-itr-configuration.js +22 -19
  30. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +22 -18
  31. package/packages/dd-trace/src/config.js +10 -8
  32. package/packages/dd-trace/src/exporter.js +3 -0
  33. package/packages/dd-trace/src/exporters/agent/index.js +4 -0
  34. package/packages/dd-trace/src/exporters/common/agent-info-exporter.js +82 -0
  35. package/packages/dd-trace/src/plugin_manager.js +0 -8
  36. package/packages/dd-trace/src/plugins/ci_plugin.js +9 -50
  37. package/packages/dd-trace/src/plugins/util/ci.js +35 -2
  38. package/packages/dd-trace/src/plugins/util/test.js +4 -0
  39. package/packages/dd-trace/src/plugins/util/web.js +1 -2
  40. package/packages/dd-trace/src/profiling/exporters/agent.js +4 -0
  41. package/packages/dd-trace/src/proxy.js +3 -17
  42. package/packages/dd-trace/src/ritm.js +18 -13
  43. package/packages/dd-trace/src/telemetry/dependencies.js +11 -1
@@ -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-js
1
+ # `dd-trace`: Node.js APM Tracer Library
2
2
 
3
- [![npm](https://img.shields.io/npm/v/dd-trace.svg?colorB=blue)](https://www.npmjs.com/package/dd-trace)
4
- [![npm (tag)](https://img.shields.io/npm/v/dd-trace/dev.svg)](https://www.npmjs.com/package/dd-trace/v/dev)
5
- [![CircleCI](https://circleci.com/gh/DataDog/dd-trace-js.svg?style=shield)](https://circleci.com/gh/DataDog/dd-trace-js)
3
+ [![npm v3](https://img.shields.io/npm/v/dd-trace/latest?color=blue&label=dd-trace%40v3&logo=npm)](https://www.npmjs.com/package/dd-trace)
4
+ [![npm v2](https://img.shields.io/npm/v/dd-trace/latest-node12?color=blue&label=dd-trace%40v2&logo=npm)](https://www.npmjs.com/package/dd-trace/v/latest-node12)
5
+ [![npm dev](https://img.shields.io/npm/v/dd-trace/dev?color=orange&label=dd-trace%40dev&logo=npm)](https://www.npmjs.com/package/dd-trace/v/dev)
6
6
  [![codecov](https://codecov.io/gh/DataDog/dd-trace-js/branch/master/graph/badge.svg)](https://codecov.io/gh/DataDog/dd-trace-js)
7
7
 
8
- **Node.js APM Tracer**
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
- Datadog APM tracing client for Node.js.
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
- ## Getting Started
12
+ ![Tracer, Agent, Datadog relationship diagram](./docs/relationship.png)
13
13
 
14
- For a basic product overview, check out our [setup documentation](https://docs.datadoghq.com/tracing/languages/nodejs/).
15
14
 
16
- For installation, configuration, and details about using the API, check out our [API documentation](https://datadog.github.io/dd-trace-js).
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) | ![npm v1](https://img.shields.io/npm/v/dd-trace/legacy-v1?color=white&label=%20&style=flat-square) | **End of Life** | 2021-07-13 | 2022-02-25 |
30
+ | [`v2`](https://github.com/DataDog/dd-trace-js/tree/v2.x) | ![npm v2](https://img.shields.io/npm/v/dd-trace/latest-node12?color=white&label=%20&style=flat-square) | **Maintenance** | 2022-01-28 | 2023-08-15 |
31
+ | [`v3`](https://github.com/DataDog/dd-trace-js/tree/v3.x) | ![npm v3](https://img.shields.io/npm/v/dd-trace/latest?color=white&label=%20&style=flat-square) | **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
- If you have found a security issue, please contact the security team directly at [security@datadoghq.com](mailto:security@datadoghq.com).
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 get started once you have Node and yarn installed, run:
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
- Before running the tests, the data stores need to be running.
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
- To run the unit tests, use:
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
- $ yarn test
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
- To run the unit tests continuously in watch mode while developing, use:
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
- $ yarn tdd
121
+ PLUGINS="express|bluebird" yarn test:plugins
63
122
  ```
64
123
 
65
- #### Memory Leaks
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
- We rely on CircleCI 2.0 for our tests. If you want to test how the CI behaves
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
- After installing the `circleci` CLI, simply run one of the following:
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
- $ circleci build --job lint
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
- When two or more approaches must be compared, please write a benchmark
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
- ```sh
110
- $ yarn bench
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) {
@@ -1,7 +1,8 @@
1
1
  declare const exporters: {
2
2
  LOG: 'log',
3
3
  AGENT: 'agent',
4
- DATADOG: 'datadog'
4
+ DATADOG: 'datadog',
5
+ AGENT_PROXY: 'agent_proxy'
5
6
  }
6
7
 
7
8
  export = exporters
package/ext/exporters.js CHANGED
@@ -2,5 +2,6 @@
2
2
  module.exports = {
3
3
  LOG: 'log',
4
4
  AGENT: 'agent',
5
- DATADOG: 'datadog'
5
+ DATADOG: 'datadog',
6
+ AGENT_PROXY: 'agent_proxy'
6
7
  }
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.9.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.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 (eventName === 'close') {
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 jestConfigurationCh = channel('ci:jest:configuration')
22
+ const jestItrConfigurationCh = channel('ci:jest:itr-configuration')
23
23
 
24
24
  let skippableSuites = []
25
25
  let isCodeCoverageEnabled = false
@@ -176,21 +176,21 @@ function cliWrapper (cli) {
176
176
  const configurationPromise = new Promise((resolve) => {
177
177
  onDone = resolve
178
178
  })
179
- if (!jestConfigurationCh.hasSubscribers) {
179
+ if (!jestItrConfigurationCh.hasSubscribers) {
180
180
  return runCLI.apply(this, arguments)
181
181
  }
182
182
 
183
183
  sessionAsyncResource.runInAsyncScope(() => {
184
- jestConfigurationCh.publish({ onDone })
184
+ jestItrConfigurationCh.publish({ onDone })
185
185
  })
186
186
 
187
187
  try {
188
- const { err, config } = await configurationPromise
188
+ const { err, itrConfig } = await configurationPromise
189
189
  if (err) {
190
190
  log.error(err)
191
191
  }
192
- isCodeCoverageEnabled = config.isCodeCoverageEnabled
193
- isSuitesSkippingEnabled = config.isSuitesSkippingEnabled
192
+ isCodeCoverageEnabled = itrConfig.isCodeCoverageEnabled
193
+ isSuitesSkippingEnabled = itrConfig.isSuitesSkippingEnabled
194
194
  } catch (e) {
195
195
  log.error(e)
196
196
  }
@@ -216,7 +216,7 @@ function cliWrapper (cli) {
216
216
  }
217
217
  }
218
218
 
219
- const isTestsSkipped = !!skippableSuites.length
219
+ const isSuitesSkipped = !!skippableSuites.length
220
220
 
221
221
  const processArgv = process.argv.slice(2).join(' ')
222
222
  sessionAsyncResource.runInAsyncScope(() => {
@@ -229,13 +229,20 @@ function cliWrapper (cli) {
229
229
 
230
230
  let testCodeCoverageLinesTotal
231
231
  try {
232
- testCodeCoverageLinesTotal = coverageMap.getCoverageSummary().lines.pct
232
+ const { pct, total } = coverageMap.getCoverageSummary().lines
233
+ testCodeCoverageLinesTotal = total !== 0 ? pct : 0
233
234
  } catch (e) {
234
235
  // ignore errors
235
236
  }
236
237
 
237
238
  sessionAsyncResource.runInAsyncScope(() => {
238
- testSessionFinishCh.publish({ status: success ? 'pass' : 'fail', isTestsSkipped, testCodeCoverageLinesTotal })
239
+ testSessionFinishCh.publish({
240
+ status: success ? 'pass' : 'fail',
241
+ isSuitesSkipped,
242
+ isSuitesSkippingEnabled,
243
+ isCodeCoverageEnabled,
244
+ testCodeCoverageLinesTotal
245
+ })
239
246
  })
240
247
 
241
248
  return result
@@ -307,6 +314,11 @@ function jestAdapterWrapper (jestAdapter) {
307
314
  const coverageFiles = getCoveredFilenamesFromCoverage(environment.global.__coverage__)
308
315
  .map(filename => getTestSuitePath(filename, environment.rootDir))
309
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
+ */
310
322
  if (coverageFiles &&
311
323
  environment.testEnvironmentOptions &&
312
324
  environment.testEnvironmentOptions._ddTestCodeCoverageEnabled) {
@@ -354,9 +366,11 @@ function configureTestEnvironment (readConfigsResult) {
354
366
  if (isSuitesSkippingEnabled) {
355
367
  // If suite skipping is enabled, the code coverage results are not going to be relevant,
356
368
  // so we do not show them.
369
+ // Also, we might skip every test, so we need to pass `passWithNoTests`
357
370
  const globalConfig = {
358
371
  ...readConfigsResult.globalConfig,
359
- coverageReporters: ['none']
372
+ coverageReporters: ['none'],
373
+ passWithNoTests: true
360
374
  }
361
375
  readConfigsResult.globalConfig = globalConfig
362
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 configurationCh = channel('ci:mocha:configuration')
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
- testSessionFinishCh.publish(status)
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,7 +320,7 @@ 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 () {
320
- if (!configurationCh.hasSubscribers) {
323
+ if (!itrConfigurationCh.hasSubscribers) {
321
324
  return run.apply(this, arguments)
322
325
  }
323
326
  const onReceivedSkippableSuites = ({ err, skippableSuites }) => {
@@ -345,7 +348,7 @@ addHook({
345
348
  }
346
349
 
347
350
  mochaRunAsyncResource.runInAsyncScope(() => {
348
- configurationCh.publish({
351
+ itrConfigurationCh.publish({
349
352
  onDone: mochaRunAsyncResource.bind(onReceivedConfiguration)
350
353
  })
351
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.1.0'] }, Transport => {
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
  })
@@ -90,7 +90,7 @@ function createWrapRouterMethod (name) {
90
90
 
91
91
  function wrapNext (req, next) {
92
92
  return function (error) {
93
- if (error) {
93
+ if (error && error !== 'route' && error !== 'router') {
94
94
  errorChannel.publish({ req, error })
95
95
  }
96
96
 
@@ -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._writer.flush()
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.enter(this._parentStore)
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._writer.flush(() => {
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', ({ status, isTestsSkipped, testCodeCoverageLinesTotal }) => {
70
- if (!this.config.isAgentlessEnabled) {
71
- return
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
- if (isTestsSkipped) {
76
- testSessionSpan.setTag(TEST_ITR_TESTS_SKIPPED, 'true')
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._writer.flush()
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
  })