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
@@ -0,0 +1,41 @@
1
+ 'use strict'
2
+
3
+ const TracingPlugin = require('../../dd-trace/src/plugins/tracing.js')
4
+
5
+ class GenAiTracingPlugin extends TracingPlugin {
6
+ static id = 'google-genai'
7
+ static operation = 'request'
8
+ static prefix = 'tracing:apm:google:genai:request'
9
+
10
+ static get type () { return 'web' }
11
+ static get kind () { return 'client' }
12
+
13
+ bindStart (ctx) {
14
+ const { args, methodName } = ctx
15
+
16
+ const inputs = args[0]
17
+ const model = inputs?.model || 'unknown'
18
+
19
+ this.startSpan('google_genai.request', {
20
+ meta: {
21
+ 'resource.name': methodName,
22
+ 'google_genai.request.model': model,
23
+ 'google_genai.request.provider': 'google'
24
+ }
25
+ }, ctx)
26
+
27
+ return ctx.currentStore
28
+ }
29
+
30
+ asyncEnd (ctx) {
31
+ const { span } = ctx.currentStore
32
+ if (!span) return
33
+
34
+ if (ctx.result) {
35
+ span.setTag('google_genai.response.model', ctx.result.modelVersion || ctx.inputs?.model)
36
+ }
37
+ span.finish()
38
+ }
39
+ }
40
+
41
+ module.exports = GenAiTracingPlugin
@@ -5,10 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  return (mod && mod.__esModule) ? mod : { "default": mod };
6
6
  };
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- const visitor_1 = require("graphql/language/visitor");
9
- const printer_1 = require("graphql/language/printer");
10
- const utilities_1 = require("graphql/utilities");
11
- const lodash_sortby_1 = __importDefault(require("lodash.sortby"));
8
+ const ddGlobal = globalThis[Symbol.for('dd-trace')];
9
+ const visitor_1 = ddGlobal.graphql_visitor;
10
+ const printer_1 = ddGlobal.graphql_printer;
11
+ const utilities_1 = ddGlobal.graphql_utilities;
12
+ const lodash_sortby_1 = __importDefault(require("../../../../vendor/dist/lodash.sortby"));
12
13
  function hideLiterals(ast) {
13
14
  return visitor_1.visit(ast, {
14
15
  IntValue(node) {
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { readFileSync } = require('fs')
4
- const { parse } = require('jest-docblock')
4
+ const { parse } = require('../../../vendor/dist/jest-docblock')
5
5
 
6
6
  const { getTestSuitePath } = require('../../dd-trace/src/plugins/util/test')
7
7
  const log = require('../../dd-trace/src/log')
@@ -62,6 +62,7 @@ function getJestTestName (test, shouldStripSeed = false) {
62
62
  }
63
63
 
64
64
  const globalDocblockRegExp = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/
65
+ const MAX_COMMENTS_CHECKED = 10
65
66
 
66
67
  function isMarkedAsUnskippable (test) {
67
68
  let testSource
@@ -86,7 +87,7 @@ function isMarkedAsUnskippable (test) {
86
87
  docblocks = parse(comment)
87
88
  } catch {
88
89
  // Skip unparsable comment and continue scanning
89
- if (commentsChecked++ >= 10) {
90
+ if (commentsChecked++ >= MAX_COMMENTS_CHECKED) {
90
91
  return false
91
92
  }
92
93
  continue
@@ -103,7 +104,7 @@ function isMarkedAsUnskippable (test) {
103
104
  }
104
105
  }
105
106
 
106
- if (commentsChecked++ >= 10) {
107
+ if (commentsChecked++ >= MAX_COMMENTS_CHECKED) {
107
108
  return false
108
109
  }
109
110
 
@@ -28,7 +28,8 @@ class KafkajsConsumerPlugin extends ConsumerPlugin {
28
28
  * @property {string} topic
29
29
  * @property {number} partition
30
30
  * @property {number} offset
31
- *
31
+ */
32
+ /**
32
33
  * @typedef {object} CommitEventItem
33
34
  * @property {string} groupId
34
35
  * @property {string} topic
@@ -25,6 +25,8 @@ class KafkajsProducerPlugin extends ProducerPlugin {
25
25
  * @property {string} topic
26
26
  * @property {number} partition
27
27
  * @property {number} offset
28
+ */
29
+ /**
28
30
  *
29
31
  * @typedef {object} ProducerResponseItem
30
32
  * @property {string} topic
@@ -49,7 +51,7 @@ class KafkajsProducerPlugin extends ProducerPlugin {
49
51
 
50
52
  /**
51
53
  *
52
- * @param {ProducerResponseItem[]} commitList
54
+ * @param {{ result: ProducerResponseItem[] }} ctx
53
55
  * @returns {void}
54
56
  */
55
57
  commit (ctx) {
@@ -12,6 +12,8 @@ const LangChainHandler = require('./handlers/default')
12
12
  const LangChainLanguageModelHandler = require('./handlers/language_models')
13
13
  const LangChainEmbeddingHandler = require('./handlers/embedding')
14
14
 
15
+ const defaultNs = ['langchain', 'embeddings']
16
+
15
17
  class BaseLangChainTracingPlugin extends TracingPlugin {
16
18
  static id = 'langchain'
17
19
  static operation = 'invoke'
@@ -36,7 +38,9 @@ class BaseLangChainTracingPlugin extends TracingPlugin {
36
38
  const type = ctx.type = this.constructor.lcType
37
39
 
38
40
  // Runnable interfaces have an `lc_namespace` property
39
- const ns = ctx.self.lc_namespace || ctx.namespace
41
+ const ns = ctx.self.lc_namespace || (
42
+ ctx.self.constructor.name === 'OpenAIEmbeddings' ? [...defaultNs, 'openai'] : defaultNs
43
+ )
40
44
 
41
45
  const resourceParts = [...ns, ctx.self.constructor.name]
42
46
  if (type === 'tool') {
@@ -111,13 +115,13 @@ class BaseLLMGeneratePlugin extends BaseLangChainTracingPlugin {
111
115
  class EmbeddingsEmbedQueryPlugin extends BaseLangChainTracingPlugin {
112
116
  static id = 'langchain_embeddings_embed_query'
113
117
  static lcType = 'embedding'
114
- static prefix = 'tracing:apm:@langchain/core:Embeddings_embedQuery'
118
+ static prefix = 'tracing:orchestrion:@langchain/core:Embeddings_embedQuery'
115
119
  }
116
120
 
117
121
  class EmbeddingsEmbedDocumentsPlugin extends BaseLangChainTracingPlugin {
118
122
  static id = 'langchain_embeddings_embed_documents'
119
123
  static lcType = 'embedding'
120
- static prefix = 'tracing:apm:@langchain/core:Embeddings_embedDocuments'
124
+ static prefix = 'tracing:orchestrion:@langchain/core:Embeddings_embedDocuments'
121
125
  }
122
126
 
123
127
  class ToolInvokePlugin extends BaseLangChainTracingPlugin {
@@ -10,10 +10,10 @@ const errorPages = new Set(['/404', '/500', '/_error', '/_not-found', '/_not-fou
10
10
 
11
11
  class NextPlugin extends ServerPlugin {
12
12
  static id = 'next'
13
+ #requestsBySpanId = new WeakMap()
13
14
 
14
15
  constructor (...args) {
15
16
  super(...args)
16
- this._requests = new WeakMap()
17
17
  this.addSub('apm:next:page:load', message => this.pageLoad(message))
18
18
  }
19
19
 
@@ -35,7 +35,9 @@ class NextPlugin extends ServerPlugin {
35
35
 
36
36
  analyticsSampler.sample(span, this.config.measured, true)
37
37
 
38
- this._requests.set(span, req)
38
+ // Store request by span ID to handle cases where child spans are activated
39
+ const spanId = span.context()._spanId
40
+ this.#requestsBySpanId.set(spanId, req)
39
41
 
40
42
  return { ...store, span }
41
43
  }
@@ -89,7 +91,13 @@ class NextPlugin extends ServerPlugin {
89
91
  if (!store) return
90
92
 
91
93
  const span = store.span
92
- const req = this._requests.get(span)
94
+
95
+ const spanId = span.context()._spanId
96
+ const parentSpanId = span.context()._parentId
97
+
98
+ // Try current span first, then parent span.
99
+ // This handles cases where pageLoad runs in a child span context
100
+ const req = this.#requestsBySpanId.get(spanId) ?? this.#requestsBySpanId.get(parentSpanId)
93
101
 
94
102
  // safeguard against missing req in complicated timeout scenarios
95
103
  if (!req) return
@@ -111,7 +111,7 @@ function constructChatCompletionResponseFromStreamedChunks (chunks, n) {
111
111
  * Constructs the entire response from a stream of OpenAI responses chunks.
112
112
  * The responses API uses event-based streaming with delta chunks.
113
113
  * @param {Array<Record<string, any>>} chunks
114
- * @returns {Record<string, any>}
114
+ * @returns {Record<string, any>|undefined}
115
115
  */
116
116
  function constructResponseResponseFromStreamedChunks (chunks) {
117
117
  // The responses API streams events with different types:
@@ -91,7 +91,7 @@ function wrapFunction (original, wrapper) {
91
91
  * @param {Record<string | symbol, unknown> | Function | undefined} target - The target
92
92
  * object.
93
93
  * @param {string | symbol} name - The property key of the method to wrap.
94
- * @param {(original: Function) => (...args) => any} wrapper - The wrapper function.
94
+ * @param {(original: Function) => (...args: unknown[]) => any} wrapper - The wrapper function.
95
95
  * @param {{ replaceGetter?: boolean }} [options] - If `replaceGetter` is set to
96
96
  * true, the getter is accessed and the getter is replaced with one that just
97
97
  * returns the earlier retrieved value. Use with care! This may only be done in
@@ -214,7 +214,7 @@ function wrap (target, name, wrapper, options) {
214
214
  * Record<string | symbol, unknown> |
215
215
  * Function} targets - The target objects.
216
216
  * @param {Array<string | symbol> | string | symbol} names - The property keys of the methods to wrap.
217
- * @param {(original: Function) => (...args) => any} wrapper - The wrapper function.
217
+ * @param {(original: Function) => (...args: unknown[]) => any} wrapper - The wrapper function.
218
218
  */
219
219
  function massWrap (targets, names, wrapper) {
220
220
  targets = toArray(targets)
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
 
3
+ const rfdc = require('../../../../vendor/dist/rfdc')({ proto: false, circles: false })
3
4
  const NoopAIGuard = require('./noop')
4
5
  const executeRequest = require('./client')
5
6
  const {
@@ -22,10 +23,11 @@ const appsecMetrics = telemetryMetrics.manager.namespace('appsec')
22
23
  const ALLOW = 'ALLOW'
23
24
 
24
25
  class AIGuardAbortError extends Error {
25
- constructor (reason) {
26
+ constructor (reason, tags) {
26
27
  super(reason)
27
28
  this.name = 'AIGuardAbortError'
28
29
  this.reason = reason
30
+ this.tags = tags
29
31
  }
30
32
  }
31
33
 
@@ -77,20 +79,26 @@ class AIGuard extends NoopAIGuard {
77
79
  this.#initialized = true
78
80
  }
79
81
 
80
- #truncate (messages) {
82
+ /**
83
+ * Returns a safe copy of the messages to be serialized into the meta struct.
84
+ *
85
+ * - Clones each message so callers cannot mutate the data set in the meta struct.
86
+ * - Truncates the list of messages and `content` fields emitting metrics accordingly.
87
+ */
88
+ #buildMessagesForMetaStruct (messages) {
81
89
  const size = Math.min(messages.length, this.#maxMessagesLength)
82
90
  if (messages.length > size) {
83
91
  appsecMetrics.count(AI_GUARD_TELEMETRY_TRUNCATED, { type: 'messages' }).inc(1)
84
92
  }
85
- const result = messages.slice(-size)
86
-
93
+ const result = []
87
94
  let contentTruncated = false
88
- for (let i = 0; i < size; i++) {
89
- const message = result[i]
95
+ for (let i = messages.length - size; i < messages.length; i++) {
96
+ const message = rfdc(messages[i])
90
97
  if (message.content?.length > this.#maxContentSize) {
91
98
  contentTruncated = true
92
- result[i] = { ...message, content: message.content.slice(0, this.#maxContentSize) }
99
+ message.content = message.content.slice(0, this.#maxContentSize)
93
100
  }
101
+ result.push(message)
94
102
  }
95
103
  if (contentTruncated) {
96
104
  appsecMetrics.count(AI_GUARD_TELEMETRY_TRUNCATED, { type: 'content' }).inc(1)
@@ -138,10 +146,11 @@ class AIGuard extends NoopAIGuard {
138
146
  span.setTag(AI_GUARD_TOOL_NAME_TAG_KEY, name)
139
147
  }
140
148
  }
149
+ const metaStruct = {
150
+ messages: this.#buildMessagesForMetaStruct(messages)
151
+ }
141
152
  span.meta_struct = {
142
- [AI_GUARD_META_STRUCT_KEY]: {
143
- messages: this.#truncate(messages)
144
- }
153
+ [AI_GUARD_META_STRUCT_KEY]: metaStruct
145
154
  }
146
155
  let response
147
156
  try {
@@ -166,7 +175,7 @@ class AIGuard extends NoopAIGuard {
166
175
  `AI Guard service call failed, status ${response.status}`,
167
176
  { errors: response.body?.errors })
168
177
  }
169
- let action, reason, blockingEnabled
178
+ let action, reason, tags, blockingEnabled
170
179
  try {
171
180
  const attr = response.body.data.attributes
172
181
  if (!attr.action) {
@@ -174,6 +183,7 @@ class AIGuard extends NoopAIGuard {
174
183
  }
175
184
  action = attr.action
176
185
  reason = attr.reason
186
+ tags = attr.tags
177
187
  blockingEnabled = attr.is_blocking_enabled ?? false
178
188
  } catch (e) {
179
189
  appsecMetrics.count(AI_GUARD_TELEMETRY_REQUESTS, { error: true }).inc(1)
@@ -182,12 +192,17 @@ class AIGuard extends NoopAIGuard {
182
192
  const shouldBlock = block && blockingEnabled && action !== ALLOW
183
193
  appsecMetrics.count(AI_GUARD_TELEMETRY_REQUESTS, { action, error: false, block: shouldBlock }).inc(1)
184
194
  span.setTag(AI_GUARD_ACTION_TAG_KEY, action)
185
- span.setTag(AI_GUARD_REASON_TAG_KEY, reason)
195
+ if (reason) {
196
+ span.setTag(AI_GUARD_REASON_TAG_KEY, reason)
197
+ }
198
+ if (tags?.length > 0) {
199
+ metaStruct.attack_categories = tags
200
+ }
186
201
  if (shouldBlock) {
187
202
  span.setTag(AI_GUARD_BLOCKED_TAG_KEY, 'true')
188
- throw new AIGuardAbortError(reason)
203
+ throw new AIGuardAbortError(reason, tags)
189
204
  }
190
- return { action, reason }
205
+ return { action, reason, tags }
191
206
  })
192
207
  }
193
208
  }
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const { TTLCache } = require('@isaacs/ttlcache')
3
+ const { TTLCache } = require('../../../../vendor/dist/@isaacs/ttlcache')
4
4
  const web = require('../plugins/util/web')
5
5
  const log = require('../log')
6
6
  const { AUTO_REJECT, USER_REJECT } = require('../../../../ext/priority')
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const { LRUCache } = require('lru-cache')
3
+ const { LRUCache } = require('../../../../../vendor/dist/lru-cache')
4
4
  const web = require('../../plugins/util/web')
5
5
  const vulnerabilities = require('./vulnerabilities')
6
6
 
@@ -47,7 +47,7 @@ export async function load (url, context, nextLoad) {
47
47
  passes.push('iast')
48
48
  }
49
49
  } else {
50
- passes = ['orchestrion']
50
+ passes = [] // TODO: Re-enable Orchestrion when viable.
51
51
  }
52
52
  const rewritten = rewriter.rewrite(result.source.toString(), url, passes)
53
53
 
@@ -175,9 +175,8 @@ function enableRewriter (telemetryVerbosity) {
175
175
  shimmer.wrap(Module.prototype, '_compile', compileMethod => getCompileMethodFn(compileMethod))
176
176
  }
177
177
  }
178
+ enableEsmRewriter(telemetryVerbosity)
178
179
  }
179
-
180
- enableEsmRewriter(telemetryVerbosity)
181
180
  } catch (e) {
182
181
  log.error('Error enabling Rewriter', e)
183
182
  }
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const { LRUCache } = require('lru-cache')
3
+ const { LRUCache } = require('../../../../../vendor/dist/lru-cache')
4
4
  const vulnerabilitiesFormatter = require('./vulnerabilities-formatter')
5
5
  const { IAST_ENABLED_TAG_KEY, IAST_JSON_TAG_KEY } = require('./tags')
6
6
  const { keepTrace } = require('../../priority_sampler')
@@ -546,10 +546,6 @@ function finishRequest (req, res, storedResponseHeaders, requestBody) {
546
546
  reportRequestBody(rootSpan, requestBody)
547
547
  }
548
548
 
549
- if (tags['appsec.event'] === 'true' && typeof req.route?.path === 'string') {
550
- newTags['http.endpoint'] = req.route.path
551
- }
552
-
553
549
  rootSpan.addTags(newTags)
554
550
  }
555
551
 
@@ -3,11 +3,18 @@
3
3
  const { storage } = require('../../datadog-core')
4
4
  const baggageStorage = storage('baggage')
5
5
 
6
+ /**
7
+ * @param {string} key
8
+ * @param {string} value
9
+ */
6
10
  function setBaggageItem (key, value) {
7
11
  storage('baggage').enterWith({ ...baggageStorage.getStore(), [key]: value })
8
12
  return storage('baggage').getStore()
9
13
  }
10
14
 
15
+ /**
16
+ * @param {string} key
17
+ */
11
18
  function getBaggageItem (key) {
12
19
  return storage('baggage').getStore()?.[key]
13
20
  }
@@ -16,6 +23,10 @@ function getAllBaggageItems () {
16
23
  return storage('baggage').getStore() ?? {}
17
24
  }
18
25
 
26
+ /**
27
+ * @param {string} keyToRemove
28
+ * @returns {Record<string, unknown>}
29
+ */
19
30
  function removeBaggageItem (keyToRemove) {
20
31
  const { [keyToRemove]: _, ...newBaggage } = storage('baggage').getStore()
21
32
  storage('baggage').enterWith(newBaggage)
@@ -36,7 +36,7 @@ session.on('Debugger.paused', async ({ params: { hitBreakpoints: [hitBreakpoint]
36
36
 
37
37
  const stack = getStackFromCallFrames(callFrames)
38
38
 
39
- const getLocalState = await getLocalStateForCallFrame(callFrames[0])
39
+ const { processLocalState } = await getLocalStateForCallFrame(callFrames[0])
40
40
 
41
41
  await session.post('Debugger.resume')
42
42
 
@@ -48,17 +48,13 @@ session.on('Debugger.paused', async ({ params: { hitBreakpoints: [hitBreakpoint]
48
48
  version: '0',
49
49
  location: probe.location
50
50
  },
51
+ captures: {
52
+ lines: { [probe.location.lines[0]]: { locals: processLocalState() } }
53
+ },
51
54
  stack,
52
55
  language: 'javascript'
53
56
  }
54
57
 
55
- const state = getLocalState()
56
- if (state) {
57
- snapshot.captures = {
58
- lines: { [probe.location.lines[0]]: { locals: state } }
59
- }
60
- }
61
-
62
58
  breakpointHitChannel.postMessage({ snapshot })
63
59
  })
64
60
 
@@ -245,7 +245,7 @@ function generateAndUploadPackFiles ({
245
245
 
246
246
  /**
247
247
  * This function uploads git metadata to CI Visibility's backend.
248
- */
248
+ */
249
249
  function sendGitMetadata (url, { isEvpProxy, evpProxyPrefix }, configRepositoryUrl, callback) {
250
250
  if (!isGitAvailable()) {
251
251
  return callback(new Error('Git is not available'))
@@ -14,7 +14,8 @@ function getTestManagementTests ({
14
14
  commitMessage,
15
15
  sha,
16
16
  commitHeadSha,
17
- commitHeadMessage
17
+ commitHeadMessage,
18
+ branch
18
19
  }, done) {
19
20
  const options = {
20
21
  path: '/api/v2/test/libraries/test-management/tests',
@@ -49,7 +50,8 @@ function getTestManagementTests ({
49
50
  attributes: {
50
51
  repository_url: repositoryUrl,
51
52
  commit_message: commitHeadMessage || commitMessage,
52
- sha: commitHeadSha || sha
53
+ sha: commitHeadSha || sha,
54
+ branch
53
55
  }
54
56
  }
55
57
  })