dd-trace 5.110.0 → 5.111.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 (115) hide show
  1. package/README.md +13 -8
  2. package/ci/init.js +21 -2
  3. package/ci/vitest-no-worker-init-setup.mjs +430 -0
  4. package/ext/tags.js +2 -0
  5. package/index.d.ts +13 -0
  6. package/initialize.mjs +5 -6
  7. package/loader-hook.mjs +76 -55
  8. package/package.json +9 -9
  9. package/packages/datadog-instrumentations/src/fs.js +8 -6
  10. package/packages/datadog-instrumentations/src/graphql.js +26 -495
  11. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +201 -0
  12. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +1 -0
  13. package/packages/datadog-instrumentations/src/mongoose.js +14 -2
  14. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +1293 -0
  15. package/packages/datadog-instrumentations/src/vitest-main.js +1567 -0
  16. package/packages/datadog-instrumentations/src/vitest-util.js +249 -0
  17. package/packages/datadog-instrumentations/src/vitest-worker.js +753 -0
  18. package/packages/datadog-instrumentations/src/vitest.js +11 -1855
  19. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/client.js +2 -2
  20. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/context.js +18 -10
  21. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/util.js +47 -11
  22. package/packages/datadog-plugin-cucumber/src/index.js +1 -1
  23. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +10 -4
  24. package/packages/datadog-plugin-cypress/src/support.js +45 -1
  25. package/packages/datadog-plugin-express/src/code_origin.js +1 -1
  26. package/packages/datadog-plugin-fastify/src/code_origin.js +1 -1
  27. package/packages/datadog-plugin-graphql/src/execute.js +627 -11
  28. package/packages/datadog-plugin-graphql/src/index.js +20 -8
  29. package/packages/datadog-plugin-graphql/src/parse.js +24 -4
  30. package/packages/datadog-plugin-graphql/src/validate.js +16 -5
  31. package/packages/datadog-plugin-http/src/index.js +6 -8
  32. package/packages/datadog-plugin-jest/src/index.js +1 -1
  33. package/packages/datadog-plugin-mocha/src/index.js +1 -1
  34. package/packages/datadog-plugin-openai/src/services.js +2 -2
  35. package/packages/datadog-plugin-playwright/src/index.js +1 -1
  36. package/packages/datadog-plugin-vitest/src/index.js +69 -63
  37. package/packages/datadog-shimmer/src/shimmer.js +37 -16
  38. package/packages/dd-trace/src/aiguard/sdk.js +2 -2
  39. package/packages/dd-trace/src/appsec/api_security/sampler.js +3 -3
  40. package/packages/dd-trace/src/appsec/channels.js +3 -1
  41. package/packages/dd-trace/src/appsec/downstream_requests.js +4 -4
  42. package/packages/dd-trace/src/appsec/graphql.js +5 -5
  43. package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +26 -19
  44. package/packages/dd-trace/src/appsec/iast/security-controls/index.js +2 -2
  45. package/packages/dd-trace/src/appsec/iast/telemetry/index.js +2 -1
  46. package/packages/dd-trace/src/appsec/index.js +10 -1
  47. package/packages/dd-trace/src/appsec/lambda.js +135 -0
  48. package/packages/dd-trace/src/appsec/reporter.js +49 -10
  49. package/packages/dd-trace/src/appsec/telemetry/index.js +1 -1
  50. package/packages/dd-trace/src/appsec/waf/index.js +16 -4
  51. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +4 -4
  52. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +21 -6
  53. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +2 -2
  54. package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +1 -1
  55. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +1 -1
  56. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +3 -2
  57. package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +1 -1
  58. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +55 -13
  59. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +2 -2
  60. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/writer.js +17 -0
  61. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +47 -26
  62. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +2 -2
  63. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +64 -53
  64. package/packages/dd-trace/src/ci-visibility/requests/upload-coverage-report.js +3 -3
  65. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +23 -5
  66. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +128 -0
  67. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +287 -0
  68. package/packages/dd-trace/src/config/defaults.js +3 -2
  69. package/packages/dd-trace/src/config/generated-config-types.d.ts +61 -57
  70. package/packages/dd-trace/src/config/helper.js +1 -0
  71. package/packages/dd-trace/src/config/index.js +35 -22
  72. package/packages/dd-trace/src/config/major-overrides.js +4 -2
  73. package/packages/dd-trace/src/config/remote_config.js +1 -1
  74. package/packages/dd-trace/src/config/supported-configurations.json +90 -56
  75. package/packages/dd-trace/src/constants.js +7 -0
  76. package/packages/dd-trace/src/datastreams/processor.js +11 -3
  77. package/packages/dd-trace/src/exporters/agent/index.js +1 -1
  78. package/packages/dd-trace/src/exporters/agentless/writer.js +4 -4
  79. package/packages/dd-trace/src/llmobs/index.js +1 -1
  80. package/packages/dd-trace/src/llmobs/plugins/base.js +4 -4
  81. package/packages/dd-trace/src/llmobs/plugins/langgraph/index.js +1 -1
  82. package/packages/dd-trace/src/llmobs/sdk.js +3 -3
  83. package/packages/dd-trace/src/llmobs/span_processor.js +1 -1
  84. package/packages/dd-trace/src/llmobs/tagger.js +3 -3
  85. package/packages/dd-trace/src/llmobs/writers/base.js +1 -1
  86. package/packages/dd-trace/src/opentelemetry/metrics/index.js +54 -5
  87. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +40 -0
  88. package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_transformer.js +169 -0
  89. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +38 -39
  90. package/packages/dd-trace/src/opentelemetry/trace/index.js +4 -0
  91. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +1 -1
  92. package/packages/dd-trace/src/opentracing/tracer.js +6 -1
  93. package/packages/dd-trace/src/plugin_manager.js +7 -7
  94. package/packages/dd-trace/src/plugins/ci_plugin.js +12 -3
  95. package/packages/dd-trace/src/plugins/util/llm.js +6 -1
  96. package/packages/dd-trace/src/plugins/util/test.js +11 -9
  97. package/packages/dd-trace/src/profiling/exporter_cli.js +2 -2
  98. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +3 -3
  99. package/packages/dd-trace/src/profiling/profilers/wall.js +1 -1
  100. package/packages/dd-trace/src/proxy.js +8 -8
  101. package/packages/dd-trace/src/span_processor.js +5 -6
  102. package/packages/dd-trace/src/span_stats.js +96 -78
  103. package/packages/dd-trace/src/startup-log.js +2 -1
  104. package/packages/dd-trace/src/telemetry/dependencies.js +1 -1
  105. package/packages/dd-trace/src/telemetry/endpoints.js +6 -4
  106. package/packages/dd-trace/src/telemetry/index.js +2 -2
  107. package/packages/dd-trace/src/telemetry/logs/index.js +1 -1
  108. package/packages/dd-trace/src/telemetry/send-data.js +8 -8
  109. package/packages/dd-trace/src/telemetry/session-propagation.js +1 -1
  110. package/packages/dd-trace/src/telemetry/telemetry.js +9 -9
  111. package/vendor/dist/@datadog/sketches-js/index.js +1 -1
  112. package/vendor/dist/protobufjs/index.js +1 -1
  113. package/vendor/dist/protobufjs/minimal/index.js +1 -1
  114. package/vendor/dist/shell-quote/index.js +1 -1
  115. package/packages/datadog-plugin-graphql/src/resolve.js +0 -170
