dd-trace 6.0.0-pre-3f6ad7e → 6.0.0-pre-bed4b20

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 (117) hide show
  1. package/LICENSE-3rdparty.csv +1 -4
  2. package/README.md +8 -18
  3. package/ci/init.js +7 -0
  4. package/ext/exporters.d.ts +2 -1
  5. package/ext/exporters.js +2 -1
  6. package/ext/tags.d.ts +1 -0
  7. package/ext/tags.js +1 -0
  8. package/index.d.ts +72 -4
  9. package/init.js +40 -1
  10. package/initialize.mjs +55 -0
  11. package/package.json +25 -27
  12. package/packages/datadog-core/src/storage/index.js +1 -10
  13. package/packages/datadog-esbuild/index.js +5 -1
  14. package/packages/datadog-instrumentations/src/amqplib.js +5 -2
  15. package/packages/datadog-instrumentations/src/apollo-server-core.js +0 -1
  16. package/packages/datadog-instrumentations/src/apollo-server.js +0 -1
  17. package/packages/datadog-instrumentations/src/aws-sdk.js +2 -1
  18. package/packages/datadog-instrumentations/src/body-parser.js +0 -1
  19. package/packages/datadog-instrumentations/src/check_require_cache.js +67 -5
  20. package/packages/datadog-instrumentations/src/cookie-parser.js +0 -1
  21. package/packages/datadog-instrumentations/src/cucumber.js +76 -34
  22. package/packages/datadog-instrumentations/src/express.js +0 -1
  23. package/packages/datadog-instrumentations/src/graphql.js +0 -2
  24. package/packages/datadog-instrumentations/src/helpers/hook.js +8 -3
  25. package/packages/datadog-instrumentations/src/helpers/hooks.js +4 -0
  26. package/packages/datadog-instrumentations/src/helpers/instrument.js +4 -3
  27. package/packages/datadog-instrumentations/src/helpers/register.js +61 -7
  28. package/packages/datadog-instrumentations/src/http/server.js +98 -1
  29. package/packages/datadog-instrumentations/src/jest.js +5 -2
  30. package/packages/datadog-instrumentations/src/mocha/common.js +48 -0
  31. package/packages/datadog-instrumentations/src/mocha/main.js +498 -0
  32. package/packages/datadog-instrumentations/src/mocha/utils.js +350 -0
  33. package/packages/datadog-instrumentations/src/mocha/worker.js +52 -0
  34. package/packages/datadog-instrumentations/src/mocha.js +4 -673
  35. package/packages/datadog-instrumentations/src/openai.js +188 -17
  36. package/packages/datadog-instrumentations/src/playwright.js +48 -33
  37. package/packages/datadog-instrumentations/src/router.js +1 -1
  38. package/packages/datadog-instrumentations/src/selenium.js +13 -6
  39. package/packages/datadog-instrumentations/src/undici.js +18 -0
  40. package/packages/datadog-instrumentations/src/vitest.js +303 -0
  41. package/packages/datadog-plugin-aws-sdk/src/base.js +8 -1
  42. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +9 -3
  43. package/packages/datadog-plugin-aws-sdk/src/services/sns.js +6 -1
  44. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +23 -5
  45. package/packages/datadog-plugin-child_process/src/index.js +1 -1
  46. package/packages/datadog-plugin-cucumber/src/index.js +24 -1
  47. package/packages/datadog-plugin-graphql/src/resolve.js +4 -0
  48. package/packages/datadog-plugin-mocha/src/index.js +107 -12
  49. package/packages/datadog-plugin-next/src/index.js +1 -2
  50. package/packages/datadog-plugin-openai/src/index.js +243 -75
  51. package/packages/datadog-plugin-openai/src/token-estimator.js +20 -0
  52. package/packages/datadog-plugin-playwright/src/index.js +4 -1
  53. package/packages/datadog-plugin-undici/src/index.js +12 -0
  54. package/packages/datadog-plugin-vitest/src/index.js +156 -0
  55. package/packages/dd-trace/src/appsec/addresses.js +4 -2
  56. package/packages/dd-trace/src/appsec/blocking.js +23 -25
  57. package/packages/dd-trace/src/appsec/channels.js +3 -1
  58. package/packages/dd-trace/src/appsec/graphql.js +10 -3
  59. package/packages/dd-trace/src/appsec/iast/path-line.js +2 -19
  60. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +4 -0
  61. package/packages/dd-trace/src/appsec/index.js +55 -14
  62. package/packages/dd-trace/src/appsec/rasp.js +62 -0
  63. package/packages/dd-trace/src/appsec/recommended.json +208 -3
  64. package/packages/dd-trace/src/appsec/remote_config/capabilities.js +3 -1
  65. package/packages/dd-trace/src/appsec/remote_config/index.js +3 -0
  66. package/packages/dd-trace/src/appsec/reporter.js +64 -20
  67. package/packages/dd-trace/src/appsec/rule_manager.js +15 -25
  68. package/packages/dd-trace/src/appsec/sdk/track_event.js +3 -0
  69. package/packages/dd-trace/src/appsec/sdk/user_blocking.js +2 -5
  70. package/packages/dd-trace/src/appsec/stack_trace.js +90 -0
  71. package/packages/dd-trace/src/appsec/standalone.js +130 -0
  72. package/packages/dd-trace/src/appsec/telemetry.js +33 -1
  73. package/packages/dd-trace/src/appsec/waf/index.js +2 -2
  74. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +5 -3
  75. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +4 -2
  76. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +5 -1
  77. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +4 -2
  78. package/packages/dd-trace/src/config.js +207 -62
  79. package/packages/dd-trace/src/constants.js +5 -1
  80. package/packages/dd-trace/src/datastreams/processor.js +2 -1
  81. package/packages/dd-trace/src/encode/0.4.js +47 -8
  82. package/packages/dd-trace/src/exporter.js +1 -0
  83. package/packages/dd-trace/src/exporters/agent/index.js +2 -2
  84. package/packages/dd-trace/src/flare/file.js +44 -0
  85. package/packages/dd-trace/src/flare/index.js +98 -0
  86. package/packages/dd-trace/src/format.js +22 -2
  87. package/packages/dd-trace/src/log/channels.js +54 -29
  88. package/packages/dd-trace/src/log/writer.js +7 -49
  89. package/packages/dd-trace/src/opentelemetry/span.js +41 -7
  90. package/packages/dd-trace/src/opentracing/propagation/text_map.js +69 -12
  91. package/packages/dd-trace/src/opentracing/span.js +42 -1
  92. package/packages/dd-trace/src/opentracing/tracer.js +2 -2
  93. package/packages/dd-trace/src/plugins/ci_plugin.js +7 -0
  94. package/packages/dd-trace/src/plugins/index.js +4 -0
  95. package/packages/dd-trace/src/plugins/util/ip_extractor.js +1 -1
  96. package/packages/dd-trace/src/plugins/util/test.js +11 -1
  97. package/packages/dd-trace/src/priority_sampler.js +10 -9
  98. package/packages/dd-trace/src/profiler.js +2 -1
  99. package/packages/dd-trace/src/profiling/config.js +1 -0
  100. package/packages/dd-trace/src/profiling/profiler.js +2 -2
  101. package/packages/dd-trace/src/profiling/{ssi-telemetry.js → ssi-heuristics.js} +64 -36
  102. package/packages/dd-trace/src/profiling/ssi-telemetry-mock-profiler.js +4 -9
  103. package/packages/dd-trace/src/proxy.js +52 -16
  104. package/packages/dd-trace/src/rate_limiter.js +2 -2
  105. package/packages/dd-trace/src/ritm.js +13 -1
  106. package/packages/dd-trace/src/sampling_rule.js +2 -1
  107. package/packages/dd-trace/src/service-naming/schemas/v0/web.js +4 -0
  108. package/packages/dd-trace/src/service-naming/schemas/v1/web.js +4 -0
  109. package/packages/dd-trace/src/span_stats.js +4 -3
  110. package/packages/dd-trace/src/startup-log.js +19 -15
  111. package/packages/dd-trace/src/tagger.js +10 -1
  112. package/packages/dd-trace/src/telemetry/index.js +6 -2
  113. package/packages/dd-trace/src/telemetry/init-telemetry.js +75 -0
  114. package/packages/dd-trace/src/tracer.js +5 -2
  115. package/packages/dd-trace/src/util.js +6 -1
  116. package/packages/datadog-core/src/storage/async_hooks.js +0 -49
  117. package/packages/dd-trace/src/plugins/util/ip_blocklist.js +0 -51
