dd-trace 5.110.0 → 5.112.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/LICENSE-3rdparty.csv +1 -2
  2. package/README.md +13 -8
  3. package/ci/init.js +21 -2
  4. package/ci/vitest-no-worker-init-setup.mjs +430 -0
  5. package/ext/tags.js +2 -0
  6. package/index.d.ts +34 -1
  7. package/initialize.mjs +5 -6
  8. package/loader-hook.mjs +76 -55
  9. package/package.json +37 -34
  10. package/packages/datadog-instrumentations/src/ai.js +45 -0
  11. package/packages/datadog-instrumentations/src/apollo-server.js +5 -13
  12. package/packages/datadog-instrumentations/src/child_process.js +3 -3
  13. package/packages/datadog-instrumentations/src/claude-agent-sdk.js +587 -0
  14. package/packages/datadog-instrumentations/src/cucumber.js +102 -43
  15. package/packages/datadog-instrumentations/src/cypress-config.js +11 -3
  16. package/packages/datadog-instrumentations/src/fastify.js +27 -8
  17. package/packages/datadog-instrumentations/src/fs.js +8 -6
  18. package/packages/datadog-instrumentations/src/graphql.js +26 -495
  19. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
  20. package/packages/datadog-instrumentations/src/helpers/instrument.js +7 -0
  21. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/ai.js +6 -6
  22. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/claude-agent-sdk.js +17 -0
  23. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +201 -0
  24. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +2 -0
  25. package/packages/datadog-instrumentations/src/jest.js +713 -63
  26. package/packages/datadog-instrumentations/src/mocha/main.js +24 -3
  27. package/packages/datadog-instrumentations/src/mocha/utils.js +128 -22
  28. package/packages/datadog-instrumentations/src/mocha/worker.js +13 -0
  29. package/packages/datadog-instrumentations/src/mongodb.js +74 -0
  30. package/packages/datadog-instrumentations/src/mongoose.js +13 -2
  31. package/packages/datadog-instrumentations/src/playwright.js +13 -9
  32. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +1297 -0
  33. package/packages/datadog-instrumentations/src/vitest-main.js +1594 -0
  34. package/packages/datadog-instrumentations/src/vitest-util.js +254 -0
  35. package/packages/datadog-instrumentations/src/vitest-worker.js +823 -0
  36. package/packages/datadog-instrumentations/src/vitest.js +11 -1855
  37. package/packages/datadog-plugin-ai/src/index.js +1 -1
  38. package/packages/datadog-plugin-ai/src/tracing.js +66 -3
  39. package/packages/datadog-plugin-ai/src/utils.js +17 -4
  40. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/client.js +2 -2
  41. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/context.js +19 -10
  42. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/handler.js +1 -0
  43. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/util.js +47 -11
  44. package/packages/datadog-plugin-child_process/src/index.js +13 -2
  45. package/packages/datadog-plugin-claude-agent-sdk/src/index.js +31 -0
  46. package/packages/datadog-plugin-claude-agent-sdk/src/tracing.js +107 -0
  47. package/packages/datadog-plugin-claude-agent-sdk/src/util.js +15 -0
  48. package/packages/datadog-plugin-cucumber/src/index.js +15 -24
  49. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +360 -14
  50. package/packages/datadog-plugin-cypress/src/index.js +47 -2
  51. package/packages/datadog-plugin-cypress/src/plugin.js +1 -0
  52. package/packages/datadog-plugin-cypress/src/support.js +45 -1
  53. package/packages/datadog-plugin-express/src/code_origin.js +1 -1
  54. package/packages/datadog-plugin-fastify/src/code_origin.js +1 -1
  55. package/packages/datadog-plugin-graphql/src/execute.js +639 -12
  56. package/packages/datadog-plugin-graphql/src/index.js +37 -9
  57. package/packages/datadog-plugin-graphql/src/parse.js +24 -4
  58. package/packages/datadog-plugin-graphql/src/utils.js +9 -2
  59. package/packages/datadog-plugin-graphql/src/validate.js +17 -6
  60. package/packages/datadog-plugin-http/src/index.js +6 -8
  61. package/packages/datadog-plugin-jest/src/index.js +31 -15
  62. package/packages/datadog-plugin-mocha/src/index.js +40 -15
  63. package/packages/datadog-plugin-mongodb-core/src/bulk-write.js +43 -0
  64. package/packages/datadog-plugin-mongodb-core/src/index.js +8 -443
  65. package/packages/datadog-plugin-mongodb-core/src/query.js +452 -0
  66. package/packages/datadog-plugin-openai/src/services.js +2 -2
  67. package/packages/datadog-plugin-playwright/src/index.js +4 -3
  68. package/packages/datadog-plugin-vitest/src/index.js +120 -72
  69. package/packages/datadog-shimmer/src/shimmer.js +37 -16
  70. package/packages/dd-trace/src/aiguard/index.js +9 -14
  71. package/packages/dd-trace/src/aiguard/integrations/index.js +34 -0
  72. package/packages/dd-trace/src/aiguard/integrations/openai.js +47 -33
  73. package/packages/dd-trace/src/aiguard/integrations/vercel-ai.js +42 -28
  74. package/packages/dd-trace/src/aiguard/sdk.js +2 -2
  75. package/packages/dd-trace/src/appsec/api_security/sampler.js +3 -3
  76. package/packages/dd-trace/src/appsec/channels.js +3 -1
  77. package/packages/dd-trace/src/appsec/downstream_requests.js +4 -4
  78. package/packages/dd-trace/src/appsec/graphql.js +14 -11
  79. package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +23 -23
  80. package/packages/dd-trace/src/appsec/iast/security-controls/index.js +2 -2
  81. package/packages/dd-trace/src/appsec/iast/telemetry/index.js +2 -1
  82. package/packages/dd-trace/src/appsec/index.js +10 -1
  83. package/packages/dd-trace/src/appsec/lambda.js +135 -0
  84. package/packages/dd-trace/src/appsec/reporter.js +49 -10
  85. package/packages/dd-trace/src/appsec/telemetry/index.js +1 -1
  86. package/packages/dd-trace/src/appsec/waf/index.js +16 -4
  87. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +4 -4
  88. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +26 -1
  89. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +115 -24
  90. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +21 -6
  91. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +5 -2
  92. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +1 -1
  93. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +1 -1
  94. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +6 -2
  95. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +1 -1
  96. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +130 -20
  97. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +2 -2
  98. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/writer.js +17 -0
  99. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +47 -26
  100. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +2 -2
  101. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +64 -53
  102. package/packages/dd-trace/src/ci-visibility/requests/upload-coverage-report.js +3 -3
  103. package/packages/dd-trace/src/ci-visibility/requests/upload-test-screenshot.js +156 -0
  104. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +23 -5
  105. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +128 -0
  106. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +287 -0
  107. package/packages/dd-trace/src/config/defaults.js +3 -2
  108. package/packages/dd-trace/src/config/generated-config-types.d.ts +71 -57
  109. package/packages/dd-trace/src/config/helper.js +1 -0
  110. package/packages/dd-trace/src/config/index.js +35 -22
  111. package/packages/dd-trace/src/config/major-overrides.js +4 -2
  112. package/packages/dd-trace/src/config/remote_config.js +1 -1
  113. package/packages/dd-trace/src/config/supported-configurations.json +127 -56
  114. package/packages/dd-trace/src/constants.js +7 -0
  115. package/packages/dd-trace/src/crashtracking/crashtracker.js +2 -2
  116. package/packages/dd-trace/src/datastreams/processor.js +11 -3
  117. package/packages/dd-trace/src/exporters/agent/index.js +1 -1
  118. package/packages/dd-trace/src/exporters/agentless/writer.js +4 -4
  119. package/packages/dd-trace/src/llmobs/index.js +1 -1
  120. package/packages/dd-trace/src/llmobs/plugins/ai/ddTelemetry.js +403 -0
  121. package/packages/dd-trace/src/llmobs/plugins/ai/index.js +8 -395
  122. package/packages/dd-trace/src/llmobs/plugins/ai/util.js +27 -0
  123. package/packages/dd-trace/src/llmobs/plugins/ai/vercelTelemetry.js +363 -0
  124. package/packages/dd-trace/src/llmobs/plugins/base.js +4 -4
  125. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +270 -0
  126. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/utils.js +10 -0
  127. package/packages/dd-trace/src/llmobs/plugins/langgraph/index.js +1 -1
  128. package/packages/dd-trace/src/llmobs/sdk.js +3 -3
  129. package/packages/dd-trace/src/llmobs/span_processor.js +1 -1
  130. package/packages/dd-trace/src/llmobs/tagger.js +3 -3
  131. package/packages/dd-trace/src/llmobs/writers/base.js +1 -1
  132. package/packages/dd-trace/src/opentelemetry/metrics/index.js +54 -5
  133. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +40 -0
  134. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_transformer.js +169 -0
  135. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +38 -39
  136. package/packages/dd-trace/src/opentelemetry/span.js +5 -0
  137. package/packages/dd-trace/src/opentelemetry/trace/index.js +4 -0
  138. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +1 -1
  139. package/packages/dd-trace/src/opentracing/tracer.js +6 -1
  140. package/packages/dd-trace/src/plugin_manager.js +23 -7
  141. package/packages/dd-trace/src/plugins/ci_plugin.js +159 -10
  142. package/packages/dd-trace/src/plugins/index.js +2 -0
  143. package/packages/dd-trace/src/plugins/util/llm.js +6 -1
  144. package/packages/dd-trace/src/plugins/util/test.js +15 -9
  145. package/packages/dd-trace/src/profiling/exporter_cli.js +2 -2
  146. package/packages/dd-trace/src/profiling/exporters/agent.js +28 -3
  147. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +3 -3
  148. package/packages/dd-trace/src/profiling/profilers/wall.js +1 -1
  149. package/packages/dd-trace/src/proxy.js +8 -8
  150. package/packages/dd-trace/src/span_processor.js +5 -6
  151. package/packages/dd-trace/src/span_stats.js +96 -78
  152. package/packages/dd-trace/src/startup-log.js +2 -1
  153. package/packages/dd-trace/src/telemetry/dependencies.js +1 -1
  154. package/packages/dd-trace/src/telemetry/endpoints.js +6 -4
  155. package/packages/dd-trace/src/telemetry/index.js +2 -2
  156. package/packages/dd-trace/src/telemetry/logs/index.js +1 -1
  157. package/packages/dd-trace/src/telemetry/send-data.js +8 -8
  158. package/packages/dd-trace/src/telemetry/session-propagation.js +1 -1
  159. package/packages/dd-trace/src/telemetry/telemetry.js +9 -9
  160. package/vendor/dist/@datadog/sketches-js/index.js +1 -1
  161. package/vendor/dist/protobufjs/index.js +1 -1
  162. package/vendor/dist/protobufjs/minimal/index.js +1 -1
  163. package/vendor/dist/shell-quote/index.js +1 -1
  164. package/packages/datadog-plugin-graphql/src/resolve.js +0 -170
