@depup/dd-trace 6.8.0-depup.0 → 6.10.0-depup.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 (211) hide show
  1. package/README.md +9 -3
  2. package/changes.json +8 -3
  3. package/ci/diagnose.js +27 -25
  4. package/ci/init.js +6 -6
  5. package/ci/runbook.md +114 -20
  6. package/ci/test-optimization-validation/approval-artifacts.js +36 -3
  7. package/ci/test-optimization-validation/approval.js +78 -22
  8. package/ci/test-optimization-validation/blocker-category.js +24 -0
  9. package/ci/test-optimization-validation/ci-discovery.js +23 -17
  10. package/ci/test-optimization-validation/ci-package-scripts.js +34 -6
  11. package/ci/test-optimization-validation/ci-remediation.js +1 -1
  12. package/ci/test-optimization-validation/cli.js +280 -52
  13. package/ci/test-optimization-validation/command-blocker.js +159 -20
  14. package/ci/test-optimization-validation/command-output-policy.js +9 -3
  15. package/ci/test-optimization-validation/command-runner.js +9 -7
  16. package/ci/test-optimization-validation/environment.js +4 -2
  17. package/ci/test-optimization-validation/executable.js +15 -13
  18. package/ci/test-optimization-validation/execution-lock.js +70 -0
  19. package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +3 -0
  20. package/ci/test-optimization-validation/framework-adapters/cucumber.js +657 -5
  21. package/ci/test-optimization-validation/framework-adapters/vitest.js +517 -0
  22. package/ci/test-optimization-validation/generated-files.js +38 -28
  23. package/ci/test-optimization-validation/generated-test-contract.js +8 -4
  24. package/ci/test-optimization-validation/generated-verifier.js +24 -17
  25. package/ci/test-optimization-validation/literal-glob.js +52 -0
  26. package/ci/test-optimization-validation/manifest-loader.js +3 -0
  27. package/ci/test-optimization-validation/manifest-scaffold.js +300 -50
  28. package/ci/test-optimization-validation/manifest-schema.js +80 -17
  29. package/ci/test-optimization-validation/offline-fixtures.js +13 -4
  30. package/ci/test-optimization-validation/package-check.js +94 -0
  31. package/ci/test-optimization-validation/plan-writer.js +183 -10
  32. package/ci/test-optimization-validation/preflight-runner.js +110 -31
  33. package/ci/test-optimization-validation/project-build-artifact.js +31 -0
  34. package/ci/test-optimization-validation/redaction.js +18 -27
  35. package/ci/test-optimization-validation/report-writer.js +182 -48
  36. package/ci/test-optimization-validation/result-semantics.js +20 -3
  37. package/ci/test-optimization-validation/runner-command.js +40 -20
  38. package/ci/test-optimization-validation/runner-contract.js +79 -43
  39. package/ci/test-optimization-validation/scenarios/basic-reporting.js +59 -5
  40. package/ci/test-optimization-validation/scenarios/ci-wiring.js +141 -35
  41. package/ci/test-optimization-validation/scenarios/helpers.js +30 -6
  42. package/ci/test-optimization-validation/static-diagnosis.js +10 -3
  43. package/ci/test-optimization-validation/test-output.js +2 -1
  44. package/ci/test-optimization-validation/validation-blocker.js +21 -0
  45. package/ci/vitest-no-worker-init-setup.mjs +140 -42
  46. package/index.d.ts +140 -1
  47. package/init.js +1 -17
  48. package/initialize.mjs +11 -0
  49. package/loader-hook.mjs +6 -4
  50. package/package.json +18 -10
  51. package/packages/datadog-core/src/utils/src/parse-tags.js +0 -1
  52. package/packages/datadog-esbuild/src/utils.js +16 -1
  53. package/packages/datadog-instrumentations/src/ai.js +61 -34
  54. package/packages/datadog-instrumentations/src/bluebird.js +6 -6
  55. package/packages/datadog-instrumentations/src/claude-agent-sdk.js +81 -5
  56. package/packages/datadog-instrumentations/src/confluentinc-kafka-javascript.js +111 -6
  57. package/packages/datadog-instrumentations/src/cucumber.js +124 -47
  58. package/packages/datadog-instrumentations/src/dns.js +21 -2
  59. package/packages/datadog-instrumentations/src/electron.js +1 -0
  60. package/packages/datadog-instrumentations/src/fastify.js +3 -1
  61. package/packages/datadog-instrumentations/src/grpc/client.js +4 -2
  62. package/packages/datadog-instrumentations/src/helpers/callback-instrumentor.js +3 -1
  63. package/packages/datadog-instrumentations/src/helpers/hooks.js +2 -0
  64. package/packages/datadog-instrumentations/src/helpers/pool-acquire.js +629 -0
  65. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +34 -9
  66. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +199 -0
  67. package/packages/datadog-instrumentations/src/helpers/rewriter/loader.mjs +20 -2
  68. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.js +32 -0
  69. package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +62 -0
  70. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +83 -1
  71. package/packages/datadog-instrumentations/src/helpers/router-helper.js +37 -6
  72. package/packages/datadog-instrumentations/src/jest/coverage-backfill.js +1 -1
  73. package/packages/datadog-instrumentations/src/jest.js +980 -234
  74. package/packages/datadog-instrumentations/src/mocha/main.js +108 -10
  75. package/packages/datadog-instrumentations/src/mocha/utils.js +66 -50
  76. package/packages/datadog-instrumentations/src/mocha/webdriverio-protocol.js +25 -0
  77. package/packages/datadog-instrumentations/src/mocha/worker.js +12 -18
  78. package/packages/datadog-instrumentations/src/mysql.js +46 -16
  79. package/packages/datadog-instrumentations/src/mysql2.js +119 -18
  80. package/packages/datadog-instrumentations/src/next.js +155 -23
  81. package/packages/datadog-instrumentations/src/openai.js +14 -0
  82. package/packages/datadog-instrumentations/src/path-to-regexp.js +67 -1
  83. package/packages/datadog-instrumentations/src/pg.js +209 -11
  84. package/packages/datadog-instrumentations/src/playwright.js +173 -79
  85. package/packages/datadog-instrumentations/src/promise-js.js +4 -4
  86. package/packages/datadog-instrumentations/src/promise.js +3 -3
  87. package/packages/datadog-instrumentations/src/router.js +195 -19
  88. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +85 -13
  89. package/packages/datadog-instrumentations/src/vitest-main.js +528 -72
  90. package/packages/datadog-instrumentations/src/vitest-util.js +106 -12
  91. package/packages/datadog-instrumentations/src/vitest-worker.js +382 -40
  92. package/packages/datadog-instrumentations/src/webdriverio.js +212 -22
  93. package/packages/datadog-instrumentations/src/when.js +3 -3
  94. package/packages/datadog-instrumentations/src/ws.js +5 -1
  95. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/trace-checkpoint.js +12 -6
  96. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +59 -48
  97. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +2 -5
  98. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +1 -5
  99. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +1 -3
  100. package/packages/datadog-plugin-cucumber/src/index.js +5 -1
  101. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +51 -47
  102. package/packages/datadog-plugin-cypress/src/support.js +7 -4
  103. package/packages/datadog-plugin-electron/src/net.js +10 -4
  104. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +31 -17
  105. package/packages/datadog-plugin-http/src/client.js +1 -1
  106. package/packages/datadog-plugin-http2/src/client.js +1 -1
  107. package/packages/datadog-plugin-jest/src/index.js +6 -22
  108. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +2 -3
  109. package/packages/datadog-plugin-kafkajs/src/consumer.js +2 -3
  110. package/packages/datadog-plugin-kafkajs/src/producer.js +5 -3
  111. package/packages/datadog-plugin-kafkajs/src/utils.js +65 -7
  112. package/packages/datadog-plugin-mocha/src/index.js +832 -4
  113. package/packages/datadog-plugin-mysql/src/index.js +37 -0
  114. package/packages/datadog-plugin-next/src/index.js +51 -21
  115. package/packages/datadog-plugin-openai/src/tracing.js +4 -0
  116. package/packages/datadog-plugin-openai-agents/src/integration.js +278 -69
  117. package/packages/datadog-plugin-openai-agents/src/processor.js +16 -4
  118. package/packages/datadog-plugin-pg/src/index.js +66 -1
  119. package/packages/datadog-plugin-playwright/src/index.js +1 -1
  120. package/packages/datadog-plugin-vitest/src/index.js +103 -27
  121. package/packages/datadog-plugin-ws/src/util.js +2 -1
  122. package/packages/datadog-shimmer/src/shimmer.js +6 -2
  123. package/packages/dd-trace/src/aiguard/sdk.js +3 -0
  124. package/packages/dd-trace/src/appsec/api_security/normalized-route.js +453 -0
  125. package/packages/dd-trace/src/appsec/{blocking.js → blocking/index.js} +26 -6
  126. package/packages/dd-trace/src/appsec/handlers/auth.js +62 -0
  127. package/packages/dd-trace/src/appsec/handlers/http-request.js +228 -0
  128. package/packages/dd-trace/src/appsec/handlers/http-response.js +78 -0
  129. package/packages/dd-trace/src/appsec/handlers/http-shared.js +24 -0
  130. package/packages/dd-trace/src/appsec/handlers/payments.js +104 -0
  131. package/packages/dd-trace/src/appsec/iast/analyzers/hsts-header-missing-analyzer.js +1 -1
  132. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +1 -1
  133. package/packages/dd-trace/src/appsec/index.js +48 -476
  134. package/packages/dd-trace/src/appsec/sdk/track_event.js +9 -0
  135. package/packages/dd-trace/src/carrier.js +356 -0
  136. package/packages/dd-trace/src/ci-visibility/coverage-report-discovery.js +46 -14
  137. package/packages/dd-trace/src/ci-visibility/efd-retry-policy.js +89 -0
  138. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +27 -13
  139. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +17 -0
  140. package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +21 -1
  141. package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +22 -7
  142. package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +9 -14
  143. package/packages/dd-trace/src/ci-visibility/requests/upload-coverage-report.js +21 -5
  144. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +1 -1
  145. package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +5 -1
  146. package/packages/dd-trace/src/config/generated-config-types.d.ts +5 -0
  147. package/packages/dd-trace/src/config/helper.js +2 -0
  148. package/packages/dd-trace/src/config/index.js +16 -5
  149. package/packages/dd-trace/src/config/remote_config.js +1 -1
  150. package/packages/dd-trace/src/config/supported-configurations.json +18 -0
  151. package/packages/dd-trace/src/datastreams/context.js +6 -1
  152. package/packages/dd-trace/src/datastreams/manager.js +5 -1
  153. package/packages/dd-trace/src/datastreams/pathway.js +23 -22
  154. package/packages/dd-trace/src/datastreams/processor.js +3 -2
  155. package/packages/dd-trace/src/debugger/devtools_client/status.js +1 -1
  156. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +0 -1
  157. package/packages/dd-trace/src/guardrails/apply-pm2-env.js +16 -0
  158. package/packages/dd-trace/src/guardrails/log.js +1 -10
  159. package/packages/dd-trace/src/llmobs/constants/tags.js +5 -0
  160. package/packages/dd-trace/src/llmobs/eval-metric.js +249 -0
  161. package/packages/dd-trace/src/llmobs/experiments/index.js +33 -25
  162. package/packages/dd-trace/src/llmobs/experiments/util.js +4 -2
  163. package/packages/dd-trace/src/llmobs/index.js +34 -2
  164. package/packages/dd-trace/src/llmobs/noop.js +2 -0
  165. package/packages/dd-trace/src/llmobs/plugins/ai/ddTelemetry.js +1 -1
  166. package/packages/dd-trace/src/llmobs/plugins/ai/util.js +1 -1
  167. package/packages/dd-trace/src/llmobs/plugins/bedrockruntime.js +5 -5
  168. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +1 -1
  169. package/packages/dd-trace/src/llmobs/sdk.js +149 -68
  170. package/packages/dd-trace/src/llmobs/span_processor.js +16 -0
  171. package/packages/dd-trace/src/llmobs/tagger.js +96 -0
  172. package/packages/dd-trace/src/llmobs/telemetry.js +18 -0
  173. package/packages/dd-trace/src/llmobs/util.js +78 -0
  174. package/packages/dd-trace/src/llmobs/writers/base.js +3 -0
  175. package/packages/dd-trace/src/llmobs/writers/util.js +2 -0
  176. package/packages/dd-trace/src/log/channels.js +1 -9
  177. package/packages/dd-trace/src/log/levels.js +12 -0
  178. package/packages/dd-trace/src/openfeature/writers/exposures.js +1 -1
  179. package/packages/dd-trace/src/openfeature/writers/util.js +1 -1
  180. package/packages/dd-trace/src/opentelemetry/logs/batch_log_processor.js +1 -1
  181. package/packages/dd-trace/src/opentelemetry/metrics/meter.js +8 -4
  182. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +1 -1
  183. package/packages/dd-trace/src/opentelemetry/span.js +4 -0
  184. package/packages/dd-trace/src/opentracing/propagation/text_map.js +126 -120
  185. package/packages/dd-trace/src/opentracing/propagation/text_map_dsm.js +4 -8
  186. package/packages/dd-trace/src/plugin_manager.js +2 -0
  187. package/packages/dd-trace/src/plugins/ci_plugin.js +21 -5
  188. package/packages/dd-trace/src/plugins/index.js +1 -0
  189. package/packages/dd-trace/src/plugins/util/ci.js +6 -0
  190. package/packages/dd-trace/src/plugins/util/git.js +6 -4
  191. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +2 -2
  192. package/packages/dd-trace/src/plugins/util/ip_extractor.js +1 -1
  193. package/packages/{datadog-plugin-jest/src/util.js → dd-trace/src/plugins/util/jest.js} +3 -62
  194. package/packages/dd-trace/src/plugins/util/stacktrace.js +3 -0
  195. package/packages/dd-trace/src/plugins/util/test.js +397 -74
  196. package/packages/dd-trace/src/plugins/util/url.js +1 -1
  197. package/packages/dd-trace/src/plugins/util/web.js +76 -3
  198. package/packages/dd-trace/src/profiler.js +1 -1
  199. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +1 -1
  200. package/packages/dd-trace/src/profiling/profilers/events.js +2 -2
  201. package/packages/dd-trace/src/proxy.js +1 -0
  202. package/packages/dd-trace/src/ritm.js +5 -0
  203. package/packages/dd-trace/src/runtime_metrics/runtime_metrics.js +4 -2
  204. package/packages/dd-trace/src/sampling_rule.js +4 -2
  205. package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +1 -1
  206. package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +1 -1
  207. package/packages/dd-trace/src/telemetry/logs/index.js +3 -0
  208. package/packages/dd-trace/src/telemetry/telemetry.js +1 -1
  209. package/vendor/dist/pprof-format/index.js +1 -1
  210. package/version.js +10 -8
  211. /package/packages/dd-trace/src/appsec/{blocked_templates.js → blocking/templates.js} +0 -0