@@ -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
@@ -66,7 +63,7 @@ dev,rimraf,ISC,Copyright Isaac Z. Schlueter and Contributors
66
63
  dev,sinon,BSD-3-Clause,Copyright 2010-2017 Christian Johansen
67
64
  dev,sinon-chai,WTFPL and BSD-2-Clause,Copyright 2004 Sam Hocevar 2012–2017 Domenic Denicola
68
65
  dev,tap,ISC,Copyright 2011-2022 Isaac Z. Schlueter and Contributors
69
- dev,tape,MIT,Copyright James Halliday
66
+ dev,tiktoken,MIT,Copyright (c) 2022 OpenAI, Shantanu Jain
70
67
  file,aws-lambda-nodejs-runtime-interface-client,Apache 2.0,Copyright 2019 Amazon.com Inc. or its affiliates. All Rights Reserved.
71
68
  file,profile.proto,Apache license 2.0,Copyright 2016 Google Inc.
72
69
  file,is-git-url,MIT,Copyright (c) 2017 Jon Schlinkert.
package/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![npm v5](https://img.shields.io/npm/v/dd-trace/latest?color=blue&label=dd-trace%40v5&logo=npm)](https://www.npmjs.com/package/dd-trace)
4
4
  [![npm v4](https://img.shields.io/npm/v/dd-trace/latest-node16?color=blue&label=dd-trace%40v4&logo=npm)](https://www.npmjs.com/package/dd-trace/v/latest-node16)
5
- [![npm v3](https://img.shields.io/npm/v/dd-trace/latest-node14?color=blue&label=dd-trace%40v3&logo=npm)](https://www.npmjs.com/package/dd-trace/v/latest-node14)
6
5
  [![codecov](https://codecov.io/gh/DataDog/dd-trace-js/branch/master/graph/badge.svg)](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) | ![npm v1](https://img.shields.io/npm/v/dd-trace/legacy-v1?color=white&label=%20&style=flat-square) | `>= v12` | **End of Life** | 2021-07-13 | 2022-02-25 |
30
29
  | [`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) | `>= v12` | **End of Life** | 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-node14?color=white&label=%20&style=flat-square) | `>= v14` | **Maintenance** | 2022-08-15 | 2024-05-15 |
30
+ | [`v3`](https://github.com/DataDog/dd-trace-js/tree/v3.x) | ![npm v3](https://img.shields.io/npm/v/dd-trace/latest-node14?color=white&label=%20&style=flat-square) | `>= v14` | **End of Life** | 2022-08-15 | 2024-05-15 |
32
31
  | [`v4`](https://github.com/DataDog/dd-trace-js/tree/v4.x) | ![npm v4](https://img.shields.io/npm/v/dd-trace/latest-node16?color=white&label=%20&style=flat-square) | `>= v16` | **Maintenance** | 2023-05-12 | 2025-01-11 |
33
32
  | [`v5`](https://github.com/DataDog/dd-trace-js/tree/v5.x) | ![npm v5](https://img.shields.io/npm/v/dd-trace/latest?color=white&label=%20&style=flat-square) | `>= v18` | **Current** | 2024-01-11 | Unknown |
34
33
 
35
- We currently maintain three release lines, namely `v5`, `v4` and `v3`.
36
- Features and bug fixes that are merged are released to the `v5` line and, if appropriate, also the `v4` & `v3` line.
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` & `v3` release line, or projects that need to support EOL versions of Node.js, may continue to use these release lines.
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
- ## Experimental ESM Support
69
+ ## EcmaScript Modules (ESM) Support
71
70
 
72
- > **Warning**
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)
@@ -4,7 +4,8 @@ declare const exporters: {
4
4
  DATADOG: 'datadog',
5
5
  AGENT_PROXY: 'agent_proxy',
6
6
  JEST_WORKER: 'jest_worker',
7
- CUCUMBER_WORKER: 'cucumber_worker'
7
+ CUCUMBER_WORKER: 'cucumber_worker',
8
+ MOCHA_WORKER: 'mocha_worker'
8
9
  }
9
10
 
10
11
  export = exporters
package/ext/exporters.js CHANGED
@@ -5,5 +5,6 @@ module.exports = {
5
5
  DATADOG: 'datadog',
6
6
  AGENT_PROXY: 'agent_proxy',
7
7
  JEST_WORKER: 'jest_worker',
8
- CUCUMBER_WORKER: 'cucumber_worker'
8
+ CUCUMBER_WORKER: 'cucumber_worker',
9
+ MOCHA_WORKER: 'mocha_worker'
9
10
  }
package/ext/tags.d.ts CHANGED
@@ -10,6 +10,7 @@ declare const tags: {
10
10
  MANUAL_DROP: 'manual.drop'
11
11
  MEASURED: '_dd.measured'
12
12
  BASE_SERVICE: '_dd.base_service'
13
+ DD_PARENT_ID: '_dd.parent_id'
13
14
  HTTP_URL: 'http.url'
14
15
  HTTP_METHOD: 'http.method'
15
16
  HTTP_STATUS_CODE: 'http.status_code'
package/ext/tags.js CHANGED
@@ -13,6 +13,7 @@ const tags = {
13
13
  MANUAL_DROP: 'manual.drop',
14
14
  MEASURED: '_dd.measured',
15
15
  BASE_SERVICE: '_dd.base_service',
16
+ DD_PARENT_ID: '_dd.parent_id',
16
17
 
17
18
  // HTTP
18
19
  HTTP_URL: 'http.url',
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
- * Create and return a string that can be included in the <head> of a
117
- * document to enable RUM tracing to include it. The resulting string
118
- * should not be cached.
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
 
@@ -191,6 +197,8 @@ interface Plugins {
191
197
  "selenium": tracer.plugins.selenium;
192
198
  "sharedb": tracer.plugins.sharedb;
193
199
  "tedious": tracer.plugins.tedious;
200
+ "undici": tracer.plugins.undici;
201
+ "vitest": tracer.plugins.vitest;
194
202
  "winston": tracer.plugins.winston;
195
203
  }
196
204
 
@@ -549,6 +557,19 @@ declare namespace tracer {
549
557
  */
550
558
  redactionValuePattern?: string
551
559
  }
560
+
561
+ appsec?: {
562
+ /**
563
+ * Configuration of Standalone ASM mode
564
+ */
565
+ standalone?: {
566
+ /**
567
+ * Whether to enable Standalone ASM.
568
+ * @default false
569
+ */
570
+ enabled?: boolean
571
+ }
572
+ }
552
573
  };
553
574
 
554
575
  /**
@@ -684,6 +705,34 @@ declare namespace tracer {
684
705
  * @default 0.1
685
706
  */
686
707
  requestSampling?: number
708
+ },
709
+ /**
710
+ * Configuration for RASP
711
+ */
712
+ rasp?: {
713
+ /** Whether to enable RASP.
714
+ * @default false
715
+ */
716
+ enabled?: boolean
717
+ },
718
+ /**
719
+ * Configuration for stack trace reporting
720
+ */
721
+ stackTrace?: {
722
+ /** Whether to enable stack trace reporting.
723
+ * @default true
724
+ */
725
+ enabled?: boolean,
726
+
727
+ /** Specifies the maximum number of stack traces to be reported.
728
+ * @default 2
729
+ */
730
+ maxStackTraces?: number,
731
+
732
+ /** Specifies the maximum depth of a stack trace to be reported.
733
+ * @default 32
734
+ */
735
+ maxDepth?: number,
687
736
  }
688
737
  };
689
738
 
@@ -1174,6 +1223,13 @@ declare namespace tracer {
1174
1223
  */
1175
1224
  splitByAwsService?: boolean;
1176
1225
 
1226
+ /**
1227
+ * Whether to inject all messages during batch AWS SQS, Kinesis, and SNS send operations. Normal
1228
+ * behavior is to inject the first message in batch send operations.
1229
+ * @default false
1230
+ */
1231
+ batchPropagationEnabled?: boolean;
1232
+
1177
1233
  /**
1178
1234
  * Hooks to run before spans are finished.
1179
1235
  */
@@ -1508,7 +1564,7 @@ declare namespace tracer {
1508
1564
 
1509
1565
  /**
1510
1566
  * This plugin automatically instruments the
1511
- * [jest](https://github.com/facebook/jest) module.
1567
+ * [jest](https://github.com/jestjs/jest) module.
1512
1568
  */
1513
1569
  interface jest extends Integration {}
1514
1570
 
@@ -1785,6 +1841,18 @@ declare namespace tracer {
1785
1841
  */
1786
1842
  interface tedious extends Instrumentation {}
1787
1843
 
1844
+ /**
1845
+ * This plugin automatically instruments the
1846
+ * [undici](https://github.com/nodejs/undici) module.
1847
+ */
1848
+ interface undici extends HttpClient {}
1849
+
1850
+ /**
1851
+ * This plugin automatically instruments the
1852
+ * [vitest](https://github.com/vitest-dev/vitest) module.
1853
+ */
1854
+ interface vitest extends Integration {}
1855
+
1788
1856
  /**
1789
1857
  * This plugin patches the [winston](https://github.com/winstonjs/winston)
1790
1858
  * to automatically inject trace identifiers in log records when the
package/init.js CHANGED
@@ -2,8 +2,26 @@
2
2
 
3
3
  const path = require('path')
4
4
  const Module = require('module')
5
+ const telemetry = require('./packages/dd-trace/src/telemetry/init-telemetry')
6
+ const semver = require('semver')
7
+
8
+ function isTrue (envVar) {
9
+ return ['1', 'true', 'True'].includes(envVar)
10
+ }
11
+
12
+ // eslint-disable-next-line no-console
13
+ let log = { info: isTrue(process.env.DD_TRACE_DEBUG) ? console.log : () => {} }
14
+ if (semver.satisfies(process.versions.node, '>=16')) {
15
+ const Config = require('./packages/dd-trace/src/config')
16
+ log = require('./packages/dd-trace/src/log')
17
+
18
+ // eslint-disable-next-line no-new
19
+ new Config() // we need this to initialize the logger
20
+ }
5
21
 
6
22
  let initBailout = false
23
+ let clobberBailout = false
24
+ const forced = isTrue(process.env.DD_INJECT_FORCE)
7
25
 
8
26
  if (process.env.DD_INJECTION_ENABLED) {
9
27
  // If we're running via single-step install, and we're not in the app's
@@ -19,13 +37,34 @@ if (process.env.DD_INJECTION_ENABLED) {
19
37
  if (resolvedInApp) {
20
38
  const ourselves = path.join(__dirname, 'index.js')
21
39
  if (ourselves !== resolvedInApp) {
40
+ clobberBailout = true
41
+ }
42
+ }
43
+
44
+ // If we're running via single-step install, and the runtime doesn't match
45
+ // the engines field in package.json, then we should not initialize the tracer.
46
+ if (!clobberBailout) {
47
+ const { engines } = require('./package.json')
48
+ const version = process.versions.node
49
+ if (!semver.satisfies(version, engines.node)) {
22
50
  initBailout = true
51
+ telemetry([
52
+ { name: 'abort', tags: ['reason:incompatible_runtime'] },
53
+ { name: 'abort.runtime', tags: [] }
54
+ ])
55
+ log.info('Aborting application instrumentation due to incompatible_runtime.')
56
+ log.info(`Found incompatible runtime nodejs ${version}, Supported runtimes: nodejs ${engines.node}.`)
57
+ if (forced) {
58
+ log.info('DD_INJECT_FORCE enabled, allowing unsupported runtimes and continuing.')
59
+ }
23
60
  }
24
61
  }
25
62
  }
26
63
 
27
- if (!initBailout) {
64
+ if (!clobberBailout && (!initBailout || forced)) {
28
65
  const tracer = require('.')
29
66
  tracer.init()
30
67
  module.exports = tracer
68
+ telemetry('complete', [`injection_forced:${forced && initBailout ? 'true' : 'false'}`])
69
+ log.info('Application instrumentation bootstrapping complete')
31
70
  }
package/initialize.mjs ADDED
@@ -0,0 +1,55 @@
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
+ // Need this IIFE for versions of Node.js without top-level await.
48
+ (async () => {
49
+ await import('./init.js')
50
+ const { register } = await import('node:module')
51
+ if (register) {
52
+ register('./loader-hook.mjs', import.meta.url)
53
+ }
54
+ })()
55
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "6.0.0-pre-3f6ad7e",
3
+ "version": "6.0.0-pre-bed4b20",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -14,37 +14,38 @@
14
14
  "type:test": "cd docs && yarn && yarn test",
15
15
  "lint": "node scripts/check_licenses.js && eslint . && yarn audit --groups dependencies",
16
16
  "services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",
17
- "test": "SERVICES=* yarn services && mocha --colors --exit --expose-gc 'packages/dd-trace/test/setup/node.js' 'packages/*/test/**/*.spec.js'",
18
- "test:appsec": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" \"packages/dd-trace/test/appsec/**/*.spec.js\"",
17
+ "test": "SERVICES=* yarn services && mocha --expose-gc 'packages/dd-trace/test/setup/node.js' 'packages/*/test/**/*.spec.js'",
18
+ "test:appsec": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" \"packages/dd-trace/test/appsec/**/*.spec.js\"",
19
19
  "test:appsec:ci": "nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" -- npm run test:appsec",
20
- "test:appsec:plugins": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/appsec/**/*.@($(echo $PLUGINS)).plugin.spec.js\"",
20
+ "test:appsec:plugins": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/appsec/**/*.@($(echo $PLUGINS)).plugin.spec.js\"",
21
21
  "test:appsec:plugins:ci": "yarn services && nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" -- npm run test:appsec:plugins",
22
22
  "test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,datastreams,encode,exporters,opentelemetry,opentracing,plugins,service-naming,telemetry}/**/*.spec.js\"",
23
23
  "test:trace:core:ci": "npm run test:trace:core -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/**/*.js\"",
24
- "test:instrumentations": "mocha --colors -r 'packages/dd-trace/test/setup/mocha.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
24
+ "test:instrumentations": "mocha -r 'packages/dd-trace/test/setup/mocha.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
25
25
  "test:instrumentations:ci": "nyc --no-clean --include 'packages/datadog-instrumentations/src/**/*.js' -- npm run test:instrumentations",
26
26
  "test:core": "tap \"packages/datadog-core/test/**/*.spec.js\"",
27
27
  "test:core:ci": "npm run test:core -- --coverage --nyc-arg=--include=\"packages/datadog-core/src/**/*.js\"",
28
- "test:lambda": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/lambda/**/*.spec.js\"",
28
+ "test:lambda": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/lambda/**/*.spec.js\"",
29
29
  "test:lambda:ci": "nyc --no-clean --include \"packages/dd-trace/src/lambda/**/*.js\" -- npm run test:lambda",
30
- "test: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\"",
30
+ "test:plugins": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-instrumentations/test/@($(echo $PLUGINS)).spec.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/**/*.spec.js\"",
31
31
  "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",
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\"",
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
- "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
- "test:shimmer": "mocha --colors 'packages/datadog-shimmer/test/**/*.spec.js'",
45
- "test:shimmer:ci": "nyc --no-clean --include 'packages/datadog-shimmer/src/**/*.js' -- npm run test:shimmer",
46
- "leak:core": "node ./scripts/install_plugin_modules && (cd packages/memwatch && yarn) && NODE_PATH=./packages/memwatch/node_modules node --no-warnings ./node_modules/.bin/tape 'packages/dd-trace/test/leak/**/*.js'",
47
- "leak:plugins": "yarn services && (cd packages/memwatch && yarn) && NODE_PATH=./packages/memwatch/node_modules node --no-warnings ./node_modules/.bin/tape \"packages/datadog-plugin-@($(echo $PLUGINS))/test/leak.js\""
35
+ "test:integration": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/*.spec.js\"",
36
+ "test:integration:cucumber": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/cucumber/*.spec.js\"",
37
+ "test:integration:cypress": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/cypress/*.spec.js\"",
38
+ "test:integration:jest": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/jest/*.spec.js\"",
39
+ "test:integration:mocha": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/mocha/*.spec.js\"",
40
+ "test:integration:playwright": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/playwright/*.spec.js\"",
41
+ "test:integration:selenium": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/selenium/*.spec.js\"",
42
+ "test:integration:vitest": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/vitest/*.spec.js\"",
43
+ "test:integration:profiler": "mocha --timeout 180000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/profiler/*.spec.js\"",
44
+ "test:integration:serverless": "mocha --timeout 60000 -r \"packages/dd-trace/test/setup/core.js\" \"integration-tests/serverless/*.spec.js\"",
45
+ "test:integration:plugins": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/integration-test/**/*.spec.js\"",
46
+ "test:unit:plugins": "mocha -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\"",
47
+ "test:shimmer": "mocha 'packages/datadog-shimmer/test/**/*.spec.js'",
48
+ "test:shimmer:ci": "nyc --no-clean --include 'packages/datadog-shimmer/src/**/*.js' -- npm run test:shimmer"
48
49
  },
49
50
  "repository": {
50
51
  "type": "git",
@@ -70,9 +71,9 @@
70
71
  "node": ">=18"
71
72
  },
72
73
  "dependencies": {
73
- "@datadog/native-appsec": "7.1.1",
74
+ "@datadog/native-appsec": "8.0.1",
74
75
  "@datadog/native-iast-rewriter": "2.3.1",
75
- "@datadog/native-iast-taint-tracking": "2.1.0",
76
+ "@datadog/native-iast-taint-tracking": "3.0.0",
76
77
  "@datadog/native-metrics": "^2.0.0",
77
78
  "@datadog/pprof": "5.3.0",
78
79
  "@datadog/sketches-js": "^2.1.0",
@@ -81,19 +82,16 @@
81
82
  "crypto-randomuuid": "^1.0.0",
82
83
  "dc-polyfill": "^0.1.4",
83
84
  "ignore": "^5.2.4",
84
- "import-in-the-middle": "^1.7.4",
85
+ "import-in-the-middle": "^1.8.1",
85
86
  "int64-buffer": "^0.1.9",
86
- "ipaddr.js": "^2.1.0",
87
87
  "istanbul-lib-coverage": "3.2.0",
88
88
  "jest-docblock": "^29.7.0",
89
89
  "koalas": "^1.0.2",
90
90
  "limiter": "1.1.5",
91
91
  "lodash.sortby": "^4.7.0",
92
92
  "lru-cache": "^7.14.0",
93
- "methods": "^1.1.2",
94
93
  "module-details-from-path": "^1.0.3",
95
94
  "msgpack-lite": "^0.1.26",
96
- "node-abort-controller": "^3.1.1",
97
95
  "opentracing": ">=0.12.1",
98
96
  "path-to-regexp": "^0.1.2",
99
97
  "pprof-format": "^2.1.0",
@@ -139,6 +137,6 @@
139
137
  "sinon": "^15.2.0",
140
138
  "sinon-chai": "^3.7.0",
141
139
  "tap": "^16.3.7",
142
- "tape": "^5.6.5"
140
+ "tiktoken": "^1.0.15"
143
141
  }
144
142
  }
@@ -2,13 +2,4 @@
2
2
 
3
3
  // TODO: default to AsyncLocalStorage when it supports triggerAsyncResource
4
4
 
5
- const semver = require('semver')
6
-
7
- // https://github.com/nodejs/node/pull/33801
8
- const hasJavaScriptAsyncHooks = semver.satisfies(process.versions.node, '>=14.5')
9
-
10
- if (hasJavaScriptAsyncHooks) {
11
- module.exports = require('./async_resource')
12
- } else {
13
- module.exports = require('./async_hooks')
14
- }
5
+ module.exports = require('./async_resource')
@@ -7,7 +7,11 @@ const hooks = require('../datadog-instrumentations/src/helpers/hooks.js')
7
7
  const extractPackageAndModulePath = require('../datadog-instrumentations/src/utils/src/extract-package-and-module-path')
8
8
 
9
9
  for (const hook of Object.values(hooks)) {
10
- hook()
10
+ if (typeof hook === 'object') {
11
+ hook.fn()
12
+ } else {
13
+ hook()
14
+ }
11
15
  }
12
16
 
13
17
  const modulesOfInterest = new Set()
@@ -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: ['>=0.5'] }, defs => {
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: ['>=0.5'] }, channel => {
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
  })
@@ -1,6 +1,5 @@
1
1
  'use strict'
2
2
 
3
- const { AbortController } = require('node-abort-controller')
4
3
  const { addHook } = require('./helpers/instrument')
5
4
  const shimmer = require('../../datadog-shimmer')
6
5
  const dc = require('dc-polyfill')
@@ -1,6 +1,5 @@
1
1
  'use strict'
2
2
 
3
- const { AbortController } = require('node-abort-controller')
4
3
  const dc = require('dc-polyfill')
5
4
 
6
5
  const { addHook } = require('./helpers/instrument')
@@ -20,7 +20,8 @@ function wrapRequest (send) {
20
20
 
21
21
  return innerAr.runInAsyncScope(() => {
22
22
  this.on('complete', innerAr.bind(response => {
23
- channel(`apm:aws:request:complete:${channelSuffix}`).publish({ response })
23
+ const cbExists = typeof cb === 'function'
24
+ channel(`apm:aws:request:complete:${channelSuffix}`).publish({ response, cbExists })
24
25
  }))
25
26
 
26
27
  startCh.publish({
@@ -1,6 +1,5 @@
1
1
  'use strict'
2
2
 
3
- const { AbortController } = require('node-abort-controller') // AbortController is not available in node <15
4
3
  const shimmer = require('../../datadog-shimmer')
5
4
  const { channel, addHook } = require('./helpers/instrument')
6
5