package/loader-hook.mjs CHANGED
@@ -13,12 +13,37 @@ import { isRelativeRequire } from './packages/datadog-instrumentations/src/helpe
13
13
 
14
14
  // This file must support Node.js 12.0.0 syntax
15
15
 
16
+ const { builtinModules } = Module
16
17
  const regexpEscape = regexpEscapeModule.default
17
18
  const require = Module.createRequire(import.meta.url)
18
19
  let syncImportInTheMiddleHook
19
20
 
20
- // For some reason `getEnvironmentVariable` is not otherwise available to ESM.
21
- const env = configHelper.getEnvironmentVariable
21
+ // The config helper's named exports aren't visible to ESM; destructure the default.
22
+ const { getValueFromEnvSources } = configHelper
23
+
24
+ // Substrings of resolved URLs that import-in-the-middle must never wrap: re-export
25
+ // shims and internal helper graphs that break when proxied, plus iitm's own files
26
+ // (via `middle`). One alternation so a single test() covers every excluded load.
27
+ export const iitmExclusionRegExp = /middle|langsmith|openai\/_shims|openai\/resources\/chat\/completions\/messages|openai\/agents-core\/dist\/shims|@anthropic-ai\/sdk\/_shims/
28
+
29
+ // Instrumented bare specifiers (`import 'express'`, builtins, symlinked or
30
+ // workspace packages) match against the specifier (the Set); their files inside
31
+ // node_modules match against the URL (the alternation). regexpEscape guards
32
+ // against a regex metacharacter entering a package name.
33
+ const includeModuleNames = new Set()
34
+ let moduleNameAlternation = ''
35
+ for (const moduleName of Object.keys(hooks)) {
36
+ // Relative hooks resolve outside node_modules and are not instrumented here.
37
+ if (isRelativeRequire(moduleName)) continue
38
+ includeModuleNames.add(moduleName)
39
+ // iitm matches a built-in by its node: specifier too, so mirror that and
40
+ // wrap `import 'node:crypto'` as well as `import 'crypto'`.
41
+ if (builtinModules.includes(moduleName)) includeModuleNames.add(`node:${moduleName}`)
42
+ if (moduleNameAlternation !== '') moduleNameAlternation += '|'
43
+ moduleNameAlternation += regexpEscape(moduleName)
44
+ }
45
+
46
+ const nodeModulesIncludeSource = `node_modules/(?:${moduleNameAlternation})/(?!node_modules).+`
22
47
 
