dd-trace 3.9.3 → 3.11.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 +2 -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 +23 -2
- package/package.json +8 -6
- package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
- package/packages/datadog-instrumentations/src/http/server.js +11 -2
- package/packages/datadog-instrumentations/src/jest.js +24 -10
- package/packages/datadog-instrumentations/src/ldapjs.js +91 -0
- package/packages/datadog-instrumentations/src/mocha.js +7 -4
- package/packages/datadog-instrumentations/src/opensearch.js +1 -1
- package/packages/datadog-instrumentations/src/pg.js +1 -2
- 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 +9 -4
- 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/datadog-plugin-router/src/index.js +6 -3
- package/packages/dd-trace/src/appsec/addresses.js +3 -1
- package/packages/dd-trace/src/appsec/blocking.js +44 -0
- package/packages/dd-trace/src/appsec/callbacks/ddwaf.js +5 -1
- package/packages/dd-trace/src/appsec/gateway/engine/engine.js +1 -1
- package/packages/dd-trace/src/appsec/gateway/engine/index.js +6 -1
- package/packages/dd-trace/src/appsec/gateway/engine/runner.js +0 -1
- package/packages/dd-trace/src/appsec/iast/analyzers/analyzers.js +2 -1
- package/packages/dd-trace/src/appsec/iast/analyzers/ldap-injection-analyzer.js +11 -0
- package/packages/dd-trace/src/appsec/iast/analyzers/sql-injection-analyzer.js +1 -1
- package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +40 -2
- package/packages/dd-trace/src/appsec/iast/iast-context.js +3 -1
- package/packages/dd-trace/src/appsec/iast/index.js +7 -0
- package/packages/dd-trace/src/appsec/iast/path-line.js +6 -5
- package/packages/dd-trace/src/appsec/iast/taint-tracking/csi-methods.js +12 -0
- package/packages/dd-trace/src/appsec/iast/taint-tracking/operations.js +2 -29
- package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +16 -15
- package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +85 -0
- package/packages/dd-trace/src/appsec/index.js +71 -25
- package/packages/dd-trace/src/{plugins/util → appsec}/ip_blocklist.js +0 -0
- package/packages/dd-trace/src/appsec/ip_extractor.js +98 -0
- package/packages/dd-trace/src/appsec/remote_config/index.js +25 -3
- 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/appsec/templates/blocked.html +99 -0
- package/packages/dd-trace/src/appsec/templates/blocked.json +8 -0
- package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +66 -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 +19 -51
- 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 +202 -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 +34 -10
- 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 -18
- 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 +2 -106
- 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
|
@@ -20,6 +20,7 @@ require,lodash.uniq,MIT,Copyright JS Foundation and other contributors
|
|
|
20
20
|
require,lru-cache,ISC,Copyright (c) 2010-2022 Isaac Z. Schlueter and Contributors
|
|
21
21
|
require,methods,MIT,Copyright 2013-2014 TJ Holowaychuk
|
|
22
22
|
require,module-details-from-path,MIT,Copyright 2016 Thomas Watson Steen
|
|
23
|
+
require,node-abort-controller,MIT,Copyright (c) 2019 Steve Faulkner
|
|
23
24
|
require,opentracing,MIT,Copyright 2016 Resonance Labs Inc
|
|
24
25
|
require,path-to-regexp,MIT,Copyright 2014 Blake Embrey
|
|
25
26
|
require,protobufjs,BSD-3-Clause,Copyright 2016 Daniel Wirtz
|
|
@@ -38,6 +39,7 @@ dev,dotenv,BSD-2-Clause,Copyright 2015 Scott Motte
|
|
|
38
39
|
dev,eslint,MIT,Copyright JS Foundation and other contributors https://js.foundation
|
|
39
40
|
dev,eslint-config-standard,MIT,Copyright Feross Aboukhadijeh
|
|
40
41
|
dev,eslint-plugin-import,MIT,Copyright 2015 Ben Mosher
|
|
42
|
+
dev,eslint-plugin-mocha,MIT,Copyright 2014 Mathias Schreck
|
|
41
43
|
dev,eslint-plugin-node,MIT,Copyright 2015 Toru Nagashima
|
|
42
44
|
dev,eslint-plugin-promise,ISC,jden and other contributors
|
|
43
45
|
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
|
@@ -509,7 +509,17 @@ export declare interface TracerOptions {
|
|
|
509
509
|
/**
|
|
510
510
|
* Specifies a regex that will redact sensitive data by its value in attack reports.
|
|
511
511
|
*/
|
|
512
|
-
obfuscatorValueRegex?: string
|
|
512
|
+
obfuscatorValueRegex?: string,
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Specifies a path to a custom blocking template html file.
|
|
516
|
+
*/
|
|
517
|
+
blockedTemplateHtml?: string,
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Specifies a path to a custom blocking template json file.
|
|
521
|
+
*/
|
|
522
|
+
blockedTemplateJson?: string,
|
|
513
523
|
};
|
|
514
524
|
}
|
|
515
525
|
|
|
@@ -1208,6 +1218,12 @@ declare namespace plugins {
|
|
|
1208
1218
|
*/
|
|
1209
1219
|
interface kafkajs extends Instrumentation {}
|
|
1210
1220
|
|
|
1221
|
+
/**
|
|
1222
|
+
* This plugin automatically instruments the
|
|
1223
|
+
* [ldapjs](https://github.com/ldapjs/node-ldapjs/) module.
|
|
1224
|
+
*/
|
|
1225
|
+
interface ldapjs extends Instrumentation {}
|
|
1226
|
+
|
|
1211
1227
|
/**
|
|
1212
1228
|
* This plugin automatically instruments the
|
|
1213
1229
|
* [mariadb](https://github.com/mariadb-corporation/mariadb-connector-nodejs) module.
|
|
@@ -1254,7 +1270,12 @@ declare namespace plugins {
|
|
|
1254
1270
|
* This plugin automatically instruments the
|
|
1255
1271
|
* [mongodb-core](https://github.com/mongodb-js/mongodb-core) module.
|
|
1256
1272
|
*/
|
|
1257
|
-
interface mongodb_core extends Instrumentation {
|
|
1273
|
+
interface mongodb_core extends Instrumentation {
|
|
1274
|
+
/**
|
|
1275
|
+
* Whether to include the query contents in the resource name.
|
|
1276
|
+
*/
|
|
1277
|
+
queryInResourceName?: boolean;
|
|
1278
|
+
}
|
|
1258
1279
|
|
|
1259
1280
|
/**
|
|
1260
1281
|
* 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.11.0",
|
|
4
4
|
"description": "Datadog APM tracing client for JavaScript",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
"services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",
|
|
17
17
|
"tdd": "node scripts/tdd.js",
|
|
18
18
|
"test": "SERVICES=* yarn services && mocha --colors --exit --expose-gc 'packages/dd-trace/test/setup/node.js' 'packages/*/test/**/*.spec.js'",
|
|
19
|
-
"test:trace:core": "mocha --colors --exit --expose-gc --file packages/dd-trace/test/setup/core.js --exclude \"packages/dd-trace/test/profiling/**/*.spec.js\" \"packages/dd-trace/test/**/*.spec.js\"",
|
|
20
|
-
"test:trace:core:ci": "nyc --no-clean --include \"packages/dd-trace/src/**/*.js\" --exclude \"packages/dd-trace/src/profiling/**/*.js\" -- npm run test:trace:core -- --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter.json",
|
|
19
|
+
"test:trace:core": "mocha --colors --exit --expose-gc --file packages/dd-trace/test/setup/core.js --exclude \"packages/dd-trace/test/profiling/**/*.spec.js\" --exclude \"packages/dd-trace/test/appsec/iast/**/*.plugin.spec.js\" \"packages/dd-trace/test/**/*.spec.js\"",
|
|
20
|
+
"test:trace:core:ci": "nyc --no-clean --include \"packages/dd-trace/src/**/*.js\" --exclude \"packages/dd-trace/src/profiling/**/*.js\" --exclude \"packages/dd-trace/test/appsec/iast/**/*.plugin.spec.js\" -- npm run test:trace:core -- --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter.json",
|
|
21
21
|
"test:instrumentations": "mocha --colors --file 'packages/dd-trace/test/setup/core.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
|
|
22
22
|
"test:instrumentations:ci": "nyc --no-clean --include 'packages/datadog-instrumentations/src/**/*.js' -- npm run test:instrumentations",
|
|
23
23
|
"test:core": "mocha --colors --file packages/datadog-core/test/setup.js 'packages/datadog-core/test/**/*.spec.js'",
|
|
24
24
|
"test:core:ci": "nyc --no-clean --include 'packages/datadog-core/src/**/*.js' -- npm run test:core",
|
|
25
|
-
"test:plugins": "mocha --colors --exit --file \"packages/dd-trace/test/setup/core.js\" \"packages/datadog-instrumentations/test/@($(echo $PLUGINS)).spec.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/**/*.spec.js\"",
|
|
26
|
-
"test:plugins:ci": "yarn services && nyc --no-clean --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS)).js\" --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS))/**/*.js\" --include \"packages/datadog-plugin-@($(echo $PLUGINS))/src/**/*.js\" -- npm run test:plugins",
|
|
25
|
+
"test:plugins": "mocha --colors --exit --file \"packages/dd-trace/test/setup/core.js\" \"packages/datadog-instrumentations/test/@($(echo $PLUGINS)).spec.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/**/*.spec.js\" \"packages/dd-trace/test/appsec/iast/**/*.@($(echo $PLUGINS)).plugin.spec.js\"",
|
|
26
|
+
"test:plugins:ci": "yarn services && nyc --no-clean --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS)).js\" --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS))/**/*.js\" --include \"packages/datadog-plugin-@($(echo $PLUGINS))/src/**/*.js\" --include \"packages/dd-trace/test/appsec/iast/**/*.@($(echo $PLUGINS)).plugin.spec.js\" -- npm run test:plugins",
|
|
27
27
|
"test:plugins:upstream": "node ./packages/dd-trace/test/plugins/suite.js",
|
|
28
28
|
"test:profiler": "mocha --colors --exit --file \"packages/dd-trace/test/setup/core.js\" \"packages/dd-trace/test/profiling/**/*.spec.js\"",
|
|
29
29
|
"test:profiler:ci": "nyc --no-clean --include \"packages/dd-trace/src/profiling/**/*.js\" -- npm run test:profiler",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@datadog/native-appsec": "2.0.0",
|
|
62
|
-
"@datadog/native-iast-rewriter": "1.
|
|
62
|
+
"@datadog/native-iast-rewriter": "1.1.2",
|
|
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",
|
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
"lru-cache": "^7.14.0",
|
|
80
80
|
"methods": "^1.1.2",
|
|
81
81
|
"module-details-from-path": "^1.0.3",
|
|
82
|
+
"node-abort-controller": "^3.0.1",
|
|
82
83
|
"opentracing": ">=0.12.1",
|
|
83
84
|
"path-to-regexp": "^0.1.2",
|
|
84
85
|
"protobufjs": "^7.1.2",
|
|
@@ -99,6 +100,7 @@
|
|
|
99
100
|
"eslint": "^8.23.0",
|
|
100
101
|
"eslint-config-standard": "^11.0.0-beta.0",
|
|
101
102
|
"eslint-plugin-import": "^2.8.0",
|
|
103
|
+
"eslint-plugin-mocha": "^10.1.0",
|
|
102
104
|
"eslint-plugin-node": "^5.2.1",
|
|
103
105
|
"eslint-plugin-promise": "^3.6.0",
|
|
104
106
|
"eslint-plugin-standard": "^3.0.1",
|
|
@@ -46,6 +46,7 @@ module.exports = {
|
|
|
46
46
|
'koa': () => require('../koa'),
|
|
47
47
|
'koa-router': () => require('../koa'),
|
|
48
48
|
'kafkajs': () => require('../kafkajs'),
|
|
49
|
+
'ldapjs': () => require('../ldapjs'),
|
|
49
50
|
'limitd-client': () => require('../limitd-client'),
|
|
50
51
|
'mariadb': () => require('../mariadb'),
|
|
51
52
|
'memcached': () => require('../memcached'),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { AbortController } = require('node-abort-controller') // AbortController is not available in node <15
|
|
3
4
|
const {
|
|
4
5
|
channel,
|
|
5
6
|
addHook
|
|
@@ -11,6 +12,8 @@ const exitServerCh = channel('apm:http:server:request:exit')
|
|
|
11
12
|
const errorServerCh = channel('apm:http:server:request:error')
|
|
12
13
|
const finishServerCh = channel('apm:http:server:request:finish')
|
|
13
14
|
|
|
15
|
+
const requestFinishedSet = new WeakSet()
|
|
16
|
+
|
|
14
17
|
addHook({ name: 'https' }, http => {
|
|
15
18
|
// http.ServerResponse not present on https
|
|
16
19
|
shimmer.wrap(http.Server.prototype, 'emit', wrapEmit)
|
|
@@ -29,8 +32,9 @@ function wrapResponseEmit (emit) {
|
|
|
29
32
|
return emit.apply(this, arguments)
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
if (
|
|
35
|
+
if (['finish', 'close'].includes(eventName) && !requestFinishedSet.has(this)) {
|
|
33
36
|
finishServerCh.publish({ req: this.req })
|
|
37
|
+
requestFinishedSet.add(this)
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
return emit.apply(this, arguments)
|
|
@@ -45,9 +49,14 @@ function wrapEmit (emit) {
|
|
|
45
49
|
if (eventName === 'request') {
|
|
46
50
|
res.req = req
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
const abortController = new AbortController()
|
|
53
|
+
|
|
54
|
+
startServerCh.publish({ req, res, abortController })
|
|
49
55
|
|
|
50
56
|
try {
|
|
57
|
+
if (abortController.signal.aborted) {
|
|
58
|
+
return res.end()
|
|
59
|
+
}
|
|
51
60
|
return emit.apply(this, arguments)
|
|
52
61
|
} catch (err) {
|
|
53
62
|
errorServerCh.publish(err)
|
|
@@ -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,21 +176,21 @@ function cliWrapper (cli) {
|
|
|
176
176
|
const configurationPromise = new Promise((resolve) => {
|
|
177
177
|
onDone = resolve
|
|
178
178
|
})
|
|
179
|
-
if (!
|
|
179
|
+
if (!jestItrConfigurationCh.hasSubscribers) {
|
|
180
180
|
return runCLI.apply(this, arguments)
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
sessionAsyncResource.runInAsyncScope(() => {
|
|
184
|
-
|
|
184
|
+
jestItrConfigurationCh.publish({ onDone })
|
|
185
185
|
})
|
|
186
186
|
|
|
187
187
|
try {
|
|
188
|
-
const { err,
|
|
188
|
+
const { err, itrConfig } = await configurationPromise
|
|
189
189
|
if (err) {
|
|
190
190
|
log.error(err)
|
|
191
191
|
}
|
|
192
|
-
isCodeCoverageEnabled =
|
|
193
|
-
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
|
|
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
|
-
|
|
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({
|
|
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
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
channel,
|
|
5
|
+
addHook,
|
|
6
|
+
AsyncResource
|
|
7
|
+
} = require('./helpers/instrument')
|
|
8
|
+
const shimmer = require('../../datadog-shimmer')
|
|
9
|
+
|
|
10
|
+
function isString (value) {
|
|
11
|
+
return typeof value === 'string' || value instanceof String
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getCallbackArgIndex (args) {
|
|
15
|
+
let callbackIndex = -1
|
|
16
|
+
for (let i = args.length - 1; i >= 0; i--) {
|
|
17
|
+
if (typeof args[i] === 'function') {
|
|
18
|
+
callbackIndex = i
|
|
19
|
+
break
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return callbackIndex
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function wrapEmitter (corkedEmitter) {
|
|
26
|
+
const callbackMap = new WeakMap()
|
|
27
|
+
|
|
28
|
+
const addListener = on => function (name, fn) {
|
|
29
|
+
if (typeof fn === 'function') {
|
|
30
|
+
let bindedFn = callbackMap.get(fn)
|
|
31
|
+
if (!bindedFn) {
|
|
32
|
+
const callbackResource = new AsyncResource('bound-anonymous-fn')
|
|
33
|
+
bindedFn = callbackResource.bind(fn)
|
|
34
|
+
callbackMap.set(fn, bindedFn)
|
|
35
|
+
}
|
|
36
|
+
arguments[1] = bindedFn
|
|
37
|
+
}
|
|
38
|
+
on.apply(this, arguments)
|
|
39
|
+
}
|
|
40
|
+
shimmer.wrap(corkedEmitter, 'on', addListener)
|
|
41
|
+
shimmer.wrap(corkedEmitter, 'addListener', addListener)
|
|
42
|
+
|
|
43
|
+
const removeListener = off => function (name, fn) {
|
|
44
|
+
if (typeof fn === 'function') {
|
|
45
|
+
const emitterOn = callbackMap.get(fn)
|
|
46
|
+
if (emitterOn) {
|
|
47
|
+
arguments[1] = emitterOn
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
off.apply(this, arguments)
|
|
51
|
+
}
|
|
52
|
+
shimmer.wrap(corkedEmitter, 'off', removeListener)
|
|
53
|
+
shimmer.wrap(corkedEmitter, 'removeListener', removeListener)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
addHook({ name: 'ldapjs', versions: ['>=2'] }, ldapjs => {
|
|
57
|
+
const ldapSearchCh = channel('datadog:ldapjs:client:search')
|
|
58
|
+
|
|
59
|
+
shimmer.wrap(ldapjs.Client.prototype, 'search', search => function (base, options) {
|
|
60
|
+
if (ldapSearchCh.hasSubscribers) {
|
|
61
|
+
let filter
|
|
62
|
+
if (isString(options)) {
|
|
63
|
+
filter = options
|
|
64
|
+
} else if (typeof options === 'object' && options.filter) {
|
|
65
|
+
if (isString(options.filter)) {
|
|
66
|
+
filter = options.filter
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
ldapSearchCh.publish({ base, filter })
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return search.apply(this, arguments)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
shimmer.wrap(ldapjs.Client.prototype, '_send', _send => function () {
|
|
76
|
+
const callbackIndex = getCallbackArgIndex(arguments)
|
|
77
|
+
if (callbackIndex > -1) {
|
|
78
|
+
const callback = arguments[callbackIndex]
|
|
79
|
+
arguments[callbackIndex] = shimmer.wrap(callback, function (err, corkedEmitter) {
|
|
80
|
+
if (typeof corkedEmitter === 'object' && typeof corkedEmitter['on'] === 'function') {
|
|
81
|
+
wrapEmitter(corkedEmitter)
|
|
82
|
+
}
|
|
83
|
+
callback.apply(this, arguments)
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return _send.apply(this, arguments)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
return ldapjs
|
|
91
|
+
})
|
|
@@ -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,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 (!
|
|
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
|
-
|
|
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
|
|
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
|
})
|