@@ -54,4 +54,203 @@ module.exports = [
54
54
  channelName: 'LocalRunner_shutdown',
55
55
  transform: 'waitForAsyncEnd',
56
56
  },
57
+ {
58
+ module: {
59
+ name: '@wdio/jasmine-framework',
60
+ versionRange: '>=9.0.0',
61
+ filePath: 'build/index.js',
62
+ },
63
+ functionQuery: {
64
+ className: 'JasmineAdapter',
65
+ methodName: 'init',
66
+ kind: 'Async',
67
+ },
68
+ channelName: 'JasmineAdapter_init',
69
+ },
70
+ {
71
+ module: {
72
+ name: '@wdio/jasmine-framework',
73
+ versionRange: '>=9.0.0',
74
+ filePath: 'build/index.js',
75
+ },
76
+ astQuery: 'VariableDeclarator[id.name="JasmineAdapter"] > ClassExpression > ClassBody > ' +
77
+ 'MethodDefinition[key.name="init"] ReturnStatement > ' +
78
+ 'CallExpression[callee.object.name="promise"][callee.property.name="then"], ' +
79
+ 'ClassDeclaration[id.name="JasmineAdapter"] > ClassBody > MethodDefinition[key.name="init"] ReturnStatement > ' +
80
+ 'CallExpression[callee.object.name="promise"][callee.property.name="then"]',
81
+ channelName: 'JasmineAdapter_init',
82
+ transform: 'waitForAsyncEnd',
83
+ },
84
+ {
85
+ module: {
86
+ name: '@wdio/jasmine-framework',
87
+ versionRange: '>=9.0.0',
88
+ filePath: 'build/index.js',
89
+ },
90
+ functionQuery: {
91
+ className: 'JasmineAdapter',
92
+ methodName: 'run',
93
+ kind: 'Async',
94
+ },
95
+ channelName: 'JasmineAdapter_run',
96
+ },
97
+ {
98
+ module: {
99
+ name: '@wdio/jasmine-framework',
100
+ versionRange: '>=9.0.0',
101
+ filePath: 'build/index.js',
102
+ },
103
+ astQuery: 'VariableDeclarator[id.name="JasmineAdapter"] > ClassExpression > ClassBody > ' +
104
+ 'MethodDefinition[key.name="run"] ReturnStatement > ' +
105
+ 'CallExpression[callee.object.name="promise"][callee.property.name="then"], ' +
106
+ 'ClassDeclaration[id.name="JasmineAdapter"] > ClassBody > MethodDefinition[key.name="run"] ReturnStatement > ' +
107
+ 'CallExpression[callee.object.name="promise"][callee.property.name="then"]',
108
+ channelName: 'JasmineAdapter_run',
109
+ transform: 'waitForAsyncEnd',
110
+ },
111
+ {
112
+ module: {
113
+ name: '@wdio/jasmine-framework',
114
+ versionRange: '>=9.0.0',
115
+ filePath: 'build/index.js',
116
+ },
117
+ functionQuery: {
118
+ className: 'JasmineReporter',
119
+ methodName: 'specDone',
120
+ kind: 'Sync',
121
+ },
122
+ channelName: 'JasmineReporter_specDone',
123
+ },
124
+ {
125
+ module: {
126
+ name: '@wdio/jasmine-framework',
127
+ versionRange: '>=9.0.0',
128
+ filePath: 'build/index.js',
129
+ },
130
+ functionQuery: {
131
+ className: 'JasmineReporter',
132
+ methodName: 'specStarted',
133
+ kind: 'Sync',
134
+ },
135
+ channelName: 'JasmineReporter_specStarted',
136
+ },
137
+ {
138
+ module: {
139
+ name: '@wdio/jasmine-framework',
140
+ versionRange: '>=9.0.0',
141
+ filePath: 'build/index.js',
142
+ },
143
+ functionQuery: {
144
+ className: 'JasmineReporter',
145
+ methodName: 'suiteStarted',
146
+ kind: 'Sync',
147
+ },
148
+ channelName: 'JasmineReporter_suiteStarted',
149
+ },
150
+ {
151
+ module: {
152
+ name: '@wdio/jasmine-framework',
153
+ versionRange: '>=9.0.0',
154
+ filePath: 'build/index.js',
155
+ },
156
+ functionQuery: {
157
+ className: 'JasmineReporter',
158
+ methodName: 'suiteDone',
159
+ kind: 'Sync',
160
+ },
161
+ channelName: 'JasmineReporter_suiteDone',
162
+ },
163
+ {
164
+ module: {
165
+ name: '@wdio/utils',
166
+ versionRange: '>=9.0.0',
167
+ filePath: 'build/index.js',
168
+ },
169
+ functionQuery: {
170
+ expressionName: 'testFrameworkFnWrapper',
171
+ kind: 'Async',
172
+ },
173
+ channelName: 'testFrameworkFnWrapper',
174
+ },
175
+ {
176
+ module: {
177
+ name: '@wdio/utils',
178
+ versionRange: '>=9.0.0',
179
+ filePath: 'build/index.js',
180
+ },
181
+ functionQuery: {
182
+ functionName: 'executeAsync',
183
+ kind: 'Async',
184
+ },
185
+ channelName: 'executeAsync',
186
+ },
187
+ {
188
+ module: {
189
+ name: '@wdio/utils',
190
+ versionRange: '>=9.0.0',
191
+ filePath: 'build/index.js',
192
+ },
193
+ astQuery: 'FunctionDeclaration[id.name="executeAsync"] CatchClause ' +
194
+ 'IfStatement[test.operator=">"][test.left.object.name="retries"]' +
195
+ '[test.left.property.name="limit"][test.right.object.name="retries"]' +
196
+ '[test.right.property.name="attempts"]',
197
+ channelName: 'executeAsync',
198
+ transform: 'awaitContextCallback',
199
+ transformOptions: {
200
+ callbackArgumentNames: ['err'],
201
+ callbackName: 'retryCallback',
202
+ },
203
+ },
204
+ {
205
+ module: {
206
+ name: 'jasmine-core',
207
+ versionRange: '>=5.0.0 <6.0.0',
208
+ filePath: 'lib/jasmine-core/jasmine.js',
209
+ },
210
+ astQuery: 'AssignmentExpression[left.object.object.name="Spec"]' +
211
+ '[left.object.property.name="prototype"][left.property.name="execute"] > FunctionExpression',
212
+ functionQuery: {
213
+ kind: 'Sync',
214
+ },
215
+ channelName: 'Spec_execute',
216
+ },
217
+ {
218
+ module: {
219
+ name: 'jasmine-core',
220
+ versionRange: '>=5.0.0 <6.0.0',
221
+ filePath: 'lib/jasmine-core/jasmine.js',
222
+ },
223
+ astQuery: 'AssignmentExpression[left.object.object.name="Spec"]' +
224
+ '[left.object.property.name="prototype"][left.property.name="status"] > FunctionExpression',
225
+ functionQuery: {
226
+ kind: 'Sync',
227
+ },
228
+ channelName: 'Spec_attemptDone',
229
+ },
230
+ {
231
+ module: {
232
+ name: 'jasmine-core',
233
+ versionRange: '>=5.0.0 <6.0.0',
234
+ filePath: 'lib/jasmine-core/jasmine.js',
235
+ },
236
+ functionQuery: {
237
+ className: 'Spec',
238
+ methodName: 'executionFinished',
239
+ kind: 'Sync',
240
+ },
241
+ channelName: 'Spec_attemptDone',
242
+ },
243
+ {
244
+ module: {
245
+ name: 'jasmine-core',
246
+ versionRange: '>=5.0.0 <6.0.0',
247
+ filePath: 'lib/jasmine-core/jasmine.js',
248
+ },
249
+ functionQuery: {
250
+ className: 'TreeRunner',
251
+ methodName: '_executeSpec',
252
+ kind: 'Sync',
253
+ },
254
+ channelName: 'Spec_execute',
255
+ },
57
256
  ]