23
48
  function initialize (data = {}) {
24
49
  prepareImportInTheMiddleOptions(data)
@@ -26,16 +51,59 @@ function initialize (data = {}) {
26
51
  }
27
52
 
28
53
  function prepareImportInTheMiddleOptions (data = {}) {
29
- if (data.include == null) data.include = []
30
- if (data.exclude == null) data.exclude = []
31
-
32
- addInstrumentations(data)
33
- addSecurityControls(data)
34
- addExclusions(data)
54
+ // A consumer-owned shouldInclude predicate takes over the wrapping decision, so
55
+ // iitm ignores the include/exclude arrays. Building the matcher here keeps the
56
+ // synchronous and asynchronous loaders on one matching implementation.
57
+ data.shouldInclude = createShouldInclude(getValueFromEnvSources('DD_IAST_SECURITY_CONTROLS_CONFIGURATION'))
35
58
 
36
59
  return data
37
60
  }
38
61
 
62
+ /**
63
+ * Builds the import-in-the-middle `shouldInclude(url, specifier)` predicate. iitm
64
+ * calls it for every resolved module and wraps the module when the result is
65
+ * truthy; supplying it replaces iitm's include/exclude list scan.
66
+ *
67
+ * @param {string} [securityControlsConfig] Raw `DD_IAST_SECURITY_CONTROLS_CONFIGURATION`;
68
+ * each entry's module path is instrumented in addition to the hook table.
69
+ */
70
+ function createShouldInclude (securityControlsConfig) {
71
+ const includeRegExp = new RegExp(buildIncludeSource(securityControlsConfig))
72
+
73
+ /**
74
+ * @param {string} url Resolved module URL (`file:`, `node:`, ...).
75
+ * @param {string} specifier Original import specifier.
76
+ */
77
+ return function shouldInclude (url, specifier) {
78
+ return (includeModuleNames.has(specifier) || includeRegExp.test(url)) && !iitmExclusionRegExp.test(url)
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Appends each `DD_IAST_SECURITY_CONTROLS_CONFIGURATION` module path — the third
84
+ * `:`-separated segment of every `;`-separated `<type>:<marks>:<module>:<...>` entry —
85
+ * to the include alternation, escaped.
86
+ *
87
+ * @param {string} [securityControlsConfig] Raw `DD_IAST_SECURITY_CONTROLS_CONFIGURATION`.
88
+ */
89
+ function buildIncludeSource (securityControlsConfig) {
90
+ if (!securityControlsConfig) return nodeModulesIncludeSource
91
+
92
+ let includeSource = nodeModulesIncludeSource
93
+ for (const entry of securityControlsConfig.split(';')) {
94
+ if (!entry) continue
95
+ const first = entry.indexOf(':')
96
+ if (first === -1) continue
97
+ const second = entry.indexOf(':', first + 1)
98
+ if (second === -1) continue
99
+ const third = entry.indexOf(':', second + 1)
100
+
101
+ const subpath = entry.slice(second + 1, third === -1 ? undefined : third).trim()
102
+ if (subpath) includeSource += `|${regexpEscape(subpath)}`
103
+ }
104
+ return includeSource
105
+ }
106
+
39
107
  function load (url, context, nextLoad) {
40
108
  return rewriterLoader.load(url, context, (url, context) => origLoad(url, context, nextLoad))
41
109
  }
@@ -113,51 +181,4 @@ function registerSyncLoaderHooks (data = {}) {
113
181
  return true
114
182
  }
115
183
 
116
- function addInstrumentations (data) {
117
- const instrumentations = Object.keys(hooks)
118
-
119
- for (const moduleName of instrumentations) {
120
- // Skip instrumentation hooks with relative module names
121
- // since there is no current business need of instrumenting imports outside of the node_modules folder
122
- if (!isRelativeRequire(moduleName)) {
123
- data.include.push(new RegExp(`node_modules/${moduleName}/(?!node_modules).+`), moduleName)
124
- }
125
- }
126
- }
127
-
128
- function addSecurityControls (data) {
129
- const raw = env('DD_IAST_SECURITY_CONTROLS_CONFIGURATION')
130
- if (!raw) return
131
- // Parse `;`-separated entries and take the 3rd `:`-separated segment.
132
- // Expected form (per entry): `<...>:<...>:<subpath>:<...>`
133
- const entries = raw.split(';')
134
- for (const entry of entries) {
135
- if (entry) {
136
- const first = entry.indexOf(':')
137
- if (first === -1) continue
138
- const second = entry.indexOf(':', first + 1)
139
- if (second === -1) continue
140
- const third = entry.indexOf(':', second + 1)
141
-
142
- const subpath = entry.slice(second + 1, third === -1 ? undefined : third).trim()
143
- if (subpath) {
144
- data.include.push(new RegExp(regexpEscape(subpath)))
145
- }
146
- }
147
- }
148
- }
149
-
150
- function addExclusions (data) {
151
- data.exclude.push(...iitmExclusions)
152
- }
153
-
154
- export const iitmExclusions = [
155
- /middle/,
156
- /langsmith/,
157
- /openai\/_shims/,
158
- /openai\/resources\/chat\/completions\/messages/,
159
- /openai\/agents-core\/dist\/shims/,
160
- /@anthropic-ai\/sdk\/_shims/,
161
- ]
162
-
163
184
  export { initialize, load, registerSyncLoaderHooks, resolve }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "5.110.0",
3
+ "version": "5.112.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
7
7
  "scripts": {
8
8
  "env": "bash ./plugin-env",
9
- "prepare": "node scripts/patch-istanbul-lib-coverage.js && cd vendor && npm ci --include=dev",
9
+ "prepare": "node scripts/patch-istanbul-lib-coverage.js && node scripts/patch-v8-to-istanbul.js && cd vendor && npm ci --include=dev",
10
10
  "prepack": "node scripts/release/swap-v5-types.js",
11
11
  "bench": "node benchmark/index.js",
12
12
  "bench:e2e:test-optimization": "node benchmark/e2e-test-optimization/benchmark-run.js",
@@ -22,50 +22,50 @@
22
22
  "lint:fix": "node scripts/check_licenses.js && node scripts/check-no-coverage-artifacts.js && node scripts/check-no-mcr-images.js && node scripts/check-docker-image-shas.js && eslint . --concurrency=auto --max-warnings 0 --fix",
23
23
  "lint:inspect": "npx @eslint/config-inspector@latest",
24
24
  "lint:codeowners": "codeowners-audit",
25
- "lint:codeowners:ci": "codeowners-audit --glob='**/*.spec.js' --glob='benchmark/sirun/**' --glob='.agents/**' --glob='.claude/**'",
25
+ "lint:codeowners:ci": "codeowners-audit --glob='**/*.spec.js' --glob='benchmark/sirun/**' --glob='.agents/**' --glob='.claude/**' --glob='integration-tests/**'",
26
26
  "lint:editorconfig": "editorconfig-checker",
27
27
  "release:proposal": "node scripts/release/proposal",
28
28
  "services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",
29
29
  "test": "echo '\nError: The root \"npm test\" command is intentionally disabled.\n\nInstead, run specific test suites:\n - npm run test:trace:core\n - npm run test:appsec\n - etc.\n\nOr run individual test files:\n npx mocha path/to/test.spec.js\n\nSee CONTRIBUTING.md (Testing section) for more details.\n' && exit 1",
30
30
  "test:aiguard": "mocha \"packages/dd-trace/test/aiguard/**/*.spec.js\"",
31
- "test:aiguard:ci": "nyc --silent node init && nyc -- npm run test:aiguard",
31
+ "test:aiguard:ci": "node scripts/c8-ci.js test:aiguard",
32
32
  "test:appsec": "mocha --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" \"packages/dd-trace/test/appsec/**/*.spec.js\"",
33
- "test:appsec:ci": "nyc --silent node init && nyc -- npm run test:appsec",
33
+ "test:appsec:ci": "node scripts/c8-ci.js test:appsec",
34
34
  "test:appsec:plugins": "mocha \"packages/dd-trace/test/appsec/**/*.@(${PLUGINS}).plugin.spec.js\"",
35
- "test:appsec:plugins:ci": "yarn services && nyc --silent node init && nyc -- npm run test:appsec:plugins",
35
+ "test:appsec:plugins:ci": "yarn services && node scripts/c8-ci.js test:appsec:plugins",
36
36
  "test:debugger": "mocha \"packages/dd-trace/test/debugger/**/*.spec.js\"",
37
- "test:debugger:ci": "nyc --silent node init && nyc -- npm run test:debugger",
37
+ "test:debugger:ci": "node scripts/c8-ci.js test:debugger",
38
38
  "test:eslint-rules": "node eslint-rules/*.test.mjs",
39
39
  "test:trace:core": "node scripts/mocha-parallel-files.js --expose-gc --timeout 30000 -- \"packages/dd-trace/test/*.spec.js\" \"packages/dd-trace/test/{agent,ci-visibility,config,crashtracking,datastreams,encode,exporters,msgpack,opentelemetry,opentracing,payload-tagging,plugins,remote_config,service-naming,standalone,telemetry,external-logger}/**/*.spec.js\"",
40
- "test:trace:core:ci": "nyc --silent node init && nyc -- npm run test:trace:core",
40
+ "test:trace:core:ci": "node scripts/c8-ci.js test:trace:core",
41
41
  "test:trace:guardrails": "mocha \"packages/dd-trace/test/guardrails/**/*.spec.js\"",
42
- "test:trace:guardrails:ci": "nyc --silent node init && nyc -- npm run test:trace:guardrails",
42
+ "test:trace:guardrails:ci": "node scripts/c8-ci.js test:trace:guardrails",
43
43
  "test:esbuild": "mocha \"packages/datadog-esbuild/test/**/*.spec.js\"",
44
- "test:esbuild:ci": "nyc --silent node init && nyc -- npm run test:esbuild",
44
+ "test:esbuild:ci": "node scripts/c8-ci.js test:esbuild",
45
45
  "test:webpack": "mocha \"packages/datadog-webpack/test/**/*.spec.js\"",
46
- "test:webpack:ci": "nyc --silent node init && nyc -- npm run test:webpack",
46
+ "test:webpack:ci": "node scripts/c8-ci.js test:webpack",
47
47
  "test:instrumentations": "mocha \"packages/datadog-instrumentations/test/@(${PLUGINS}).spec.js\"",
48
- "test:instrumentations:ci": "yarn services && nyc --silent node init && nyc -- npm run test:instrumentations",
49
- "test:instrumentations:misc": "mocha \"packages/datadog-instrumentations/test/*/**/*.spec.js\"",
50
- "test:instrumentations:misc:ci": "nyc --silent node init && nyc -- npm run test:instrumentations:misc",
48
+ "test:instrumentations:ci": "yarn services && node scripts/c8-ci.js test:instrumentations",
49
+ "test:instrumentations:misc": "mocha \"packages/datadog-instrumentations/test/*/**/*.spec.{js,mjs}\"",
50
+ "test:instrumentations:misc:ci": "node scripts/c8-ci.js test:instrumentations:misc",
51
51
  "test:core": "node scripts/mocha-parallel-files.js --expose-gc --timeout 30000 -- \"packages/datadog-core/test/**/*.spec.js\"",
52
- "test:core:ci": "nyc --silent node init && nyc -- npm run test:core",
52
+ "test:core:ci": "node scripts/c8-ci.js test:core",
53
53
  "test:code-origin": "mocha \"packages/datadog-code-origin/test/**/*.spec.js\"",
54
- "test:code-origin:ci": "nyc --silent node init && nyc -- npm run test:code-origin",
54
+ "test:code-origin:ci": "node scripts/c8-ci.js test:code-origin",
55
55
  "test:lambda": "mocha \"packages/dd-trace/test/lambda/**/*.spec.js\"",
56
- "test:lambda:ci": "nyc --silent node init && nyc -- npm run test:lambda",
56
+ "test:lambda:ci": "node scripts/c8-ci.js test:lambda",
57
57
  "test:llmobs:sdk": "mocha --exclude \"packages/dd-trace/test/llmobs/plugins/**/*.spec.js\" \"packages/dd-trace/test/llmobs/**/*.spec.js\"",
58
- "test:llmobs:sdk:ci": "nyc --silent node init && nyc -- npm run test:llmobs:sdk",
58
+ "test:llmobs:sdk:ci": "node scripts/c8-ci.js test:llmobs:sdk",
59
59
  "test:llmobs:plugins": "mocha \"packages/dd-trace/test/llmobs/plugins/@(${PLUGINS})/*.spec.js\"",
60
- "test:llmobs:plugins:ci": "yarn services && nyc --silent node init && nyc -- npm run test:llmobs:plugins",
60
+ "test:llmobs:plugins:ci": "yarn services && node scripts/c8-ci.js test:llmobs:plugins",
61
61
  "test:openfeature": "mocha \"packages/dd-trace/test/openfeature/**/*.spec.js\"",
62
- "test:openfeature:ci": "nyc --silent node init && nyc -- npm run test:openfeature",
62
+ "test:openfeature:ci": "node scripts/c8-ci.js test:openfeature",
63
63
  "test:plugins": "node --expose-gc ./node_modules/mocha/bin/mocha.js \"packages/datadog-plugin-@(${PLUGINS})/test/**/${SPEC:-*}*.spec.js\"",
64
- "test:plugins:ci": "yarn services && nyc --silent node init && nyc -- npm run test:plugins",
65
- "test:plugins:ci:flaky": "yarn services && nyc --silent node init && nyc -- npm run test:plugins -- --bail --retries 2",
64
+ "test:plugins:ci": "yarn services && node scripts/c8-ci.js test:plugins",
65
+ "test:plugins:ci:flaky": "yarn services && node scripts/c8-ci.js test:plugins --bail --retries 2",
66
66
  "test:plugins:upstream": "node ./packages/dd-trace/test/plugins/suite.js",
67
67
  "test:profiler": "node scripts/mocha-parallel-files.js --expose-gc --timeout 30000 -- \"packages/dd-trace/test/profiling/**/*.spec.js\"",
68
- "test:profiler:ci": "nyc --silent node init && nyc -- npm run test:profiler",
68
+ "test:profiler:ci": "node scripts/c8-ci.js test:profiler",
69
69
  "test:integration": "mocha --timeout 60000 \"integration-tests/*.spec.js\"",
70
70
  "test:integration:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/*.spec.js\"",
71
71
  "test:integration:aiguard": "mocha --timeout 60000 \"integration-tests/aiguard/*.spec.js\"",
@@ -104,9 +104,9 @@
104
104
  "test:integration:plugins:coverage": "yarn services && node ./integration-tests/coverage/run-suite.js \"packages/datadog-plugin-@(${PLUGINS})/test/integration-test/**/${SPEC:-*}*.spec.js\"",
105
105
  "test:unit:plugins": "mocha \"packages/datadog-instrumentations/test/@(${PLUGINS}).spec.js\" \"packages/datadog-plugin-@(${PLUGINS})/test/**/*.spec.js\" --exclude \"packages/datadog-plugin-@(${PLUGINS})/test/integration-test/**/*.spec.js\"",
106
106
  "test:release": "mocha \"scripts/release/**/*.spec.js\"",
107
- "test:scripts": "mocha \"scripts/helpers/**/*.spec.js\"",
107
+ "test:scripts": "mocha \"scripts/helpers/**/*.spec.js\" \"scripts/*.spec.mjs\"",
108
108
  "test:shimmer": "mocha \"packages/datadog-shimmer/test/**/*.spec.js\"",
109
- "test:shimmer:ci": "nyc --silent node init && nyc -- npm run test:shimmer",
109
+ "test:shimmer:ci": "node scripts/c8-ci.js test:shimmer",
110
110
  "verify:workflow-job-names": "node scripts/verify-workflow-job-names.js",
111
111
  "verify-exercised-tests": "node scripts/verify-exercised-tests.js"
112
112
  },
@@ -164,7 +164,7 @@
164
164
  ],
165
165
  "dependencies": {
166
166
  "dc-polyfill": "^0.1.11",
167
- "import-in-the-middle": "^3.1.0",
167
+ "import-in-the-middle": "^3.3.1",
168
168
  "opentracing": ">=0.14.7"
169
169
  },
170
170
  "optionalDependencies": {
@@ -192,24 +192,25 @@
192
192
  "@types/mocha": "^10.0.10",
193
193
  "@types/node": "^18.19.106",
194
194
  "@types/sinon": "^21.0.1",
195
- "axios": "^1.18.0",
195
+ "axios": "^1.18.1",
196
196
  "benchmark": "^2.1.4",
197
197
  "body-parser": "^2.3.0",
198
198
  "bun": "1.3.14",
199
+ "c8": "^11.0.0",
199
200
  "codeowners-audit": "^2.9.0",
200
201
  "editorconfig-checker": "^6.1.1",
201
202
  "eslint": "^9.39.2",
202
- "eslint-plugin-cypress": "^6.4.1",
203
+ "eslint-plugin-cypress": "^6.4.2",
203
204
  "eslint-plugin-import": "^2.32.0",
204
- "eslint-plugin-jsdoc": "^63.0.6",
205
+ "eslint-plugin-jsdoc": "^63.0.10",
205
206
  "eslint-plugin-mocha": "^11.3.0",
206
- "eslint-plugin-n": "^18.1.0",
207
+ "eslint-plugin-n": "^18.2.1",
207
208
  "eslint-plugin-promise": "^7.3.0",
208
209
  "eslint-plugin-sonarjs": "^4.1.0",
209
210
  "eslint-plugin-unicorn": "^64.0.0",
210
211
  "express": "^5.1.0",
211
212
  "glob": "^10.4.5",
212
- "globals": "^17.2.0",
213
+ "globals": "^17.7.0",
213
214
  "graphql": "*",
214
215
  "husky": "^9.1.7",
215
216
  "istanbul-lib-report": "^3.0.0",
@@ -219,7 +220,7 @@
219
220
  "mocha-junit-reporter": "^2.2.1",
220
221
  "mocha-multi-reporters": "^1.5.1",
221
222
  "multer": "^2.2.0",
222
- "nock": "^14.0.15",
223
+ "nock": "^14.0.16",
223
224
  "node-preload": "^0.2.1",
224
225
  "nyc": "^18.0.0",
225
226
  "octokit": "^5.0.3",
@@ -227,11 +228,13 @@
227
228
  "proxyquire": "^2.1.3",
228
229
  "retry": "^0.13.1",
229
230
  "semifies": "^1.0.0",
230
- "semver": "^7.8.4",
231
+ "semver": "^7.8.5",
231
232
  "sinon": "^22.0.0",
233
+ "test-exclude": "^8.0.0",
232
234
  "tiktoken": "^1.0.21",
233
235
  "typescript": "^6.0.3",
234
- "workerpool": "^10.0.2",
236
+ "v8-to-istanbul": "^9.0.0",
237
+ "workerpool": "^10.0.3",
235
238
  "yaml": "^2.9.0",
236
239
  "yarn-deduplicate": "^6.0.2"
237
240
  }
@@ -233,4 +233,49 @@ for (const hook of getHooks('ai')) {
233
233
  })
234
234
  }
