dd-trace 5.14.0 → 5.15.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 +0 -3
- package/README.md +8 -18
- package/ci/init.js +7 -0
- package/ext/exporters.d.ts +1 -0
- package/ext/exporters.js +2 -1
- package/ext/tags.d.ts +1 -0
- package/ext/tags.js +1 -0
- package/index.d.ts +18 -3
- package/initialize.mjs +52 -0
- package/package.json +9 -12
- package/packages/datadog-esbuild/index.js +1 -31
- package/packages/datadog-instrumentations/src/amqplib.js +5 -2
- package/packages/datadog-instrumentations/src/apollo-server-core.js +0 -1
- package/packages/datadog-instrumentations/src/apollo-server.js +0 -1
- package/packages/datadog-instrumentations/src/body-parser.js +0 -1
- package/packages/datadog-instrumentations/src/check_require_cache.js +103 -0
- package/packages/datadog-instrumentations/src/cookie-parser.js +0 -1
- package/packages/datadog-instrumentations/src/express.js +0 -1
- package/packages/datadog-instrumentations/src/graphql.js +0 -2
- package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -1
- package/packages/datadog-instrumentations/src/helpers/register.js +11 -2
- package/packages/datadog-instrumentations/src/http/server.js +0 -1
- package/packages/datadog-instrumentations/src/jest.js +6 -51
- package/packages/datadog-instrumentations/src/mocha/common.js +48 -0
- package/packages/datadog-instrumentations/src/mocha/main.js +487 -0
- package/packages/datadog-instrumentations/src/mocha/utils.js +306 -0
- package/packages/datadog-instrumentations/src/mocha/worker.js +51 -0
- package/packages/datadog-instrumentations/src/mocha.js +4 -673
- package/packages/datadog-instrumentations/src/openai.js +188 -17
- package/packages/datadog-instrumentations/src/playwright.js +4 -3
- package/packages/datadog-instrumentations/src/router.js +1 -1
- package/packages/datadog-instrumentations/src/selenium.js +13 -6
- package/packages/datadog-instrumentations/src/utils/src/extract-package-and-module-path.js +33 -0
- package/packages/datadog-plugin-mocha/src/index.js +82 -8
- package/packages/datadog-plugin-next/src/index.js +1 -2
- package/packages/datadog-plugin-openai/src/index.js +219 -73
- package/packages/dd-trace/src/appsec/addresses.js +4 -2
- package/packages/dd-trace/src/appsec/blocking.js +19 -25
- package/packages/dd-trace/src/appsec/channels.js +2 -1
- package/packages/dd-trace/src/appsec/graphql.js +10 -3
- package/packages/dd-trace/src/appsec/index.js +11 -4
- package/packages/dd-trace/src/appsec/rasp.js +35 -0
- package/packages/dd-trace/src/appsec/remote_config/capabilities.js +2 -1
- package/packages/dd-trace/src/appsec/remote_config/index.js +1 -0
- package/packages/dd-trace/src/appsec/rule_manager.js +15 -25
- package/packages/dd-trace/src/appsec/sdk/user_blocking.js +2 -5
- package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +3 -1
- package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +5 -1
- package/packages/dd-trace/src/config.js +59 -16
- package/packages/dd-trace/src/encode/0.4.js +47 -8
- package/packages/dd-trace/src/exporter.js +1 -0
- package/packages/dd-trace/src/flare/file.js +44 -0
- package/packages/dd-trace/src/flare/index.js +98 -0
- package/packages/dd-trace/src/log/channels.js +54 -29
- package/packages/dd-trace/src/log/writer.js +7 -49
- package/packages/dd-trace/src/opentracing/propagation/text_map.js +57 -12
- package/packages/dd-trace/src/plugins/index.js +1 -1
- package/packages/dd-trace/src/plugins/util/ip_extractor.js +1 -1
- package/packages/dd-trace/src/plugins/util/test.js +6 -0
- package/packages/dd-trace/src/profiler.js +2 -1
- package/packages/dd-trace/src/profiling/config.js +1 -0
- package/packages/dd-trace/src/profiling/profiler.js +1 -1
- package/packages/dd-trace/src/profiling/{ssi-telemetry.js → ssi-heuristics.js} +64 -36
- package/packages/dd-trace/src/profiling/ssi-telemetry-mock-profiler.js +4 -9
- package/packages/dd-trace/src/proxy.js +49 -15
- package/packages/dd-trace/src/ritm.js +13 -1
- package/packages/dd-trace/src/startup-log.js +19 -15
- package/packages/dd-trace/src/telemetry/index.js +6 -2
- package/packages/dd-trace/src/tracer.js +3 -0
- package/packages/dd-trace/src/plugins/util/ip_blocklist.js +0 -51
package/LICENSE-3rdparty.csv
CHANGED
|
@@ -12,17 +12,14 @@ require,dc-polyfill,MIT,Copyright 2023 Datadog Inc.
|
|
|
12
12
|
require,ignore,MIT,Copyright 2013 Kael Zhang and contributors
|
|
13
13
|
require,import-in-the-middle,Apache license 2.0,Copyright 2021 Datadog Inc.
|
|
14
14
|
require,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
|
|
15
|
-
require,ipaddr.js,MIT,Copyright 2011-2017 whitequark
|
|
16
15
|
require,istanbul-lib-coverage,BSD-3-Clause,Copyright 2012-2015 Yahoo! Inc.
|
|
17
16
|
require,jest-docblock,MIT,Copyright Meta Platforms, Inc. and affiliates.
|
|
18
17
|
require,koalas,MIT,Copyright 2013-2017 Brian Woodward
|
|
19
18
|
require,limiter,MIT,Copyright 2011 John Hurliman
|
|
20
19
|
require,lodash.sortby,MIT,Copyright JS Foundation and other contributors
|
|
21
20
|
require,lru-cache,ISC,Copyright (c) 2010-2022 Isaac Z. Schlueter and Contributors
|
|
22
|
-
require,methods,MIT,Copyright 2013-2014 TJ Holowaychuk
|
|
23
21
|
require,module-details-from-path,MIT,Copyright 2016 Thomas Watson Steen
|
|
24
22
|
require,msgpack-lite,MIT,Copyright 2015 Yusuke Kawasaki
|
|
25
|
-
require,node-abort-controller,MIT,Copyright (c) 2019 Steve Faulkner
|
|
26
23
|
require,opentracing,MIT,Copyright 2016 Resonance Labs Inc
|
|
27
24
|
require,path-to-regexp,MIT,Copyright 2014 Blake Embrey
|
|
28
25
|
require,pprof-format,MIT,Copyright 2022 Stephen Belanger
|
package/README.md
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/dd-trace)
|
|
4
4
|
[](https://www.npmjs.com/package/dd-trace/v/latest-node16)
|
|
5
|
-
[](https://www.npmjs.com/package/dd-trace/v/latest-node14)
|
|
6
5
|
[](https://codecov.io/gh/DataDog/dd-trace-js)
|
|
7
6
|
|
|
8
7
|
<img align="right" src="https://user-images.githubusercontent.com/551402/208212084-1d0c07e2-4135-4c61-b2da-8f2fddbc66ed.png" alt="Bits the dog JavaScript" width="200px"/>
|
|
@@ -28,12 +27,12 @@ Most of the documentation for `dd-trace` is available on these webpages:
|
|
|
28
27
|
| :---: | :---: | :---: | :---: | :---: | :---: |
|
|
29
28
|
| [`v1`](https://github.com/DataDog/dd-trace-js/tree/v1.x) |  | `>= v12` | **End of Life** | 2021-07-13 | 2022-02-25 |
|
|
30
29
|
| [`v2`](https://github.com/DataDog/dd-trace-js/tree/v2.x) |  | `>= v12` | **End of Life** | 2022-01-28 | 2023-08-15 |
|
|
31
|
-
| [`v3`](https://github.com/DataDog/dd-trace-js/tree/v3.x) |  | `>= v14` | **
|
|
30
|
+
| [`v3`](https://github.com/DataDog/dd-trace-js/tree/v3.x) |  | `>= v14` | **End of Life** | 2022-08-15 | 2024-05-15 |
|
|
32
31
|
| [`v4`](https://github.com/DataDog/dd-trace-js/tree/v4.x) |  | `>= v16` | **Maintenance** | 2023-05-12 | 2025-01-11 |
|
|
33
32
|
| [`v5`](https://github.com/DataDog/dd-trace-js/tree/v5.x) |  | `>= v18` | **Current** | 2024-01-11 | Unknown |
|
|
34
33
|
|
|
35
|
-
We currently maintain
|
|
36
|
-
Features and bug fixes that are merged are released to the `v5` line and, if appropriate, also
|
|
34
|
+
We currently maintain two release lines, namely `v5`, and `v4`.
|
|
35
|
+
Features and bug fixes that are merged are released to the `v5` line and, if appropriate, also `v4`.
|
|
37
36
|
|
|
38
37
|
For any new projects it is recommended to use the `v5` release line:
|
|
39
38
|
|
|
@@ -42,7 +41,7 @@ $ npm install dd-trace
|
|
|
42
41
|
$ yarn add dd-trace
|
|
43
42
|
```
|
|
44
43
|
|
|
45
|
-
However, existing projects that already use the `v4`
|
|
44
|
+
However, existing projects that already use the `v4` release line, or projects that need to support EOL versions of Node.js, may continue to use these release lines.
|
|
46
45
|
This is done by specifying the version when installing the package.
|
|
47
46
|
|
|
48
47
|
```sh
|
|
@@ -67,18 +66,9 @@ Changes associated with each individual release are documented on the [GitHub Re
|
|
|
67
66
|
Please read the [CONTRIBUTING.md](https://github.com/DataDog/dd-trace-js/blob/master/CONTRIBUTING.md) document before contributing to this open source project.
|
|
68
67
|
|
|
69
68
|
|
|
70
|
-
##
|
|
69
|
+
## EcmaScript Modules (ESM) Support
|
|
71
70
|
|
|
72
|
-
|
|
73
|
-
>
|
|
74
|
-
> ESM support has been temporarily disabled starting from Node 20 as significant
|
|
75
|
-
> changes are in progress.
|
|
76
|
-
|
|
77
|
-
ESM support is currently in the experimental stages, while CJS has been supported
|
|
78
|
-
since inception. This means that code loaded using `require()` should work fine
|
|
79
|
-
but code loaded using `import` might not always work.
|
|
80
|
-
|
|
81
|
-
Use the following command to enable experimental ESM support with your application:
|
|
71
|
+
ESM support requires an additional command-line argument. Use the following to enable experimental ESM support with your application:
|
|
82
72
|
|
|
83
73
|
Node.js < v20.6
|
|
84
74
|
|
|
@@ -110,9 +100,9 @@ If you would like to trace your bundled application then please read this page o
|
|
|
110
100
|
|
|
111
101
|
Please refer to the [SECURITY.md](https://github.com/DataDog/dd-trace-js/blob/master/SECURITY.md) document if you have found a security issue.
|
|
112
102
|
|
|
103
|
+
|
|
113
104
|
## Datadog With OpenTelemetery
|
|
114
105
|
|
|
115
|
-
Please refer to the [Node.js Custom Instrumentation using OpenTelemetry API](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/nodejs/otel/) document. It includes information on how to use the OpenTelemetry API with dd-trace-js
|
|
106
|
+
Please refer to the [Node.js Custom Instrumentation using OpenTelemetry API](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/nodejs/otel/) document. It includes information on how to use the OpenTelemetry API with dd-trace-js.
|
|
116
107
|
|
|
117
108
|
Note that our internal implementation of the OpenTelemetry API is currently set within the version range `>=1.0.0 <1.9.0`. This range will be updated at a regular cadence therefore, we recommend updating your tracer to the latest release to ensure up to date support.
|
|
118
|
-
|
package/ci/init.js
CHANGED
|
@@ -4,6 +4,7 @@ const { isTrue } = require('../packages/dd-trace/src/util')
|
|
|
4
4
|
|
|
5
5
|
const isJestWorker = !!process.env.JEST_WORKER_ID
|
|
6
6
|
const isCucumberWorker = !!process.env.CUCUMBER_WORKER_ID
|
|
7
|
+
const isMochaWorker = !!process.env.MOCHA_WORKER_ID
|
|
7
8
|
|
|
8
9
|
const options = {
|
|
9
10
|
startupLogs: false,
|
|
@@ -44,6 +45,12 @@ if (isCucumberWorker) {
|
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
if (isMochaWorker) {
|
|
49
|
+
options.experimental = {
|
|
50
|
+
exporter: 'mocha_worker'
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
47
54
|
if (shouldInit) {
|
|
48
55
|
tracer.init(options)
|
|
49
56
|
tracer.use('fs', false)
|
package/ext/exporters.d.ts
CHANGED
package/ext/exporters.js
CHANGED
package/ext/tags.d.ts
CHANGED
package/ext/tags.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -113,9 +113,15 @@ interface Tracer extends opentracing.Tracer {
|
|
|
113
113
|
wrap<T = (...args: any[]) => any> (name: string, options: (...args: any[]) => tracer.TraceOptions & tracer.SpanOptions, fn: T): T;
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
|
-
*
|
|
117
|
-
* document to enable
|
|
118
|
-
*
|
|
116
|
+
* Returns an HTML string containing <meta> tags that should be included in
|
|
117
|
+
* the <head> of a document to enable correlating the current trace with the
|
|
118
|
+
* RUM view. Otherwise, it is not possible to associate the trace used to
|
|
119
|
+
* generate the initial HTML document with a given RUM view. The resulting
|
|
120
|
+
* HTML document should not be cached as the meta tags are time-sensitive
|
|
121
|
+
* and are associated with a specific user.
|
|
122
|
+
*
|
|
123
|
+
* Note that this feature is currently not supported by the backend and
|
|
124
|
+
* using it will have no effect.
|
|
119
125
|
*/
|
|
120
126
|
getRumData (): string;
|
|
121
127
|
|
|
@@ -684,6 +690,15 @@ declare namespace tracer {
|
|
|
684
690
|
* @default 0.1
|
|
685
691
|
*/
|
|
686
692
|
requestSampling?: number
|
|
693
|
+
},
|
|
694
|
+
/**
|
|
695
|
+
* Configuration for RASP
|
|
696
|
+
*/
|
|
697
|
+
rasp?: {
|
|
698
|
+
/** Whether to enable RASP.
|
|
699
|
+
* @default false
|
|
700
|
+
*/
|
|
701
|
+
enabled?: boolean
|
|
687
702
|
}
|
|
688
703
|
};
|
|
689
704
|
|
package/initialize.mjs
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file serves one of two purposes, depending on how it's used.
|
|
3
|
+
*
|
|
4
|
+
* If used with --import, it will import init.js and register the loader hook.
|
|
5
|
+
* If used with --loader, it will act as the loader hook, except that it will
|
|
6
|
+
* also import init.js inside the source code of the entrypoint file.
|
|
7
|
+
*
|
|
8
|
+
* The result is that no matter how this file is used, so long as it's with
|
|
9
|
+
* one of the two flags, the tracer will always be initialized, and the loader
|
|
10
|
+
* hook will always be active for ESM support.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { isMainThread } from 'worker_threads'
|
|
14
|
+
|
|
15
|
+
import { fileURLToPath } from 'node:url'
|
|
16
|
+
import {
|
|
17
|
+
load as origLoad,
|
|
18
|
+
resolve as origResolve,
|
|
19
|
+
getFormat as origGetFormat,
|
|
20
|
+
getSource as origGetSource
|
|
21
|
+
} from 'import-in-the-middle/hook.mjs'
|
|
22
|
+
|
|
23
|
+
let hasInsertedInit = false
|
|
24
|
+
function insertInit (result) {
|
|
25
|
+
if (!hasInsertedInit) {
|
|
26
|
+
hasInsertedInit = true
|
|
27
|
+
result.source = `
|
|
28
|
+
import '${fileURLToPath(new URL('./init.js', import.meta.url))}';
|
|
29
|
+
${result.source}`
|
|
30
|
+
}
|
|
31
|
+
return result
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function load (...args) {
|
|
35
|
+
return insertInit(await origLoad(...args))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const resolve = origResolve
|
|
39
|
+
|
|
40
|
+
export const getFormat = origGetFormat
|
|
41
|
+
|
|
42
|
+
export async function getSource (...args) {
|
|
43
|
+
return insertInit(await origGetSource(...args))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (isMainThread) {
|
|
47
|
+
await import('./init.js')
|
|
48
|
+
const { register } = await import('node:module')
|
|
49
|
+
if (register) {
|
|
50
|
+
register('./loader-hook.mjs', import.meta.url)
|
|
51
|
+
}
|
|
52
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dd-trace",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.15.0",
|
|
4
4
|
"description": "Datadog APM tracing client for JavaScript",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"test:plugins:upstream": "node ./packages/dd-trace/test/plugins/suite.js",
|
|
33
33
|
"test:profiler": "tap \"packages/dd-trace/test/profiling/**/*.spec.js\"",
|
|
34
34
|
"test:profiler:ci": "npm run test:profiler -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/profiling/**/*.js\"",
|
|
35
|
-
"test:integration": "mocha --colors --timeout 30000 \"integration-tests/*.spec.js\"",
|
|
36
|
-
"test:integration:cucumber": "mocha --colors --timeout 30000 \"integration-tests/cucumber/*.spec.js\"",
|
|
37
|
-
"test:integration:cypress": "mocha --colors --timeout 30000 \"integration-tests/cypress/*.spec.js\"",
|
|
38
|
-
"test:integration:playwright": "mocha --colors --timeout 30000 \"integration-tests/playwright/*.spec.js\"",
|
|
39
|
-
"test:integration:selenium": "mocha --colors --timeout 30000 \"integration-tests/selenium/*.spec.js\"",
|
|
40
|
-
"test:integration:profiler": "mocha --colors --timeout 90000 \"integration-tests/profiler/*.spec.js\"",
|
|
41
|
-
"test:integration:serverless": "mocha --colors --timeout 30000 \"integration-tests/serverless/*.spec.js\"",
|
|
35
|
+
"test:integration": "mocha --colors --timeout 30000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/*.spec.js\"",
|
|
36
|
+
"test:integration:cucumber": "mocha --colors --timeout 30000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/cucumber/*.spec.js\"",
|
|
37
|
+
"test:integration:cypress": "mocha --colors --timeout 30000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/cypress/*.spec.js\"",
|
|
38
|
+
"test:integration:playwright": "mocha --colors --timeout 30000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/playwright/*.spec.js\"",
|
|
39
|
+
"test:integration:selenium": "mocha --colors --timeout 30000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/selenium/*.spec.js\"",
|
|
40
|
+
"test:integration:profiler": "mocha --colors --timeout 90000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/profiler/*.spec.js\"",
|
|
41
|
+
"test:integration:serverless": "mocha --colors --timeout 30000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/serverless/*.spec.js\"",
|
|
42
42
|
"test:integration:plugins": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/integration-test/**/*.spec.js\"",
|
|
43
43
|
"test:unit:plugins": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-instrumentations/test/@($(echo $PLUGINS)).spec.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/**/*.spec.js\" --exclude \"packages/datadog-plugin-@($(echo $PLUGINS))/test/integration-test/**/*.spec.js\"",
|
|
44
44
|
"test:shimmer": "mocha --colors 'packages/datadog-shimmer/test/**/*.spec.js'",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"node": ">=18"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@datadog/native-appsec": "
|
|
73
|
+
"@datadog/native-appsec": "8.0.1",
|
|
74
74
|
"@datadog/native-iast-rewriter": "2.3.1",
|
|
75
75
|
"@datadog/native-iast-taint-tracking": "2.1.0",
|
|
76
76
|
"@datadog/native-metrics": "^2.0.0",
|
|
@@ -83,17 +83,14 @@
|
|
|
83
83
|
"ignore": "^5.2.4",
|
|
84
84
|
"import-in-the-middle": "^1.7.4",
|
|
85
85
|
"int64-buffer": "^0.1.9",
|
|
86
|
-
"ipaddr.js": "^2.1.0",
|
|
87
86
|
"istanbul-lib-coverage": "3.2.0",
|
|
88
87
|
"jest-docblock": "^29.7.0",
|
|
89
88
|
"koalas": "^1.0.2",
|
|
90
89
|
"limiter": "1.1.5",
|
|
91
90
|
"lodash.sortby": "^4.7.0",
|
|
92
91
|
"lru-cache": "^7.14.0",
|
|
93
|
-
"methods": "^1.1.2",
|
|
94
92
|
"module-details-from-path": "^1.0.3",
|
|
95
93
|
"msgpack-lite": "^0.1.26",
|
|
96
|
-
"node-abort-controller": "^3.1.1",
|
|
97
94
|
"opentracing": ">=0.12.1",
|
|
98
95
|
"path-to-regexp": "^0.1.2",
|
|
99
96
|
"pprof-format": "^2.1.0",
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
const instrumentations = require('../datadog-instrumentations/src/helpers/instrumentations.js')
|
|
6
6
|
const hooks = require('../datadog-instrumentations/src/helpers/hooks.js')
|
|
7
|
+
const extractPackageAndModulePath = require('../datadog-instrumentations/src/utils/src/extract-package-and-module-path')
|
|
7
8
|
|
|
8
9
|
for (const hook of Object.values(hooks)) {
|
|
9
10
|
hook()
|
|
@@ -21,7 +22,6 @@ for (const instrumentation of Object.values(instrumentations)) {
|
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
const NM = 'node_modules/'
|
|
25
25
|
const INSTRUMENTED = Object.keys(instrumentations)
|
|
26
26
|
const RAW_BUILTINS = require('module').builtinModules
|
|
27
27
|
const CHANNEL = 'dd-trace:bundler:load'
|
|
@@ -181,33 +181,3 @@ function dotFriendlyResolve (path, directory) {
|
|
|
181
181
|
|
|
182
182
|
return require.resolve(path, { paths: [directory] })
|
|
183
183
|
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* For a given full path to a module,
|
|
187
|
-
* return the package name it belongs to and the local path to the module
|
|
188
|
-
* input: '/foo/node_modules/@co/stuff/foo/bar/baz.js'
|
|
189
|
-
* output: { pkg: '@co/stuff', path: 'foo/bar/baz.js' }
|
|
190
|
-
*/
|
|
191
|
-
function extractPackageAndModulePath (fullPath) {
|
|
192
|
-
const nm = fullPath.lastIndexOf(NM)
|
|
193
|
-
if (nm < 0) {
|
|
194
|
-
return { pkg: null, path: null }
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const subPath = fullPath.substring(nm + NM.length)
|
|
198
|
-
const firstSlash = subPath.indexOf('/')
|
|
199
|
-
|
|
200
|
-
if (subPath[0] === '@') {
|
|
201
|
-
const secondSlash = subPath.substring(firstSlash + 1).indexOf('/')
|
|
202
|
-
|
|
203
|
-
return {
|
|
204
|
-
pkg: subPath.substring(0, firstSlash + 1 + secondSlash),
|
|
205
|
-
path: subPath.substring(firstSlash + 1 + secondSlash + 1)
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return {
|
|
210
|
-
pkg: subPath.substring(0, firstSlash),
|
|
211
|
-
path: subPath.substring(firstSlash + 1)
|
|
212
|
-
}
|
|
213
|
-
}
|
|
@@ -8,13 +8,16 @@ const {
|
|
|
8
8
|
const kebabCase = require('../../datadog-core/src/utils/src/kebabcase')
|
|
9
9
|
const shimmer = require('../../datadog-shimmer')
|
|
10
10
|
|
|
11
|
+
const { NODE_MAJOR, NODE_MINOR } = require('../../../version')
|
|
12
|
+
const MIN_VERSION = ((NODE_MAJOR > 22) || (NODE_MAJOR === 22 && NODE_MINOR >= 2)) ? '>=0.5.3' : '>=0.5.0'
|
|
13
|
+
|
|
11
14
|
const startCh = channel('apm:amqplib:command:start')
|
|
12
15
|
const finishCh = channel('apm:amqplib:command:finish')
|
|
13
16
|
const errorCh = channel('apm:amqplib:command:error')
|
|
14
17
|
|
|
15
18
|
let methods = {}
|
|
16
19
|
|
|
17
|
-
addHook({ name: 'amqplib', file: 'lib/defs.js', versions: [
|
|
20
|
+
addHook({ name: 'amqplib', file: 'lib/defs.js', versions: [MIN_VERSION] }, defs => {
|
|
18
21
|
methods = Object.keys(defs)
|
|
19
22
|
.filter(key => Number.isInteger(defs[key]))
|
|
20
23
|
.filter(key => isCamelCase(key))
|
|
@@ -22,7 +25,7 @@ addHook({ name: 'amqplib', file: 'lib/defs.js', versions: ['>=0.5'] }, defs => {
|
|
|
22
25
|
return defs
|
|
23
26
|
})
|
|
24
27
|
|
|
25
|
-
addHook({ name: 'amqplib', file: 'lib/channel.js', versions: [
|
|
28
|
+
addHook({ name: 'amqplib', file: 'lib/channel.js', versions: [MIN_VERSION] }, channel => {
|
|
26
29
|
shimmer.wrap(channel.Channel.prototype, 'sendImmediately', sendImmediately => function (method, fields) {
|
|
27
30
|
return instrument(sendImmediately, this, arguments, methods[method], fields)
|
|
28
31
|
})
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// This code runs before the tracer is configured and before a logger is ready
|
|
4
|
+
// For that reason we queue up the messages now and decide what to do with them later
|
|
5
|
+
const warnings = []
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Here we maintain a list of packages that an application
|
|
9
|
+
* may have installed which could potentially conflict with
|
|
10
|
+
*/
|
|
11
|
+
const potentialConflicts = new Set([
|
|
12
|
+
'@appsignal/javascript',
|
|
13
|
+
'@appsignal/nodejs',
|
|
14
|
+
'@dynatrace/oneagent',
|
|
15
|
+
'@instana/aws-fargate',
|
|
16
|
+
'@instana/aws-lambda',
|
|
17
|
+
'@instana/azure-container-services',
|
|
18
|
+
'@instana/collector',
|
|
19
|
+
'@instana/google-cloud-run',
|
|
20
|
+
'@sentry/node',
|
|
21
|
+
'appoptics-apm',
|
|
22
|
+
'atatus-nodejs',
|
|
23
|
+
'elastic-apm-node',
|
|
24
|
+
'newrelic',
|
|
25
|
+
'stackify-node-apm',
|
|
26
|
+
'sqreen'
|
|
27
|
+
])
|
|
28
|
+
|
|
29
|
+
const extractPackageAndModulePath = require('./utils/src/extract-package-and-module-path')
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The lowest hanging fruit to debug an app that isn't tracing
|
|
33
|
+
* properly is to check that it is loaded before any modules
|
|
34
|
+
* that need to be instrumented. This function checks the
|
|
35
|
+
* `require.cache` to see if any supported packages have
|
|
36
|
+
* already been required and prints a warning.
|
|
37
|
+
*
|
|
38
|
+
* Note that this only going to work for modules within npm
|
|
39
|
+
* packages, like `express`, and not internal modules, like
|
|
40
|
+
* `http`. It also only works with CJS, not with ESM imports.
|
|
41
|
+
*
|
|
42
|
+
* The output isn't necessarily 100% perfect. For example if the
|
|
43
|
+
* app loads a package we instrument but outside of an
|
|
44
|
+
* unsupported version then a warning would still be displayed.
|
|
45
|
+
* This is OK as the tracer should be loaded earlier anyway.
|
|
46
|
+
*/
|
|
47
|
+
module.exports.checkForRequiredModules = function () {
|
|
48
|
+
const packages = require('../../datadog-instrumentations/src/helpers/hooks')
|
|
49
|
+
const naughties = new Set()
|
|
50
|
+
let didWarn = false
|
|
51
|
+
|
|
52
|
+
for (const pathToModule of Object.keys(require.cache)) {
|
|
53
|
+
const { pkg } = extractPackageAndModulePath(pathToModule)
|
|
54
|
+
|
|
55
|
+
if (naughties.has(pkg)) continue
|
|
56
|
+
if (!(pkg in packages)) continue
|
|
57
|
+
|
|
58
|
+
warnings.push(`Warning: Package '${pkg}' was loaded before dd-trace! This may break instrumentation.`)
|
|
59
|
+
|
|
60
|
+
naughties.add(pkg)
|
|
61
|
+
didWarn = true
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (didWarn) warnings.push('Warning: Please ensure dd-trace is loaded before other modules.')
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* APM tools, and some other packages in the community, work
|
|
69
|
+
* by monkey-patching internal modules and possibly some
|
|
70
|
+
* globals. Usually this is done in a conflict-free way by
|
|
71
|
+
* wrapping an existing method with a new method that still
|
|
72
|
+
* calls the original method. Unfortunately it's possible
|
|
73
|
+
* that some of these packages (dd-trace included) may
|
|
74
|
+
* wrap methods in a way that make it unsafe for the methods
|
|
75
|
+
* to be wrapped again by another library.
|
|
76
|
+
*
|
|
77
|
+
* When encountered, and when debug mode is on, a warning is
|
|
78
|
+
* printed if such a package is discovered. This can help
|
|
79
|
+
* when debugging a faulty installation.
|
|
80
|
+
*/
|
|
81
|
+
module.exports.checkForPotentialConflicts = function () {
|
|
82
|
+
const naughties = new Set()
|
|
83
|
+
let didWarn = false
|
|
84
|
+
|
|
85
|
+
for (const pathToModule of Object.keys(require.cache)) {
|
|
86
|
+
const { pkg } = extractPackageAndModulePath(pathToModule)
|
|
87
|
+
if (naughties.has(pkg)) continue
|
|
88
|
+
if (!potentialConflicts.has(pkg)) continue
|
|
89
|
+
|
|
90
|
+
warnings.push(`Warning: Package '${pkg}' may cause conflicts with dd-trace.`)
|
|
91
|
+
|
|
92
|
+
naughties.add(pkg)
|
|
93
|
+
didWarn = true
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (didWarn) warnings.push('Warning: Packages were loaded that may conflict with dd-trace.')
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
module.exports.flushStartupLogs = function (log) {
|
|
100
|
+
while (warnings.length) {
|
|
101
|
+
log.warn(warnings.shift())
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
const { createWrapRouterMethod } = require('./router')
|
|
4
4
|
const shimmer = require('../../datadog-shimmer')
|
|
5
5
|
const { addHook, channel } = require('./helpers/instrument')
|
|
6
|
-
const { AbortController } = require('node-abort-controller')
|
|
7
6
|
|
|
8
7
|
const handleChannel = channel('apm:express:request:handle')
|
|
9
8
|
|
|
@@ -57,7 +57,6 @@ module.exports = {
|
|
|
57
57
|
'jest-config': () => require('../jest'),
|
|
58
58
|
'jest-environment-node': () => require('../jest'),
|
|
59
59
|
'jest-environment-jsdom': () => require('../jest'),
|
|
60
|
-
'jest-jasmine2': () => require('../jest'),
|
|
61
60
|
'jest-runtime': () => require('../jest'),
|
|
62
61
|
'jest-worker': () => require('../jest'),
|
|
63
62
|
knex: () => require('../knex'),
|
|
@@ -72,6 +71,7 @@ module.exports = {
|
|
|
72
71
|
'microgateway-core': () => require('../microgateway-core'),
|
|
73
72
|
mocha: () => require('../mocha'),
|
|
74
73
|
'mocha-each': () => require('../mocha'),
|
|
74
|
+
workerpool: () => require('../mocha'),
|
|
75
75
|
moleculer: () => require('../moleculer'),
|
|
76
76
|
mongodb: () => require('../mongodb'),
|
|
77
77
|
'mongodb-core': () => require('../mongodb-core'),
|
|
@@ -6,8 +6,12 @@ const semver = require('semver')
|
|
|
6
6
|
const Hook = require('./hook')
|
|
7
7
|
const requirePackageJson = require('../../../dd-trace/src/require-package-json')
|
|
8
8
|
const log = require('../../../dd-trace/src/log')
|
|
9
|
+
const checkRequireCache = require('../check_require_cache')
|
|
9
10
|
|
|
10
|
-
const {
|
|
11
|
+
const {
|
|
12
|
+
DD_TRACE_DISABLED_INSTRUMENTATIONS = '',
|
|
13
|
+
DD_TRACE_DEBUG = ''
|
|
14
|
+
} = process.env
|
|
11
15
|
|
|
12
16
|
const hooks = require('./hooks')
|
|
13
17
|
const instrumentations = require('./instrumentations')
|
|
@@ -25,8 +29,13 @@ if (!disabledInstrumentations.has('fetch')) {
|
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
const HOOK_SYMBOL = Symbol('hookExportsMap')
|
|
28
|
-
// TODO: make this more efficient
|
|
29
32
|
|
|
33
|
+
if (DD_TRACE_DEBUG && DD_TRACE_DEBUG.toLowerCase() !== 'false') {
|
|
34
|
+
checkRequireCache.checkForRequiredModules()
|
|
35
|
+
setImmediate(checkRequireCache.checkForPotentialConflicts)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// TODO: make this more efficient
|
|
30
39
|
for (const packageName of names) {
|
|
31
40
|
if (disabledInstrumentations.has(packageName)) continue
|
|
32
41
|
|