@@ -1,4 +1,8 @@
1
- import { rewrite } from './index.js'
1
+ import * as Module from 'module'
2
+
3
+ const require = Module.createRequire(import.meta.url)
4
+ const { getRewriteTarget } = require('./targets.js')
5
+ let rewriter
2
6
 
3
7
  async function load (url, context, nextLoad) {
4
8
  const result = await nextLoad(url, context)
@@ -12,6 +16,11 @@ function loadSync (url, context, nextLoad) {
12
16
  return rewriteResult(result, url, context)
13
17
  }
14
18
 
19
+ /**
20
+ * @param {{ format?: string, source?: unknown }} result
21
+ * @param {string} url
22
+ * @param {{ format?: string }} context
23
+ */
15
24
  function rewriteResult (result, url, context) {
16
25
  const format = result.format || context.format
17
26
 
@@ -19,7 +28,16 @@ function rewriteResult (result, url, context) {
19
28
  // double-instruments CommonJS entrypoints loaded through sync hooks.
20
29
  if (format === 'commonjs') return result
21
30
 
22
- result.source = rewrite(result.source, url, format)
31
+ if (result.source) {
32
+ const target = getRewriteTarget(url)
33
+ if (target) {
34
+ if (!rewriter) {
35
+ rewriter = require('./index.js')
36
+ }
37
+
38
+ result.source = rewriter.rewrite(result.source, url, format, target)
39
+ }
40
+ }
23
41
 
24
42
  return result
25
43
  }
@@ -0,0 +1,32 @@
1
+ 'use strict'
2
+
3
+ // Generated by scripts/generate-rewriter-targets.js from ./instrumentations. Do not edit by hand.
4
+ const targets = require('./targets.json')
5
+
6
+ const NODE_MODULES = '/node_modules/'
7
+
8
+ /**
9
+ * @typedef {object} RewriteTarget
10
+ * @property {string} moduleName
11
+ * @property {string} filePath
12
+ */
13
+
14
+ /**
15
+ * @param {string} filename
16
+ * @returns {RewriteTarget|undefined}
17
+ */
18
+ function getRewriteTarget (filename) {
19
+ const nodeModulesIndex = filename.lastIndexOf(NODE_MODULES)
20
+ if (nodeModulesIndex === -1) return
21
+
22
+ const modulePath = filename.slice(nodeModulesIndex + NODE_MODULES.length)
23
+ const moduleName = targets[modulePath]
24
+ if (typeof moduleName !== 'string') return
25
+
26
+ return {
27
+ moduleName,
28
+ filePath: modulePath.slice(moduleName.length + 1),
29
+ }
30
+ }
31
+
32
+ module.exports = { getRewriteTarget }
@@ -0,0 +1,62 @@
1
+ {
2
+ "@anthropic-ai/claude-agent-sdk/sdk.mjs": "@anthropic-ai/claude-agent-sdk",
3
+ "@aws/durable-execution-sdk-js/dist-cjs/index.js": "@aws/durable-execution-sdk-js",
4
+ "@aws/durable-execution-sdk-js/dist/index.mjs": "@aws/durable-execution-sdk-js",
5
+ "@azure/cosmos/dist/browser/plugins/Plugin.js": "@azure/cosmos",
6
+ "@azure/cosmos/dist/commonjs/plugins/Plugin.js": "@azure/cosmos",
7
+ "@azure/cosmos/dist/esm/plugins/Plugin.js": "@azure/cosmos",
8
+ "@azure/cosmos/dist/react-native/plugins/Plugin.js": "@azure/cosmos",
9
+ "@graphql-tools/executor/cjs/execution/execute.js": "@graphql-tools/executor",
10
+ "@graphql-tools/executor/cjs/execution/normalizedExecutor.js": "@graphql-tools/executor",
11
+ "@graphql-tools/executor/esm/execution/execute.js": "@graphql-tools/executor",
12
+ "@graphql-tools/executor/esm/execution/normalizedExecutor.js": "@graphql-tools/executor",
13
+ "@langchain/core/dist/embeddings.cjs": "@langchain/core",
14
+ "@langchain/core/dist/embeddings.js": "@langchain/core",
15
+ "@langchain/core/dist/language_models/chat_models.cjs": "@langchain/core",
16
+ "@langchain/core/dist/language_models/chat_models.js": "@langchain/core",
17
+ "@langchain/core/dist/language_models/llms.cjs": "@langchain/core",
18
+ "@langchain/core/dist/language_models/llms.js": "@langchain/core",
19
+ "@langchain/core/dist/runnables/base.cjs": "@langchain/core",
20
+ "@langchain/core/dist/runnables/base.js": "@langchain/core",
21
+ "@langchain/core/dist/tools/index.cjs": "@langchain/core",
22
+ "@langchain/core/dist/tools/index.js": "@langchain/core",
23
+ "@langchain/core/dist/vectorstores.cjs": "@langchain/core",
24
+ "@langchain/core/dist/vectorstores.js": "@langchain/core",
25
+ "@langchain/langgraph/dist/pregel/index.cjs": "@langchain/langgraph",
26
+ "@langchain/langgraph/dist/pregel/index.js": "@langchain/langgraph",
27
+ "@modelcontextprotocol/sdk/dist/cjs/client/index.js": "@modelcontextprotocol/sdk",
28
+ "@modelcontextprotocol/sdk/dist/cjs/server/mcp.js": "@modelcontextprotocol/sdk",
29
+ "@modelcontextprotocol/sdk/dist/esm/client/index.js": "@modelcontextprotocol/sdk",
30
+ "@modelcontextprotocol/sdk/dist/esm/server/mcp.js": "@modelcontextprotocol/sdk",
31
+ "@openai/agents-openai/dist/openaiChatCompletionsModel.js": "@openai/agents-openai",
32
+ "@openai/agents-openai/dist/openaiChatCompletionsModel.mjs": "@openai/agents-openai",
33
+ "@wdio/cli/build/index.js": "@wdio/cli",
34
+ "@wdio/jasmine-framework/build/index.js": "@wdio/jasmine-framework",
35
+ "@wdio/local-runner/build/index.js": "@wdio/local-runner",
36
+ "@wdio/utils/build/index.js": "@wdio/utils",
37
+ "ai/dist/index.js": "ai",
38
+ "ai/dist/index.mjs": "ai",
39
+ "bullmq/dist/cjs/classes/flow-producer.js": "bullmq",
40
+ "bullmq/dist/cjs/classes/queue.js": "bullmq",
41
+ "bullmq/dist/cjs/classes/worker.js": "bullmq",
42
+ "bullmq/dist/esm/classes/flow-producer.js": "bullmq",
43
+ "bullmq/dist/esm/classes/queue.js": "bullmq",
44
+ "bullmq/dist/esm/classes/worker.js": "bullmq",
45
+ "graphql/execution/execute.js": "graphql",
46
+ "graphql/execution/execute.mjs": "graphql",
47
+ "graphql/language/parser.js": "graphql",
48
+ "graphql/language/parser.mjs": "graphql",
49
+ "graphql/language/printer.js": "graphql",
50
+ "graphql/language/printer.mjs": "graphql",
51
+ "graphql/language/visitor.js": "graphql",
52
+ "graphql/language/visitor.mjs": "graphql",
53
+ "graphql/utilities/index.js": "graphql",
54
+ "graphql/utilities/index.mjs": "graphql",
55
+ "graphql/validation/validate.js": "graphql",
56
+ "graphql/validation/validate.mjs": "graphql",
57
+ "jasmine-core/lib/jasmine-core/jasmine.js": "jasmine-core",
58
+ "mercurius/index.js": "mercurius",
59
+ "playwright-core/lib/coreBundle.js": "playwright-core",
60
+ "playwright/lib/index.js": "playwright",
61
+ "playwright/lib/runner/index.js": "playwright"
62
+ }
@@ -14,7 +14,89 @@ const clone = require('../../../../../vendor/dist/rfdc')({ proto: false, circles
14
14
 
15
15
  const { parse, query } = require('./compiler')
16
16
 
17
- module.exports = { waitForAsyncEnd }
17
+ const functionTypes = new Set(['ArrowFunctionExpression', 'FunctionDeclaration', 'FunctionExpression'])
18
+ const identifierPattern = /^[$A-Z_a-z][$\w]*$/
19
+
20
+ module.exports = { awaitContextCallback, waitForAsyncEnd }
21
+
22
+ /**
23
+ * Awaits an optional context callback before continuing through a matched conditional branch.
24
+ *
25
+ * The branch condition is checked again after the callback settles so the
26
+ * original body does not run against state that changed while awaiting.
27
+ *
28
+ * @param {{
29
+ * transformOptions?: {
30
+ * callbackArgumentNames?: string[],
31
+ * callbackName?: string
32
+ * }
33
+ * }} state
34
+ * @param {import('estree').IfStatement} node
35
+ * @param {import('estree').Node} _parent
36
+ * @param {import('estree').Node[]} ancestry
37
+ * @returns {void}
38
+ */
39
+ function awaitContextCallback (state, node, _parent, ancestry) {
40
+ assert(node.type === 'IfStatement' && node.consequent?.type === 'BlockStatement',
41
+ 'awaitContextCallback: expected an if statement with a block body')
42
+
43
+ const { callbackArgumentNames = [], callbackName } = state.transformOptions ?? {}
44
+
45
+ assert(identifierPattern.test(callbackName), 'awaitContextCallback: callbackName must be an identifier')
46
+ assert(callbackArgumentNames.every(name => identifierPattern.test(name)),
47
+ 'awaitContextCallback: callbackArgumentNames must be identifiers')
48
+
49
+ let enclosingFunction
50
+ let hasTraceWrapper = false
51
+ for (const ancestor of ancestry) {
52
+ if (!functionTypes.has(ancestor.type)) continue
53
+
54
+ enclosingFunction ??= ancestor
55
+ if (ancestor.body?.type !== 'BlockStatement') continue
56
+
57
+ let hasContextBinding = false
58
+ let hasTracedBinding = false
59
+ for (const statement of ancestor.body.body) {
60
+ if (statement.type !== 'VariableDeclaration') continue
61
+
62
+ for (const declaration of statement.declarations) {
63
+ hasContextBinding ||= declaration.id?.name === '__apm$ctx'
64
+ hasTracedBinding ||= declaration.id?.name === '__apm$traced'
65
+ }
66
+ }
67
+ hasTraceWrapper ||= hasContextBinding && hasTracedBinding
68
+ }
69
+
70
+ assert(enclosingFunction?.async, 'awaitContextCallback: expected an enclosing async function')
71
+ assert(hasTraceWrapper, 'awaitContextCallback: expected an enclosing trace wrapper')
72
+
73
+ const callbackVariable = `__apm$${callbackName}`
74
+ if (query(node, `[id.name="${callbackVariable}"]`).length > 0) {
75
+ return
76
+ }
77
+
78
+ const originalStatements = node.consequent.body
79
+ const callbackStatements = parse(`
80
+ async function wrapper () {
81
+ const ${callbackVariable} = __apm$ctx.${callbackName};
82
+ if (typeof ${callbackVariable} === 'function') {
83
+ try {
84
+ await ${callbackVariable}(${callbackArgumentNames.join(', ')});
85
+ } catch {}
86
+ if (true) {}
87
+ } else {
88
+ }
89
+ }
90
+ `).body[0].body.body
91
+
92
+ const callbackBranch = callbackStatements[1]
93
+ const recheckedBranch = callbackBranch.consequent.body[1]
94
+ recheckedBranch.test = clone(node.test)
95
+ recheckedBranch.consequent.body.push(...clone(originalStatements))
96
+ recheckedBranch.alternate = clone(node.alternate)
97
+ callbackBranch.alternate.body.push(...originalStatements)
98
+ node.consequent.body = callbackStatements
99
+ }
18
100
 
19
101
  /**
20
102
  * Injects settlement-specific asyncEnd waits into a generated `tracePromise`
@@ -7,10 +7,25 @@ const routerMountPaths = new WeakMap() // to track mount paths for router instan
7
7
  const layerMeta = new WeakMap() // per-layer middleware dispatch metadata (resolved name + route matchers)
8
8
  const appMountedRouters = new WeakSet() // to track routers mounted via app.use()
9
9
 
10
+ /**
11
+ * @typedef {object} LayerMeta
12
+ * @property {string} [name]
13
+ * @property {string} [captureRoute]
14
+ * @property {boolean} [needMultiMatch]
15
+ * @property {Array<{ path?: string, regex?: RegExp }> & {
16
+ * hasStarPath?: boolean,
17
+ * hasSlashPath?: boolean
18
+ * }} [matchers]
19
+ */
20
+
10
21
  const METHODS = [...require('http').METHODS.map(v => v.toLowerCase()), 'all']
11
22
 
12
23
  const routeAddedChannel = channel('apm:express:route:added')
13
24
 
25
+ /**
26
+ * @typedef {{ stack?: Array<{ route?: unknown, handle?: ExpressRouter }> }} ExpressRouter
27
+ */
28
+
14
29
  /**
15
30
  * Joins two URL path segments into a single path
16
31
  *
@@ -57,12 +72,14 @@ function collectRoutesFromRouter (router, prefix) {
57
72
  const fullPaths = getRouteFullPaths(route, prefix)
58
73
 
59
74
  for (const fullPath of fullPaths) {
60
- for (const [method, enabled] of Object.entries(route.methods || {})) {
61
- if (!enabled) continue
62
- routeAddedChannel.publish({
63
- method: normalizeMethodName(method),
64
- path: fullPath,
65
- })
75
+ if (route.methods) {
76
+ for (const [method, enabled] of Object.entries(route.methods)) {
77
+ if (!enabled) continue
78
+ routeAddedChannel.publish({
79
+ method: normalizeMethodName(method),
80
+ path: fullPath,
81
+ })
82
+ }
66
83
  }
67
84
  }
68
85
  } else if (layer.handle?.stack?.length) {
@@ -121,10 +138,19 @@ function getRouterMountPaths (router) {
121
138
  return [...paths]
122
139
  }
123
140
 
141
+ /**
142
+ * @param {object} layer
143
+ * @param {LayerMeta} meta
144
+ * @returns {void}
145
+ */
124
146
  function setLayerMeta (layer, meta) {
125
147
  layerMeta.set(layer, meta)
126
148
  }
127
149
 
150
+ /**
151
+ * @param {object} layer
152
+ * @returns {LayerMeta | undefined}
153
+ */
128
154
  function getLayerMeta (layer) {
129
155
  return layerMeta.get(layer)
130
156
  }
@@ -157,6 +183,8 @@ function isAppMounted (router) {
157
183
  * Express accepts strings, regex, arrays (possibly nested), or
158
184
  * no mount path at all; this helper returns the flattened set of paths along
159
185
  * with the index where actual middleware arguments start.
186
+ *
187
+ * @param {unknown} path First `use()` argument, which may be a mount path or already a middleware.
160
188
  */
161
189
  function extractMountPaths (path) {
162
190
  const hasMount = typeof path === 'string' || path instanceof RegExp || Array.isArray(path)
@@ -174,6 +202,9 @@ function extractMountPaths (path) {
174
202
 
175
203
  /**
176
204
  * Detect cycle router graphs.
205
+ *
206
+ * @param {ExpressRouter | undefined} router
207
+ * @param {Set<ExpressRouter>} [stack]
177
208
  */
178
209
  function hasRouterCycle (router, stack = new Set()) {
179
210
  if (!router?.stack?.length) return false
@@ -14,7 +14,7 @@ const TRANSFORM_OPTIONS = {
14
14
 
15
15
  function getCoverageBackfillFiles (skippableSuitesCoverage, rootDir, getTestSuitePath) {
16
16
  const files = []
17
- for (const filename of Object.keys(skippableSuitesCoverage || {})) {
17
+ for (const filename of Object.keys(skippableSuitesCoverage)) {
18
18
  const relativeFilename = path.isAbsolute(filename)
19
19
  ? getTestSuitePath(filename, rootDir)
20
20
  : filename