235
235
 
236
+ const aiSdkTelemetryChannel = tracingChannel('ai:telemetry')
237
+ const aiSdkTelemetryStreamedChunkChannel = channel('dd-trace:vercel-ai:chunk')
238
+
239
+ // for testing, and possibly actual instrumentation use, we want to
240
+ // guard against double-subscribing to the asyncEnd channel of the
241
+ // vercel ai-provided tracingChannel
242
+ let subscribed = false
243
+
244
+ // as of the v7 release, the ai sdk does not automatically aggregate streamed responses
245
+ // we will handle emitting the chunks directly for products to handle
246
+ addHook({ name: 'ai', versions: ['>=7.0.0'] }, exports => {
247
+ if (subscribed) return exports
248
+ subscribed = true
249
+
250
+ // ai sdk v7 only supported on node.js 22+
251
+ // inlining this import here so we only import in those cases
252
+ // eslint-disable-next-line n/no-unsupported-features/node-builtins
253
+ const { TransformStream } = require('node:stream/web')
254
+
255
+ aiSdkTelemetryChannel.subscribe({
256
+ asyncEnd (ctx) {
257
+ // guard against this event being re-emitted.
258
+ if (!ctx.isStream || !ctx.result?.stream || ctx.streamConsumed) return
259
+
260
+ const transform = new TransformStream({
261
+ transform (chunk, controller) {
262
+ const done = chunk.type === 'finish'
263
+
264
+ aiSdkTelemetryStreamedChunkChannel.publish({ ctx, chunk, done })
265
+
266
+ if (done) {
267
+ aiSdkTelemetryChannel.asyncEnd.publish(ctx)
268
+ }
269
+
270
+ controller.enqueue(chunk) // pass through value
271
+ },
272
+ })
273
+
274
+ ctx.result.stream = ctx.result.stream.pipeThrough(transform)
275
+ },
276
+ })
277
+
278
+ return exports
279
+ })
280
+
236
281
  module.exports = { wrapModelWithLifecycle }
