dd-trace 5.79.0 → 5.81.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 (242) hide show
  1. package/LICENSE-3rdparty.csv +79 -87
  2. package/ext/tags.d.ts +1 -0
  3. package/ext/tags.js +1 -0
  4. package/index.d.ts +46 -39
  5. package/initialize.mjs +10 -10
  6. package/loader-hook.mjs +10 -3
  7. package/package.json +23 -40
  8. package/packages/datadog-core/src/storage.js +4 -4
  9. package/packages/datadog-esbuild/index.js +36 -19
  10. package/packages/datadog-esbuild/src/utils.js +5 -1
  11. package/packages/datadog-instrumentations/index.js +1 -0
  12. package/packages/datadog-instrumentations/src/anthropic.js +12 -0
  13. package/packages/datadog-instrumentations/src/aws-sdk.js +13 -2
  14. package/packages/datadog-instrumentations/src/azure-service-bus.js +43 -36
  15. package/packages/datadog-instrumentations/src/cucumber.js +2 -2
  16. package/packages/datadog-instrumentations/src/find-my-way.js +6 -5
  17. package/packages/datadog-instrumentations/src/google-genai.js +120 -0
  18. package/packages/datadog-instrumentations/src/graphql.js +20 -0
  19. package/packages/datadog-instrumentations/src/helpers/hook.js +1 -0
  20. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
  21. package/packages/datadog-instrumentations/src/helpers/instrument.js +12 -1
  22. package/packages/datadog-instrumentations/src/helpers/register.js +6 -1
  23. package/packages/datadog-instrumentations/src/helpers/rewriter/compiler.js +27 -0
  24. package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +152 -0
  25. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +5 -0
  26. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/langchain.js +237 -0
  27. package/packages/datadog-instrumentations/src/helpers/rewriter/loader.js +9 -0
  28. package/packages/datadog-instrumentations/src/helpers/rewriter/loader.mjs +11 -0
  29. package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +139 -0
  30. package/packages/datadog-instrumentations/src/jest.js +1 -1
  31. package/packages/datadog-instrumentations/src/langchain.js +3 -109
  32. package/packages/datadog-instrumentations/src/mocha/main.js +1 -1
  33. package/packages/datadog-instrumentations/src/mysql2.js +1 -1
  34. package/packages/datadog-instrumentations/src/playwright.js +65 -16
  35. package/packages/datadog-instrumentations/src/router.js +1 -1
  36. package/packages/datadog-instrumentations/src/selenium.js +3 -1
  37. package/packages/datadog-instrumentations/src/ws.js +35 -17
  38. package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +3 -2
  39. package/packages/datadog-plugin-azure-service-bus/src/producer.js +14 -5
  40. package/packages/datadog-plugin-child_process/src/scrub-cmd-params.js +1 -1
  41. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +23 -2
  42. package/packages/datadog-plugin-cypress/src/plugin.js +1 -1
  43. package/packages/datadog-plugin-cypress/src/support.js +73 -31
  44. package/packages/datadog-plugin-google-genai/src/index.js +17 -0
  45. package/packages/datadog-plugin-google-genai/src/tracing.js +41 -0
  46. package/packages/datadog-plugin-graphql/src/tools/transforms.js +5 -4
  47. package/packages/datadog-plugin-jest/src/util.js +4 -3
  48. package/packages/datadog-plugin-kafkajs/src/consumer.js +2 -1
  49. package/packages/datadog-plugin-kafkajs/src/producer.js +3 -1
  50. package/packages/datadog-plugin-langchain/src/tracing.js +7 -3
  51. package/packages/datadog-plugin-next/src/index.js +11 -3
  52. package/packages/datadog-plugin-openai/src/stream-helpers.js +1 -1
  53. package/packages/datadog-shimmer/src/shimmer.js +2 -2
  54. package/packages/dd-trace/src/aiguard/sdk.js +29 -14
  55. package/packages/dd-trace/src/appsec/api_security_sampler.js +1 -1
  56. package/packages/dd-trace/src/appsec/iast/overhead-controller.js +1 -1
  57. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter-esm.mjs +1 -1
  58. package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +1 -2
  59. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +1 -1
  60. package/packages/dd-trace/src/appsec/reporter.js +0 -4
  61. package/packages/dd-trace/src/baggage.js +11 -0
  62. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +4 -8
  63. package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +1 -1
  64. package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +4 -2
  65. package/packages/dd-trace/src/config.js +81 -7
  66. package/packages/dd-trace/src/config_defaults.js +15 -2
  67. package/packages/dd-trace/src/datastreams/encoding.js +23 -6
  68. package/packages/dd-trace/src/datastreams/pathway.js +40 -1
  69. package/packages/dd-trace/src/datastreams/processor.js +1 -1
  70. package/packages/dd-trace/src/datastreams/schemas/schema_builder.js +1 -1
  71. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +15 -5
  72. package/packages/dd-trace/src/debugger/devtools_client/condition.js +1 -1
  73. package/packages/dd-trace/src/debugger/devtools_client/config.js +2 -0
  74. package/packages/dd-trace/src/debugger/devtools_client/index.js +30 -15
  75. package/packages/dd-trace/src/debugger/devtools_client/inspector_promises_polyfill.js +2 -0
  76. package/packages/dd-trace/src/debugger/devtools_client/json-buffer.js +24 -18
  77. package/packages/dd-trace/src/debugger/devtools_client/send.js +18 -8
  78. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +103 -15
  79. package/packages/dd-trace/src/debugger/devtools_client/snapshot/constants.js +25 -0
  80. package/packages/dd-trace/src/debugger/devtools_client/snapshot/index.js +56 -25
  81. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +64 -23
  82. package/packages/dd-trace/src/debugger/devtools_client/snapshot/symbols.js +3 -1
  83. package/packages/dd-trace/src/debugger/devtools_client/snapshot-pruner.js +404 -0
  84. package/packages/dd-trace/src/debugger/devtools_client/source-maps.js +1 -1
  85. package/packages/dd-trace/src/debugger/devtools_client/state.js +7 -2
  86. package/packages/dd-trace/src/debugger/devtools_client/status.js +1 -1
  87. package/packages/dd-trace/src/debugger/index.js +1 -1
  88. package/packages/dd-trace/src/encode/0.4.js +3 -3
  89. package/packages/dd-trace/src/encode/coverage-ci-visibility.js +2 -2
  90. package/packages/dd-trace/src/encode/span-stats.js +7 -1
  91. package/packages/dd-trace/src/exporters/agent/writer.js +6 -13
  92. package/packages/dd-trace/src/histogram.js +1 -1
  93. package/packages/dd-trace/src/id.js +60 -0
  94. package/packages/dd-trace/src/lambda/runtime/ritm.js +2 -3
  95. package/packages/dd-trace/src/llmobs/constants/tags.js +1 -0
  96. package/packages/dd-trace/src/llmobs/index.js +5 -5
  97. package/packages/dd-trace/src/llmobs/noop.js +6 -0
  98. package/packages/dd-trace/src/llmobs/plugins/ai/index.js +1 -0
  99. package/packages/dd-trace/src/llmobs/plugins/genai/index.js +104 -0
  100. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +486 -0
  101. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +2 -2
  102. package/packages/dd-trace/src/llmobs/plugins/{openai.js → openai/index.js} +87 -39
  103. package/packages/dd-trace/src/llmobs/plugins/openai/utils.js +114 -0
  104. package/packages/dd-trace/src/llmobs/sdk.js +10 -1
  105. package/packages/dd-trace/src/llmobs/span_processor.js +11 -6
  106. package/packages/dd-trace/src/llmobs/tagger.js +35 -17
  107. package/packages/dd-trace/src/msgpack/chunk.js +2 -2
  108. package/packages/dd-trace/src/msgpack/encoder.js +2 -3
  109. package/packages/dd-trace/src/msgpack/index.js +2 -2
  110. package/packages/dd-trace/src/openfeature/flagging_provider.js +5 -3
  111. package/packages/dd-trace/src/opentelemetry/logs/index.js +3 -3
  112. package/packages/dd-trace/src/opentelemetry/logs/logger.js +14 -8
  113. package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +6 -4
  114. package/packages/dd-trace/src/opentelemetry/logs/otlp_transformer.js +9 -17
  115. package/packages/dd-trace/src/opentelemetry/metrics/constants.js +34 -0
  116. package/packages/dd-trace/src/opentelemetry/metrics/index.js +81 -0
  117. package/packages/dd-trace/src/opentelemetry/metrics/instruments.js +225 -0
  118. package/packages/dd-trace/src/opentelemetry/metrics/meter.js +171 -0
  119. package/packages/dd-trace/src/opentelemetry/metrics/meter_provider.js +54 -0
  120. package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +62 -0
  121. package/packages/dd-trace/src/opentelemetry/metrics/otlp_transformer.js +251 -0
  122. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +532 -0
  123. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +10 -18
  124. package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +36 -22
  125. package/packages/dd-trace/src/opentelemetry/otlp/protobuf_loader.js +2 -2
  126. package/packages/dd-trace/src/opentelemetry/span.js +1 -1
  127. package/packages/dd-trace/src/opentelemetry/tracer.js +1 -1
  128. package/packages/dd-trace/src/opentelemetry/tracer_provider.js +1 -1
  129. package/packages/dd-trace/src/payload-tagging/index.js +2 -2
  130. package/packages/dd-trace/src/plugin_manager.js +4 -2
  131. package/packages/dd-trace/src/plugins/database.js +1 -0
  132. package/packages/dd-trace/src/plugins/index.js +1 -0
  133. package/packages/dd-trace/src/plugins/plugin.js +7 -9
  134. package/packages/dd-trace/src/plugins/util/test.js +3 -3
  135. package/packages/dd-trace/src/plugins/util/url.js +119 -1
  136. package/packages/dd-trace/src/plugins/util/web.js +10 -41
  137. package/packages/dd-trace/src/process-tags/index.js +81 -0
  138. package/packages/dd-trace/src/profiling/config.js +1 -1
  139. package/packages/dd-trace/src/profiling/exporter_cli.js +7 -6
  140. package/packages/dd-trace/src/profiling/exporters/agent.js +1 -1
  141. package/packages/dd-trace/src/profiling/profilers/events.js +10 -1
  142. package/packages/dd-trace/src/proxy.js +5 -0
  143. package/packages/dd-trace/src/rate_limiter.js +1 -1
  144. package/packages/dd-trace/src/remote_config/manager.js +1 -1
  145. package/packages/dd-trace/src/require-package-json.js +1 -1
  146. package/packages/dd-trace/src/ritm.js +1 -1
  147. package/packages/dd-trace/src/service-naming/index.js +31 -4
  148. package/packages/dd-trace/src/service-naming/schemas/v0/web.js +4 -0
  149. package/packages/dd-trace/src/service-naming/schemas/v1/web.js +4 -0
  150. package/packages/dd-trace/src/{format.js → span_format.js} +9 -4
  151. package/packages/dd-trace/src/span_processor.js +16 -11
  152. package/packages/dd-trace/src/span_stats.js +15 -4
  153. package/packages/dd-trace/src/spanleak.js +1 -1
  154. package/packages/dd-trace/src/supported-configurations.json +13 -0
  155. package/packages/dd-trace/src/telemetry/dependencies.js +1 -1
  156. package/packages/dd-trace/src/telemetry/telemetry.js +11 -2
  157. package/vendor/dist/@datadog/sketches-js/LICENSE +39 -0
  158. package/vendor/dist/@datadog/sketches-js/index.js +1 -0
  159. package/vendor/dist/@datadog/source-map/LICENSE +28 -0
  160. package/vendor/dist/@datadog/source-map/index.js +1 -0
  161. package/vendor/dist/@isaacs/ttlcache/LICENSE +55 -0
  162. package/vendor/dist/@isaacs/ttlcache/index.js +1 -0
  163. package/vendor/dist/@opentelemetry/core/LICENSE +201 -0
  164. package/vendor/dist/@opentelemetry/core/index.js +1 -0
  165. package/vendor/dist/@opentelemetry/resources/LICENSE +201 -0
  166. package/vendor/dist/@opentelemetry/resources/index.js +1 -0
  167. package/vendor/dist/astring/LICENSE +19 -0
  168. package/vendor/dist/astring/index.js +1 -0
  169. package/vendor/dist/crypto-randomuuid/index.js +1 -0
  170. package/vendor/dist/escape-string-regexp/LICENSE +9 -0
  171. package/vendor/dist/escape-string-regexp/index.js +1 -0
  172. package/vendor/dist/esquery/LICENSE +24 -0
  173. package/vendor/dist/esquery/index.js +1 -0
  174. package/vendor/dist/ignore/LICENSE +21 -0
  175. package/vendor/dist/ignore/index.js +1 -0
  176. package/vendor/dist/istanbul-lib-coverage/LICENSE +24 -0
  177. package/vendor/dist/istanbul-lib-coverage/index.js +1 -0
  178. package/vendor/dist/jest-docblock/LICENSE +21 -0
  179. package/vendor/dist/jest-docblock/index.js +1 -0
  180. package/vendor/dist/jsonpath-plus/LICENSE +22 -0
  181. package/vendor/dist/jsonpath-plus/index.js +1 -0
  182. package/vendor/dist/limiter/LICENSE +19 -0
  183. package/vendor/dist/limiter/index.js +1 -0
  184. package/vendor/dist/lodash.sortby/LICENSE +47 -0
  185. package/vendor/dist/lodash.sortby/index.js +1 -0
  186. package/vendor/dist/lru-cache/LICENSE +15 -0
  187. package/vendor/dist/lru-cache/index.js +1 -0
  188. package/vendor/dist/meriyah/LICENSE +7 -0
  189. package/vendor/dist/meriyah/index.js +1 -0
  190. package/vendor/dist/module-details-from-path/LICENSE +21 -0
  191. package/vendor/dist/module-details-from-path/index.js +1 -0
  192. package/vendor/dist/mutexify/promise/LICENSE +21 -0
  193. package/vendor/dist/mutexify/promise/index.js +1 -0
  194. package/vendor/dist/opentracing/LICENSE +201 -0
  195. package/vendor/dist/opentracing/binary_carrier.d.ts +11 -0
  196. package/vendor/dist/opentracing/constants.d.ts +61 -0
  197. package/vendor/dist/opentracing/examples/demo/demo.d.ts +2 -0
  198. package/vendor/dist/opentracing/ext/tags.d.ts +90 -0
  199. package/vendor/dist/opentracing/functions.d.ts +20 -0
  200. package/vendor/dist/opentracing/global_tracer.d.ts +14 -0
  201. package/vendor/dist/opentracing/index.d.ts +12 -0
  202. package/vendor/dist/opentracing/index.js +1 -0
  203. package/vendor/dist/opentracing/mock_tracer/index.d.ts +5 -0
  204. package/vendor/dist/opentracing/mock_tracer/mock_context.d.ts +13 -0
  205. package/vendor/dist/opentracing/mock_tracer/mock_report.d.ts +16 -0
  206. package/vendor/dist/opentracing/mock_tracer/mock_span.d.ts +50 -0
  207. package/vendor/dist/opentracing/mock_tracer/mock_tracer.d.ts +26 -0
  208. package/vendor/dist/opentracing/noop.d.ts +8 -0
  209. package/vendor/dist/opentracing/reference.d.ts +33 -0
  210. package/vendor/dist/opentracing/span.d.ts +147 -0
  211. package/vendor/dist/opentracing/span_context.d.ts +26 -0
  212. package/vendor/dist/opentracing/test/api_compatibility.d.ts +16 -0
  213. package/vendor/dist/opentracing/test/mocktracer_implemenation.d.ts +3 -0
  214. package/vendor/dist/opentracing/test/noop_implementation.d.ts +4 -0
  215. package/vendor/dist/opentracing/test/opentracing_api.d.ts +3 -0
  216. package/vendor/dist/opentracing/test/unittest.d.ts +2 -0
  217. package/vendor/dist/opentracing/tracer.d.ts +127 -0
  218. package/vendor/dist/path-to-regexp/LICENSE +21 -0
  219. package/vendor/dist/path-to-regexp/index.js +1 -0
  220. package/vendor/dist/pprof-format/LICENSE +8 -0
  221. package/vendor/dist/pprof-format/index.js +1 -0
  222. package/vendor/dist/protobufjs/LICENSE +39 -0
  223. package/vendor/dist/protobufjs/index.js +1 -0
  224. package/vendor/dist/protobufjs/minimal/LICENSE +39 -0
  225. package/vendor/dist/protobufjs/minimal/index.js +1 -0
  226. package/vendor/dist/retry/LICENSE +21 -0
  227. package/vendor/dist/retry/index.js +1 -0
  228. package/vendor/dist/rfdc/LICENSE +15 -0
  229. package/vendor/dist/rfdc/index.js +1 -0
  230. package/vendor/dist/semifies/LICENSE +201 -0
  231. package/vendor/dist/semifies/index.js +1 -0
  232. package/vendor/dist/shell-quote/LICENSE +24 -0
  233. package/vendor/dist/shell-quote/index.js +1 -0
  234. package/vendor/dist/source-map/LICENSE +28 -0
  235. package/vendor/dist/source-map/index.js +1 -0
  236. package/vendor/dist/source-map/lib/util/LICENSE +28 -0
  237. package/vendor/dist/source-map/lib/util/index.js +1 -0
  238. package/vendor/dist/source-map/mappings.wasm +0 -0
  239. package/vendor/dist/tlhunter-sorted-set/LICENSE +21 -0
  240. package/vendor/dist/tlhunter-sorted-set/index.js +1 -0
  241. package/vendor/dist/ttl-set/LICENSE +21 -0
  242. package/vendor/dist/ttl-set/index.js +1 -0