@@ -0,0 +1,249 @@
1
+ 'use strict'
2
+
3
+ const log = require('../../dd-trace/src/log')
4
+ const { channel } = require('./helpers/instrument')
5
+
6
+ // test hooks
7
+ const testStartCh = channel('ci:vitest:test:start')
8
+ const testFinishTimeCh = channel('ci:vitest:test:finish-time')
9
+ const testPassCh = channel('ci:vitest:test:pass')
10
+ const testErrorCh = channel('ci:vitest:test:error')
11
+ const testSkipCh = channel('ci:vitest:test:skip')
12
+ const testFnCh = channel('ci:vitest:test:fn')
13
+
14
+ // test suite hooks
15
+ const testSuiteStartCh = channel('ci:vitest:test-suite:start')
16
+ const testSuiteFinishCh = channel('ci:vitest:test-suite:finish')
17
+ const testSuiteErrorCh = channel('ci:vitest:test-suite:error')
18
+
19
+ // test session hooks
20
+ const testSessionStartCh = channel('ci:vitest:session:start')
21
+ const testSessionFinishCh = channel('ci:vitest:session:finish')
22
+ const testSessionConfigurationCh = channel('ci:vitest:session:configuration')
23
+ const libraryConfigurationCh = channel('ci:vitest:library-configuration')
24
+ const knownTestsCh = channel('ci:vitest:known-tests')
25
+ const isEarlyFlakeDetectionFaultyCh = channel('ci:vitest:is-early-flake-detection-faulty')
26
+ const testManagementTestsCh = channel('ci:vitest:test-management-tests')
27
+ const modifiedFilesCh = channel('ci:vitest:modified-files')
28
+
29
+ const workerReportTraceCh = channel('ci:vitest:worker-report:trace')
30
+ const workerReportLogsCh = channel('ci:vitest:worker-report:logs')
31
+ const codeCoverageReportCh = channel('ci:vitest:coverage-report')
32
+
33
+ function findExportByName (pkg, name) {
34
+ for (const [key, value] of Object.entries(pkg)) {
35
+ if (value?.name === name) {
36
+ return { key, value }
37
+ }
38
+ }
39
+ }
40
+
41
+ function getChannelPromise (channelToPublishTo, frameworkVersion, payload) {
42
+ return new Promise(resolve => {
43
+ channelToPublishTo.publish({ ...payload, onDone: resolve, frameworkVersion })
44
+ })
45
+ }
46
+
47
+ function getTestRunnerExport (testPackage) {
48
+ return findExportByName(testPackage, 'VitestTestRunner') || findExportByName(testPackage, 'TestRunner')
49
+ }
50
+
51
+ function getTypeTasks (fileTasks, type = 'test') {
52
+ const typeTasks = []
53
+
54
+ function getTasks (tasks) {
55
+ for (const task of tasks) {
56
+ if (task.type === type) {
57
+ typeTasks.push(task)
58
+ } else if (task.tasks) {
59
+ getTasks(task.tasks)
60
+ }
61
+ }
62
+ }
63
+
64
+ getTasks(fileTasks)
65
+
66
+ return typeTasks
67
+ }
68
+
69
+ function getTestName (task) {
70
+ let testName = task.name
71
+ let currentTask = task.suite
72
+
73
+ while (currentTask) {
74
+ if (currentTask.name) {
75
+ testName = `${currentTask.name} ${testName}`
76
+ }
77
+ currentTask = currentTask.suite
78
+ }
79
+
80
+ return testName
81
+ }
82
+
83
+ function getWorkspaceProject (ctx) {
84
+ return ctx.getCoreWorkspaceProject
85
+ ? ctx.getCoreWorkspaceProject()
86
+ : ctx.getRootProject()
87
+ }
88
+
89
+ function setProvidedContext (ctx, values, warningMessage) {
90
+ try {
91
+ Object.assign(getWorkspaceProject(ctx)._provided, values)
92
+ } catch {
93
+ log.warn(warningMessage)
94
+ }
95
+ }
96
+
97
+ function getProvidedContext () {
98
+ try {
99
+ const {
100
+ _ddIsEarlyFlakeDetectionEnabled,
101
+ _ddIsDiEnabled,
102
+ _ddTestPropertiesByFilepath: testPropertiesByFilepath,
103
+ _ddEarlyFlakeDetectionNumRetries: numRepeats,
104
+ _ddEarlyFlakeDetectionSlowTestRetries: slowTestRetries,
105
+ _ddIsKnownTestsEnabled: isKnownTestsEnabled,
106
+ _ddIsTestManagementTestsEnabled: isTestManagementTestsEnabled,
107
+ _ddTestManagementAttemptToFixRetries: testManagementAttemptToFixRetries,
108
+ _ddIsFlakyTestRetriesEnabled: isFlakyTestRetriesEnabled,
109
+ _ddFlakyTestRetriesCount: flakyTestRetriesCount,
110
+ _ddFlakyTestRetriesIncludesUnnamedProject: flakyTestRetriesIncludesUnnamedProject,
111
+ _ddFlakyTestRetriesProjectNames: flakyTestRetriesProjectNames,
112
+ _ddIsImpactedTestsEnabled: isImpactedTestsEnabled,
113
+ _ddTestSessionId: testSessionId,
114
+ _ddTestModuleId: testModuleId,
115
+ _ddTestCommand: testCommand,
116
+ _ddRepositoryRoot: repositoryRoot,
117
+ _ddCodeOwnersEntries: codeOwnersEntries,
118
+ } = globalThis.__vitest_worker__.providedContext
119
+
120
+ return {
121
+ isDiEnabled: _ddIsDiEnabled,
122
+ isEarlyFlakeDetectionEnabled: _ddIsEarlyFlakeDetectionEnabled,
123
+ testPropertiesByFilepath,
124
+ numRepeats,
125
+ slowTestRetries: slowTestRetries ?? {},
126
+ isKnownTestsEnabled,
127
+ isTestManagementTestsEnabled,
128
+ testManagementAttemptToFixRetries,
129
+ isFlakyTestRetriesEnabled,
130
+ flakyTestRetriesCount: flakyTestRetriesCount ?? 0,
131
+ flakyTestRetriesIncludesUnnamedProject,
132
+ flakyTestRetriesProjectNames,
133
+ isImpactedTestsEnabled,
134
+ testSessionId,
135
+ testModuleId,
136
+ testCommand,
137
+ repositoryRoot,
138
+ codeOwnersEntries,
139
+ }
140
+ } catch {
141
+ log.error('Vitest workers could not parse provided context, so some features will not work.')
142
+ return {
143
+ isDiEnabled: false,
144
+ isEarlyFlakeDetectionEnabled: false,
145
+ testPropertiesByFilepath: {},
146
+ numRepeats: 0,
147
+ slowTestRetries: {},
148
+ isKnownTestsEnabled: false,
149
+ isTestManagementTestsEnabled: false,
150
+ testManagementAttemptToFixRetries: 0,
151
+ isFlakyTestRetriesEnabled: false,
152
+ flakyTestRetriesCount: 0,
153
+ flakyTestRetriesIncludesUnnamedProject: false,
154
+ flakyTestRetriesProjectNames: undefined,
155
+ isImpactedTestsEnabled: false,
156
+ testSessionId: undefined,
157
+ testModuleId: undefined,
158
+ testCommand: undefined,
159
+ repositoryRoot: undefined,
160
+ codeOwnersEntries: undefined,
161
+ }
162
+ }
163
+ }
164
+
165
+ function isFlakyTestRetriesEnabledForTask (providedContext, task) {
166
+ if (!providedContext.isFlakyTestRetriesEnabled) return false
167
+
168
+ const { flakyTestRetriesProjectNames } = providedContext
169
+ if (!Array.isArray(flakyTestRetriesProjectNames)) return true
170
+
171
+ const projectName = task.file?.projectName
172
+ if (!projectName) {
173
+ return providedContext.flakyTestRetriesIncludesUnnamedProject === true
174
+ }
175
+
176
+ return flakyTestRetriesProjectNames.includes(projectName)
177
+ }
178
+
179
+ /**
180
+ * Return the main-prepared Test Optimization metadata for a Vitest test.
181
+ *
182
+ * @param {{ testPropertiesByFilepath?: Record<string, {
183
+ * testSuite?: string,
184
+ * knownTests?: string[],
185
+ * testManagementTests?: Record<string, {
186
+ * isAttemptToFix?: boolean,
187
+ * isDisabled?: boolean,
188
+ * isQuarantined?: boolean
189
+ * }>,
190
+ * isModified?: boolean
191
+ * }> }} providedContext
192
+ * @param {string} testSuiteAbsolutePath
193
+ * @param {string} testName
194
+ * @returns {{
195
+ * testSuite?: string,
196
+ * isNew: boolean,
197
+ * isModified: boolean,
198
+ * isAttemptToFix?: boolean,
199
+ * isDisabled?: boolean,
200
+ * isQuarantined?: boolean
201
+ * }}
202
+ */
203
+ function getVitestTestProperties (providedContext, testSuiteAbsolutePath, testName) {
204
+ const testProperties = providedContext.testPropertiesByFilepath?.[testSuiteAbsolutePath]
205
+ const knownTests = testProperties?.knownTests
206
+ const testManagementProperties = testProperties?.testManagementTests?.[testName] || {}
207
+
208
+ return {
209
+ testSuite: testProperties?.testSuite,
210
+ isNew: Array.isArray(knownTests) ? !knownTests.includes(testName) : false,
211
+ isModified: testProperties?.isModified === true,
212
+ isAttemptToFix: testManagementProperties.isAttemptToFix,
213
+ isDisabled: testManagementProperties.isDisabled,
214
+ isQuarantined: testManagementProperties.isQuarantined,
215
+ }
216
+ }
217
+
218
+ module.exports = {
219
+ testStartCh,
220
+ testFinishTimeCh,
221
+ testPassCh,
222
+ testErrorCh,
223
+ testSkipCh,
224
+ testFnCh,
225
+ testSuiteStartCh,
226
+ testSuiteFinishCh,
227
+ testSuiteErrorCh,
228
+ testSessionStartCh,
229
+ testSessionFinishCh,
230
+ testSessionConfigurationCh,
231
+ libraryConfigurationCh,
232
+ knownTestsCh,
233
+ isEarlyFlakeDetectionFaultyCh,
234
+ testManagementTestsCh,
235
+ modifiedFilesCh,
236
+ workerReportTraceCh,
237
+ workerReportLogsCh,
238
+ codeCoverageReportCh,
239
+ findExportByName,
240
+ getChannelPromise,
241
+ getTestRunnerExport,
242
+ getTypeTasks,
243
+ getTestName,
244
+ getWorkspaceProject,
245
+ setProvidedContext,
246
+ getProvidedContext,
247
+ isFlakyTestRetriesEnabledForTask,
248
+ getVitestTestProperties,
249
+ }