@@ -112,24 +112,16 @@ function apolloDrainHttpServerHook (drainModule) {
112
112
  return drainModule
113
113
  }
114
114
 
115
- addHook({ name: '@apollo/server', file: 'dist/cjs/ApolloServer.js', versions: ['4'] }, apolloServerHook)
115
+ addHook({ name: '@apollo/server', file: 'dist/cjs/ApolloServer.js', versions: ['>=4'] }, apolloServerHook)
116
116
 
117
117
  addHook({ name: '@apollo/server', file: 'dist/cjs/express4/index.js', versions: ['4'] }, apolloExpress4Hook)
118
118
 
119
- addHook({ name: '@apollo/server', file: 'dist/cjs/utils/HeaderMap.js', versions: ['4'] }, apolloHeaderMapHook)
120
-
121
119
  addHook(
122
- { name: '@apollo/server', file: 'dist/cjs/plugin/drainHttpServer/index.js', versions: ['>=5.0.0'] },
123
- apolloDrainHttpServerHook
120
+ { name: '@apollo/server', file: 'dist/cjs/utils/HeaderMap.js', versions: ['>=4'] },
121
+ apolloHeaderMapHook
124
122
  )
125
123
 
126
124
  addHook(
127
- { name: '@apollo/server', file: 'dist/cjs/runHttpQuery.js', versions: ['>=5.0.0'] },
128
- (runHttpQueryModule) => {
129
- shimmer.wrap(runHttpQueryModule, 'runHttpQuery', function wrapRunHttpQuery (originalRunHttpQuery) {
130
- return wrapExecuteHTTPGraphQLRequest(originalRunHttpQuery)
131
- })
132
-
133
- return runHttpQueryModule
134
- }
125
+ { name: '@apollo/server', file: 'dist/cjs/plugin/drainHttpServer/index.js', versions: ['>=5.0.0'] },
126
+ apolloDrainHttpServerHook
135
127
  )