@@ -245,28 +245,45 @@ ${build.initialOptions.banner.js}`
245
245
  }
246
246
  }
247
247
 
248
- const packageJson = JSON.parse(fs.readFileSync(pathToPackageJson).toString())
248
+ try {
249
+ const packageJson = JSON.parse(fs.readFileSync(pathToPackageJson).toString())
249
250
 
250
- const isESM = isESMFile(fullPathToModule, pathToPackageJson, packageJson)
251
- if (isESM && !interceptedESMModules.has(fullPathToModule)) {
252
- fullPathToModule += ESM_INTERCEPTED_SUFFIX
253
- }
251
+ const isESM = isESMFile(fullPathToModule, pathToPackageJson, packageJson)
252
+ if (isESM && !interceptedESMModules.has(fullPathToModule)) {
253
+ fullPathToModule += ESM_INTERCEPTED_SUFFIX
254
+ }
254
255
 
255
- if (DEBUG) console.log(`RESOLVE: ${args.path}@${packageJson.version}`)
256
+ if (DEBUG) console.log(`RESOLVE: ${args.path}@${packageJson.version}`)
256
257
 
257
- // https://esbuild.github.io/plugins/#on-resolve-arguments
258
- return {
259
- path: fullPathToModule,
260
- pluginData: {
261
- version: packageJson.version,
262
- pkg: extracted.pkg,
263
- path: extracted.path,
264
- full: fullPathToModule,
265
- raw: args.path,
266
- pkgOfInterest: true,
267
- kind: args.kind,
268
- internal,
269
- isESM
258
+ // https://esbuild.github.io/plugins/#on-resolve-arguments
259
+ return {
260
+ path: fullPathToModule,
261
+ pluginData: {
262
+ version: packageJson.version,
263
+ pkg: extracted.pkg,
264
+ path: extracted.path,
265
+ full: fullPathToModule,
266
+ raw: args.path,
267
+ pkgOfInterest: true,
268
+ kind: args.kind,
269
+ internal,
270
+ isESM
271
+ }
272
+ }
273
+ } catch (e) {
274
+ // Skip vendored dependencies which never have a `package.json`. This
275
+ // will use the default resolve logic of ESBuild which is what we want
276
+ // since those files should be treated as regular files and not modules
277
+ // even though they are in a `node_modules` folder.
278
+ if (e.code === 'ENOENT') {
279
+ if (DEBUG) {
280
+ console.log([
281
+ 'Skipping `package.json` lookup.',
282
+ 'This usually means the package was vendored but could indicate an issue otherwise.'
283
+ ].join(' '))
284
+ }
285
+ } else {
286
+ throw e
270
287
  }
271
288
  }
272
289
  }
@@ -65,7 +65,11 @@ function getSource (url, { format }) {
65
65
  /**
66
66
  * Generates the pieces of code for the proxy module before the path
67
67
  *
68
- * @param {Object} moduleData { path, internal, context, excludeDefault }
68
+ * @param {object} moduleData
69
+ * @param {string} moduleData.path
70
+ * @param {boolean} moduleData.internal
71
+ * @param {object} moduleData.context
72
+ * @param {boolean} moduleData.excludeDefault
69
73
  * @returns {Promise<Map>}
70
74
  */
71
75
  async function processModule ({ path, internal, context, excludeDefault }) {
@@ -2,3 +2,4 @@
2
2
 
3
3
  require('./src/helpers/bundler-register')
4
4
  require('./src/helpers/register')
5
+ require('./src/helpers/rewriter/loader')
@@ -112,4 +112,16 @@ for (const extension of extensions) {
112
112
 
113
113
  return exports
114
114
  })
115
+
116
+ addHook({
117
+ name: '@anthropic-ai/sdk',
118
+ file: `resources/beta/messages/messages.${extension}`,
119
+ versions: ['>=0.33.0']
120
+ }, exports => {
121
+ const Messages = exports.Messages
122
+
123
+ shimmer.wrap(Messages.prototype, 'create', wrapCreate)
124
+
125
+ return exports
126
+ })
115
127
  }
@@ -3,6 +3,8 @@
3
3
  const { channel, addHook } = require('./helpers/instrument')
4
4
  const shimmer = require('../../datadog-shimmer')
5
5
 
6
+ const patchedClientConfigProtocols = new WeakSet()
7
+
6
8
  function wrapRequest (send) {
7
9
  return function wrappedRequest (cb) {
8
10
  if (!this.service) return send.apply(this, arguments)
@@ -34,10 +36,11 @@ function wrapRequest (send) {
34
36
  }
35
37
  }
36
38
 
37
- function wrapDeserialize (deserialize, channelSuffix) {
39
+ function wrapDeserialize (deserialize, channelSuffix, responseIndex = 0) {
38
40
  const headersCh = channel(`apm:aws:response:deserialize:${channelSuffix}`)
39
41
 
40
- return function (response) {
42
+ return function () {
43
+ const response = arguments[responseIndex]
41
44
  if (headersCh.hasSubscribers) {
42
45
  headersCh.publish({ headers: response.headers })
43
46
  }
@@ -66,6 +69,14 @@ function wrapSmithySend (send) {
66
69
 
67
70
  if (typeof command.deserialize === 'function') {
68
71
  shimmer.wrap(command, 'deserialize', deserialize => wrapDeserialize(deserialize, channelSuffix))
72
+ } else if (this.config?.protocol?.deserializeResponse && !patchedClientConfigProtocols.has(this.config.protocol)) {
73
+ shimmer.wrap(
74
+ this.config.protocol,
75
+ 'deserializeResponse',
76
+ deserializeResponse => wrapDeserialize(deserializeResponse, channelSuffix, 2)
77
+ )
78
+
79
+ patchedClientConfigProtocols.add(this.config.protocol)
69
80
  }
70
81
 
71
82
  const ctx = {
@@ -8,57 +8,64 @@ const shimmer = require('../../datadog-shimmer')
8
8
  const dc = require('dc-polyfill')
9
9
 
10
10
  const producerCh = dc.tracingChannel('apm:azure-service-bus:send')
11
+ const isItDefault = new WeakSet()
11
12
 
12
- addHook({ name: '@azure/service-bus', versions: ['>=7.9.2'], patchDefault: false }, (obj) => {
13
+ addHook({ name: '@azure/service-bus', versions: ['>=7.9.2'] }, (obj) => {
13
14
  const ServiceBusClient = obj.ServiceBusClient
14
- let didItShim = false
15
15
  shimmer.wrap(ServiceBusClient.prototype, 'createSender',
16
16
  createSender => function (queueOrTopicName) {
17
17
  const sender = createSender.apply(this, arguments)
18
- if (didItShim) return sender
19
18
  const senderPrototype = sender.constructor.prototype
20
19
  const senderSenderPrototype = sender._sender.constructor.prototype
21
- shimmer.wrap(senderPrototype, 'scheduleMessages', scheduleMessages =>
22
- function (msg, scheduledEnqueueTimeUtc) {
23
- const functionName = scheduleMessages.name
20
+
21
+ if (!isItDefault.has(senderPrototype)) {
22
+ isItDefault.add(senderPrototype)
23
+
24
+ shimmer.wrap(senderPrototype, 'scheduleMessages', scheduleMessages =>
25
+ function (msg, scheduledEnqueueTimeUtc) {
26
+ const functionName = scheduleMessages.name
27
+ const config = this._context.config
28
+ const entityPath = this._entityPath
29
+ return producerCh.tracePromise(
30
+ scheduleMessages,
31
+ { config, entityPath, functionName, msg, scheduledEnqueueTimeUtc },
32
+ this, ...arguments
33
+ )
34
+ })
35
+
36
+ shimmer.wrap(senderPrototype, 'createMessageBatch', createMessageBatch => async function () {
37
+ const batch = await createMessageBatch.apply(this, arguments)
38
+ shimmer.wrap(batch, 'tryAddMessage', tryAddMessage => function (msg) {
39
+ const functionName = tryAddMessage.name
40
+ const config = this._context.config
41
+ return producerCh.tracePromise(
42
+ tryAddMessage, { config, functionName, batch, msg }, this, ...arguments)
43
+ })
44
+ return batch
45
+ })
46
+ }
47
+
48
+ if (!isItDefault.has(senderSenderPrototype)) {
49
+ isItDefault.add(senderSenderPrototype)
50
+
51
+ shimmer.wrap(senderSenderPrototype, 'send', send => function (msg) {
52
+ const functionName = send.name
24
53
  const config = this._context.config
25
- const entityPath = this._entityPath
54
+ const entityPath = this.entityPath
26
55
  return producerCh.tracePromise(
27
- scheduleMessages,
28
- { config, entityPath, functionName, msg, scheduledEnqueueTimeUtc },
29
- this, ...arguments
56
+ send, { config, entityPath, functionName, msg }, this, ...arguments
30
57
  )
31
58
  })
32
59
 
33
- shimmer.wrap(senderPrototype, 'createMessageBatch', createMessageBatch => async function () {
34
- const batch = await createMessageBatch.apply(this, arguments)
35
- shimmer.wrap(batch.constructor.prototype, 'tryAddMessage', tryAddMessage => function (msg) {
36
- const functionName = tryAddMessage.name
60
+ shimmer.wrap(senderSenderPrototype, 'sendBatch', sendBatch => function (msg) {
61
+ const functionName = sendBatch.name
37
62
  const config = this._context.config
63
+ const entityPath = this.entityPath
38
64
  return producerCh.tracePromise(
39
- tryAddMessage, { config, functionName, batch, msg }, this, ...arguments)
65
+ sendBatch, { config, entityPath, functionName, msg }, this, ...arguments
66
+ )
40
67
  })
41
- return batch
42
- })
43
-
44
- shimmer.wrap(senderSenderPrototype, 'send', send => function (msg) {
45
- const functionName = send.name
46
- const config = this._context.config
47
- const entityPath = this.entityPath
48
- return producerCh.tracePromise(
49
- send, { config, entityPath, functionName, msg }, this, ...arguments
50
- )
51
- })
52
-
53
- shimmer.wrap(senderSenderPrototype, 'sendBatch', sendBatch => function (msg) {
54
- const functionName = sendBatch.name
55
- const config = this._context.config
56
- const entityPath = this.entityPath
57
- return producerCh.tracePromise(
58
- sendBatch, { config, entityPath, functionName, msg }, this, ...arguments
59
- )
60
- })
61
- didItShim = true
68
+ }
62
69
  return sender
63
70
  })
64
71
  return obj
@@ -1,5 +1,5 @@
1
1
  'use strict'
2
- const { createCoverageMap } = require('istanbul-lib-coverage')
2
+ const { createCoverageMap } = require('../../../vendor/dist/istanbul-lib-coverage')
3
3
 
4
4
  const { addHook, channel } = require('./helpers/instrument')
5
5
  const shimmer = require('../../datadog-shimmer')
@@ -43,7 +43,7 @@ const {
43
43
  CUCUMBER_WORKER_TRACE_PAYLOAD_CODE,
44
44
  getIsFaultyEarlyFlakeDetection
45
45
  } = require('../../dd-trace/src/plugins/util/test')
46
- const satisfies = require('semifies')
46
+ const satisfies = require('../../../vendor/dist/semifies')
47
47
 
48
48
  const isMarkedAsUnskippable = (pickle) => {
49
49
  return pickle.tags.some(tag => tag.name === '@datadog:unskippable')
@@ -9,13 +9,13 @@ function wrapOn (on) {
9
9
  return function onWithTrace (method, path, opts) {
10
10
  const index = typeof opts === 'function' ? 2 : 3
11
11
  const handler = arguments[index]
12
- const wrapper = shimmer.wrapFunction(handler, handler => function (req) {
13
- routeChannel.publish({ req, route: path })
14
-
15
- return handler.apply(this, arguments)
16
- })
17
12
 
18
13
  if (typeof handler === 'function') {
14
+ const wrapper = shimmer.wrapFunction(handler, handler => function (req) {
15
+ routeChannel.publish({ req, route: path })
16
+
17
+ return handler.apply(this, arguments)
18
+ })
19
19
  arguments[index] = wrapper
20
20
  }
21
21
 
@@ -24,6 +24,7 @@ function wrapOn (on) {
24
24
  }
25
25
 
26
26
  addHook({ name: 'find-my-way', versions: ['>=1'] }, Router => {
27
+ // No need to wrap the off method as it would not contain the handler function.
27
28
  shimmer.wrap(Router.prototype, 'on', wrapOn)
28
29
 
29
30
  return Router
@@ -0,0 +1,120 @@
1
+ 'use strict'
2
+
3
+ const { addHook } = require('./helpers/instrument')
4
+ const shimmer = require('../../datadog-shimmer')
5
+ const tracingChannel = require('dc-polyfill').tracingChannel
6
+ const channel = require('dc-polyfill').channel
7
+
8
+ const genaiTracingChannel = tracingChannel('apm:google:genai:request')
9
+ const onStreamedChunkCh = channel('apm:google:genai:request:chunk')
10
+
11
+ function wrapGenerateContent (method) {
12
+ return function wrappedGenerateContent (original) {
13
+ return function (...args) {
14
+ if (!genaiTracingChannel.start.hasSubscribers) {
15
+ return original.apply(this, args)
16
+ }
17
+
18
+ const normalizedName = normalizeMethodName(method)
19
+
20
+ const ctx = { args, methodName: normalizedName }
21
+
22
+ return genaiTracingChannel.start.runStores(ctx, () => {
23
+ let result
24
+ try {
25
+ result = original.apply(this, arguments)
26
+ } catch (error) {
27
+ finish(ctx, null, error)
28
+ throw error
29
+ } finally {
30
+ genaiTracingChannel.end.publish(ctx)
31
+ }
32
+ return result.then(response => {
33
+ if (response[Symbol.asyncIterator]) {
34
+ shimmer.wrap(response, Symbol.asyncIterator, iterator => wrapStreamIterator(iterator, ctx))
35
+ } else {
36
+ finish(ctx, response, null)
37
+ }
38
+ return response
39
+ }).catch(error => {
40
+ finish(ctx, null, error)
41
+ throw error
42
+ })
43
+ })
44
+ }
45
+ }
46
+ }
47
+
48
+ function wrapStreamIterator (iterator, ctx) {
49
+ return function () {
50
+ const itr = iterator.apply(this, arguments)
51
+ shimmer.wrap(itr, 'next', next => function () {
52
+ return next.apply(this, arguments)
53
+ .then(res => {
54
+ const { done, value: chunk } = res
55
+ onStreamedChunkCh.publish({ ctx, chunk, done })
56
+
57
+ if (done) {
58
+ finish(ctx)
59
+ }
60
+
61
+ return res
62
+ })
63
+ .catch(error => {
64
+ finish(ctx, null, error)
65
+ throw error
66
+ })
67
+ })
68
+
69
+ return itr
70
+ }
71
+ }
72
+ function finish (ctx, result, error) {
73
+ if (error) {
74
+ ctx.error = error
75
+ genaiTracingChannel.error.publish(ctx)
76
+ }
77
+
78
+ // streamed responses are handled and set separately
79
+ ctx.result ??= result
80
+
81
+ genaiTracingChannel.asyncEnd.publish(ctx)
82
+ }
83
+ // Hook the main package entry point
84
+ addHook({
85
+ name: '@google/genai',
86
+ versions: ['>=1.19.0']
87
+ }, exports => {
88
+ // Wrap GoogleGenAI to intercept when it creates Models instances
89
+ if (!exports.GoogleGenAI) return exports
90
+
91
+ shimmer.wrap(exports, 'GoogleGenAI', GoogleGenAI => {
92
+ return class extends GoogleGenAI {
93
+ constructor (...args) {
94
+ super(...args)
95
+
96
+ // We are patching the instance instead of the prototype because when it is compiled from
97
+ // typescript, the models property is not available on the prototype.
98
+ if (this.models) {
99
+ if (this.models.generateContent) {
100
+ shimmer.wrap(this.models, 'generateContent', wrapGenerateContent('generateContent'))
101
+ }
102
+ if (this.models.generateContentStream) {
103
+ shimmer.wrap(this.models, 'generateContentStream', wrapGenerateContent('generateContentStream'))
104
+ }
105
+ if (this.models.embedContent) {
106
+ shimmer.wrap(this.models, 'embedContent', wrapGenerateContent('embedContent'))
107
+ }
108
+ }
109
+ }
110
+ }
111
+ })
112
+ return exports
113
+ })
114
+
115
+ function normalizeMethodName (methodName) {
116
+ // Convert camelCase to snake_case and add Models prefix
117
+ return 'Models.' + methodName
118
+ .replaceAll(/([a-z0-9])([A-Z])/g, '$1_$2')
119
+ .toLowerCase()
120
+ }
@@ -6,6 +6,8 @@ const {
6
6
  } = require('./helpers/instrument')
7
7
  const shimmer = require('../../datadog-shimmer')
8
8
 
9
+ const ddGlobal = globalThis[Symbol.for('dd-trace')] ??= {}
10
+
9
11
  /** cached objects */
10
12
 
11
13
  const contexts = new WeakMap()
@@ -360,3 +362,21 @@ addHook({ name: 'graphql', file: 'validation/validate.js', versions: ['>=0.10']
360
362
 
361
363
  return validate
362
364
  })
365
+
366
+ addHook({ name: 'graphql', file: 'language/printer.js', versions: ['>=0.10'] }, printer => {
367
+ // HACK: It's possible `graphql` is loaded before `@apollo/gateway` so we
368
+ // can't use a channel as the latter plugin would load after the publish
369
+ // happened. Not sure how to handle this so for now use a global.
370
+ ddGlobal.graphql_printer = printer
371
+ return printer
372
+ })
373
+
374
+ addHook({ name: 'graphql', file: 'language/visitor.js', versions: ['>=0.10'] }, visitor => {
375
+ ddGlobal.graphql_visitor = visitor
376
+ return visitor
377
+ })
378
+
379
+ addHook({ name: 'graphql', file: 'utilities/index.js', versions: ['>=0.10'] }, utilities => {
380
+ ddGlobal.graphql_utilities = utilities
381
+ return utilities
382
+ })
@@ -8,6 +8,7 @@ const ritm = require('../../../dd-trace/src/ritm')
8
8
  * In practice, `modules` is always an array with a single entry.
9
9
  *
10
10
  * @param {string[]} modules list of modules to hook into
11
+ * @param {object} hookOptions hook options
11
12
  * @param {Function} onrequire callback to be executed upon encountering module
12
13
  */
13
14
  function Hook (modules, hookOptions, onrequire) {
@@ -13,6 +13,7 @@ module.exports = {
13
13
  '@playwright/test': () => require('../playwright'),
14
14
  '@elastic/elasticsearch': () => require('../elasticsearch'),
15
15
  '@elastic/transport': () => require('../elasticsearch'),
16
+ '@google/genai': () => require('../google-genai'),
16
17
  '@google-cloud/pubsub': () => require('../google-cloud-pubsub'),
17
18
  '@google-cloud/vertexai': () => require('../google-cloud-vertexai'),
18
19
  '@graphql-tools/executor': () => require('../graphql'),
@@ -2,6 +2,7 @@
2
2
 
3
3
  const dc = require('dc-polyfill')
4
4
  const instrumentations = require('./instrumentations')
5
+ const rewriterInstrumentations = require('./rewriter/instrumentations')
5
6
  const { AsyncResource } = require('async_hooks')
6
7
 
7
8
  const channelMap = {}
@@ -22,13 +23,23 @@ exports.tracingChannel = function (name) {
22
23
  return tc
23
24
  }
24
25
 
26
+ exports.getHooks = function getHooks (names) {
27
+ names = [names].flat()
28
+
29
+ return rewriterInstrumentations
30
+ .map(inst => inst.module)
31
+ .filter(({ name }) => names.includes(name))
32
+ .map(({ name, versionRange, filePath }) => ({ name, versions: [versionRange], file: filePath }))
33
+ }
34
+
25
35
  /**
26
36
  * @param {object} args
27
37
  * @param {string|string[]} args.name module name
28
38
  * @param {string[]} args.versions array of semver range strings
29
39
  * @param {string} [args.file='index.js'] path to file within package to instrument
30
40
  * @param {string} [args.filePattern] pattern to match files within package to instrument
31
- * @param Function hook
41
+ * @param {boolean} [args.patchDefault] whether to patch the default export
42
+ * @param {(moduleExports: unknown, version: string) => unknown} hook
32
43
  */
33
44
  exports.addHook = function addHook ({ name, versions, file, filePattern, patchDefault }, hook) {
34
45
  if (typeof name === 'string') {
@@ -2,7 +2,7 @@
2
2
 
3
3
  const { channel } = require('dc-polyfill')
4
4
  const path = require('path')
5
- const satisfies = require('semifies')
5
+ const satisfies = require('../../../../vendor/dist/semifies')
6
6
  const Hook = require('./hook')
7
7
  const requirePackageJson = require('../../../dd-trace/src/require-package-json')
8
8
  const log = require('../../../dd-trace/src/log')
@@ -10,6 +10,7 @@ const checkRequireCache = require('./check-require-cache')
10
10
  const telemetry = require('../../../dd-trace/src/guardrails/telemetry')
11
11
  const { isInServerlessEnvironment } = require('../../../dd-trace/src/serverless')
12
12
  const { getEnvironmentVariables } = require('../../../dd-trace/src/config-helper')
13
+ const rewriter = require('./rewriter')
13
14
 
14
15
  const envs = getEnvironmentVariables()
15
16
 
@@ -48,6 +49,10 @@ if (DD_TRACE_DEBUG && DD_TRACE_DEBUG.toLowerCase() !== 'false') {
48
49
  const seenCombo = new Set()
49
50
  const allInstrumentations = {}
50
51
 
52
+ for (const inst of disabledInstrumentations) {
53
+ rewriter.disable(inst)
54
+ }
55
+
51
56
  // TODO: make this more efficient
52
57
  for (const packageName of names) {
53
58
  if (disabledInstrumentations.has(packageName)) continue
@@ -0,0 +1,27 @@
1
+ 'use strict'
2
+
3
+ let meriyah
4
+ let astring
5
+ let esquery
6
+
7
+ module.exports = {
8
+ parse: (...args) => {
9
+ meriyah ??= require('../../../../../vendor/dist/meriyah')
10
+
11
+ return meriyah.parse(...args)
12
+ },
13
+
14
+ generate: (...args) => {
15
+ astring ??= require('../../../../../vendor/dist/astring')
16
+
17
+ return astring.generate(...args)
18
+ },
19
+
20
+ traverse: (ast, query, visitor) => {
21
+ esquery ??= require('../../../../../vendor/dist/esquery').default
22
+
23
+ const selector = esquery.parse(query)
24
+
25
+ return esquery.traverse(ast, selector, visitor)
26
+ },
27
+ }