@@ -129,7 +129,7 @@ function wrapChildProcessCustomPromisifyMethod (customPromisifyMethod, shell) {
129
129
  const context = createContextFromChildProcessInfo(childProcessInfo)
130
130
  context.callArgs = callArgs
131
131
 
132
- const { start, end, asyncStart, asyncEnd, error } = childProcessChannel
132
+ const { start, end, asyncStart, asyncEnd, error: errorChannel } = childProcessChannel
133
133
  start.publish(context)
134
134
 
135
135
  let result
@@ -140,7 +140,7 @@ function wrapChildProcessCustomPromisifyMethod (customPromisifyMethod, shell) {
140
140
  result = customPromisifyMethod.apply(this, context.callArgs)
141
141
  } catch (error) {
142
142
  context.error = error
143
- error.publish(context)
143
+ errorChannel.publish(context)
144
144
  throw error
145
145
  } finally {
146
146
  end.publish(context)
@@ -149,7 +149,7 @@ function wrapChildProcessCustomPromisifyMethod (customPromisifyMethod, shell) {
149
149
 
150
150
  function reject (err) {
151
151
  context.error = err
152
- error.publish(context)
152
+ errorChannel.publish(context)
153
153
  asyncStart.publish(context)
154
154
 
155
155
  asyncEnd.publish(context)