dd-trace 5.23.1 → 5.25.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 (156) hide show
  1. package/LICENSE-3rdparty.csv +1 -1
  2. package/ext/types.d.ts +1 -0
  3. package/ext/types.js +1 -0
  4. package/index.d.ts +361 -0
  5. package/package.json +18 -13
  6. package/packages/datadog-code-origin/index.js +38 -0
  7. package/packages/datadog-core/index.js +2 -2
  8. package/packages/datadog-core/src/utils/src/parse-tags.js +33 -0
  9. package/packages/datadog-esbuild/index.js +4 -2
  10. package/packages/datadog-instrumentations/src/amqplib.js +65 -5
  11. package/packages/datadog-instrumentations/src/avsc.js +37 -0
  12. package/packages/datadog-instrumentations/src/azure-functions.js +48 -0
  13. package/packages/datadog-instrumentations/src/child_process.js +144 -27
  14. package/packages/datadog-instrumentations/src/express.js +37 -4
  15. package/packages/datadog-instrumentations/src/fastify.js +12 -1
  16. package/packages/datadog-instrumentations/src/fs.js +27 -7
  17. package/packages/datadog-instrumentations/src/helpers/hooks.js +6 -0
  18. package/packages/datadog-instrumentations/src/helpers/register.js +9 -0
  19. package/packages/datadog-instrumentations/src/jest.js +2 -1
  20. package/packages/datadog-instrumentations/src/kafkajs.js +123 -63
  21. package/packages/datadog-instrumentations/src/mocha/common.js +1 -1
  22. package/packages/datadog-instrumentations/src/mocha/utils.js +2 -2
  23. package/packages/datadog-instrumentations/src/multer.js +37 -0
  24. package/packages/datadog-instrumentations/src/mysql2.js +220 -1
  25. package/packages/datadog-instrumentations/src/openai.js +2 -2
  26. package/packages/datadog-instrumentations/src/protobufjs.js +127 -0
  27. package/packages/datadog-instrumentations/src/url.js +84 -0
  28. package/packages/datadog-instrumentations/src/utils/src/extract-package-and-module-path.js +7 -4
  29. package/packages/datadog-instrumentations/src/winston.js +22 -0
  30. package/packages/datadog-plugin-amqplib/src/consumer.js +4 -4
  31. package/packages/datadog-plugin-avsc/src/index.js +9 -0
  32. package/packages/datadog-plugin-avsc/src/schema_iterator.js +169 -0
  33. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +1 -0
  34. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +1 -0
  35. package/packages/datadog-plugin-aws-sdk/src/services/s3.js +1 -0
  36. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +1 -0
  37. package/packages/datadog-plugin-azure-functions/src/index.js +77 -0
  38. package/packages/datadog-plugin-fastify/src/code_origin.js +31 -0
  39. package/packages/datadog-plugin-fastify/src/index.js +10 -12
  40. package/packages/datadog-plugin-fastify/src/tracing.js +19 -0
  41. package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +8 -1
  42. package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +8 -0
  43. package/packages/datadog-plugin-grpc/src/client.js +3 -0
  44. package/packages/datadog-plugin-grpc/src/server.js +3 -0
  45. package/packages/datadog-plugin-kafkajs/src/batch-consumer.js +6 -3
  46. package/packages/datadog-plugin-kafkajs/src/consumer.js +8 -4
  47. package/packages/datadog-plugin-kafkajs/src/producer.js +10 -4
  48. package/packages/datadog-plugin-mocha/src/index.js +4 -1
  49. package/packages/datadog-plugin-openai/src/index.js +9 -1015
  50. package/packages/datadog-plugin-openai/src/tracing.js +1023 -0
  51. package/packages/datadog-plugin-protobufjs/src/index.js +14 -0
  52. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +180 -0
  53. package/packages/dd-trace/src/appsec/addresses.js +8 -1
  54. package/packages/dd-trace/src/appsec/channels.js +7 -1
  55. package/packages/dd-trace/src/appsec/iast/analyzers/cookie-analyzer.js +13 -1
  56. package/packages/dd-trace/src/appsec/iast/analyzers/path-traversal-analyzer.js +8 -1
  57. package/packages/dd-trace/src/appsec/iast/iast-plugin.js +1 -1
  58. package/packages/dd-trace/src/appsec/iast/index.js +3 -0
  59. package/packages/dd-trace/src/appsec/iast/taint-tracking/csi-methods.js +1 -0
  60. package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +55 -7
  61. package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +15 -0
  62. package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +4 -2
  63. package/packages/dd-trace/src/appsec/index.js +61 -43
  64. package/packages/dd-trace/src/appsec/rasp/command_injection.js +49 -0
  65. package/packages/dd-trace/src/appsec/rasp/fs-plugin.js +99 -0
  66. package/packages/dd-trace/src/appsec/rasp/index.js +27 -10
  67. package/packages/dd-trace/src/appsec/rasp/lfi.js +112 -0
  68. package/packages/dd-trace/src/appsec/rasp/sql_injection.js +24 -4
  69. package/packages/dd-trace/src/appsec/rasp/ssrf.js +4 -3
  70. package/packages/dd-trace/src/appsec/rasp/utils.js +4 -2
  71. package/packages/dd-trace/src/appsec/recommended.json +3 -7
  72. package/packages/dd-trace/src/appsec/remote_config/capabilities.js +6 -1
  73. package/packages/dd-trace/src/appsec/remote_config/index.js +10 -0
  74. package/packages/dd-trace/src/appsec/reporter.js +17 -9
  75. package/packages/dd-trace/src/appsec/sdk/track_event.js +10 -3
  76. package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +1 -1
  77. package/packages/dd-trace/src/appsec/waf/waf_manager.js +4 -0
  78. package/packages/dd-trace/src/azure_metadata.js +120 -0
  79. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +97 -0
  80. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +90 -0
  81. package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +2 -14
  82. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +19 -1
  83. package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +53 -0
  84. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +8 -1
  85. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +43 -0
  86. package/packages/dd-trace/src/ci-visibility/log-submission/log-submission-plugin.js +53 -0
  87. package/packages/dd-trace/src/config.js +86 -6
  88. package/packages/dd-trace/src/constants.js +3 -1
  89. package/packages/dd-trace/src/datastreams/pathway.js +1 -0
  90. package/packages/dd-trace/src/datastreams/schemas/schema_builder.js +25 -17
  91. package/packages/dd-trace/src/debugger/devtools_client/config.js +2 -0
  92. package/packages/dd-trace/src/debugger/devtools_client/index.js +52 -5
  93. package/packages/dd-trace/src/debugger/devtools_client/remote_config.js +4 -4
  94. package/packages/dd-trace/src/debugger/devtools_client/send.js +29 -2
  95. package/packages/dd-trace/src/debugger/devtools_client/snapshot/collector.js +187 -0
  96. package/packages/dd-trace/src/debugger/devtools_client/snapshot/index.js +40 -0
  97. package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +252 -0
  98. package/packages/dd-trace/src/debugger/devtools_client/snapshot/symbols.js +6 -0
  99. package/packages/dd-trace/src/debugger/devtools_client/state.js +19 -4
  100. package/packages/dd-trace/src/debugger/index.js +10 -3
  101. package/packages/dd-trace/src/exporters/common/request.js +8 -34
  102. package/packages/dd-trace/src/exporters/common/url-to-http-options-polyfill.js +31 -0
  103. package/packages/dd-trace/src/llmobs/constants/tags.js +34 -0
  104. package/packages/dd-trace/src/llmobs/constants/text.js +6 -0
  105. package/packages/dd-trace/src/llmobs/constants/writers.js +13 -0
  106. package/packages/dd-trace/src/llmobs/index.js +103 -0
  107. package/packages/dd-trace/src/llmobs/noop.js +82 -0
  108. package/packages/dd-trace/src/llmobs/plugins/base.js +65 -0
  109. package/packages/dd-trace/src/llmobs/plugins/openai.js +205 -0
  110. package/packages/dd-trace/src/llmobs/sdk.js +377 -0
  111. package/packages/dd-trace/src/llmobs/span_processor.js +195 -0
  112. package/packages/dd-trace/src/llmobs/storage.js +7 -0
  113. package/packages/dd-trace/src/llmobs/tagger.js +322 -0
  114. package/packages/dd-trace/src/llmobs/util.js +176 -0
  115. package/packages/dd-trace/src/llmobs/writers/base.js +111 -0
  116. package/packages/dd-trace/src/llmobs/writers/evaluations.js +29 -0
  117. package/packages/dd-trace/src/llmobs/writers/spans/agentProxy.js +23 -0
  118. package/packages/dd-trace/src/llmobs/writers/spans/agentless.js +17 -0
  119. package/packages/dd-trace/src/llmobs/writers/spans/base.js +49 -0
  120. package/packages/dd-trace/src/noop/proxy.js +3 -0
  121. package/packages/dd-trace/src/noop/span.js +3 -0
  122. package/packages/dd-trace/src/opentelemetry/span.js +1 -1
  123. package/packages/dd-trace/src/opentelemetry/tracer.js +1 -0
  124. package/packages/dd-trace/src/opentracing/propagation/text_map.js +73 -12
  125. package/packages/dd-trace/src/opentracing/span.js +12 -0
  126. package/packages/dd-trace/src/opentracing/tracer.js +8 -1
  127. package/packages/dd-trace/src/payload-tagging/config/aws.json +71 -3
  128. package/packages/dd-trace/src/payload-tagging/index.js +1 -1
  129. package/packages/dd-trace/src/payload-tagging/jsonpath-plus.js +2094 -0
  130. package/packages/dd-trace/src/plugin_manager.js +4 -2
  131. package/packages/dd-trace/src/plugins/ci_plugin.js +2 -0
  132. package/packages/dd-trace/src/plugins/index.js +3 -0
  133. package/packages/dd-trace/src/plugins/log_plugin.js +1 -1
  134. package/packages/dd-trace/src/plugins/outbound.js +9 -0
  135. package/packages/dd-trace/src/plugins/schema.js +35 -0
  136. package/packages/dd-trace/src/plugins/util/ci.js +23 -1
  137. package/packages/dd-trace/src/plugins/util/serverless.js +7 -0
  138. package/packages/dd-trace/src/plugins/util/stacktrace.js +94 -0
  139. package/packages/dd-trace/src/plugins/util/tags.js +7 -0
  140. package/packages/dd-trace/src/plugins/util/test.js +20 -22
  141. package/packages/dd-trace/src/plugins/util/web.js +6 -4
  142. package/packages/dd-trace/src/priority_sampler.js +16 -0
  143. package/packages/dd-trace/src/profiling/config.js +3 -1
  144. package/packages/dd-trace/src/profiling/exporters/agent.js +7 -5
  145. package/packages/dd-trace/src/profiling/profiler.js +24 -14
  146. package/packages/dd-trace/src/profiling/profilers/events.js +3 -3
  147. package/packages/dd-trace/src/profiling/profilers/wall.js +95 -66
  148. package/packages/dd-trace/src/proxy.js +20 -1
  149. package/packages/dd-trace/src/service-naming/schemas/v0/index.js +2 -1
  150. package/packages/dd-trace/src/service-naming/schemas/v0/serverless.js +12 -0
  151. package/packages/dd-trace/src/service-naming/schemas/v1/index.js +2 -1
  152. package/packages/dd-trace/src/service-naming/schemas/v1/serverless.js +12 -0
  153. package/packages/dd-trace/src/span_processor.js +5 -0
  154. package/packages/dd-trace/src/telemetry/index.js +11 -1
  155. package/packages/datadog-core/src/storage/async_resource.js +0 -108
  156. package/packages/datadog-core/src/storage/index.js +0 -5
@@ -14,7 +14,6 @@ require,import-in-the-middle,Apache license 2.0,Copyright 2021 Datadog Inc.
14
14
  require,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
15
15
  require,istanbul-lib-coverage,BSD-3-Clause,Copyright 2012-2015 Yahoo! Inc.
16
16
  require,jest-docblock,MIT,Copyright Meta Platforms, Inc. and affiliates.
17
- require,jsonpath-plus,MIT,Copyright (c) 2011-2019 Stefan Goessner, Subbu Allamaraju, Mike Brevoort, Robert Krahn, Brett Zamir, Richard Schneider
18
17
  require,koalas,MIT,Copyright 2013-2017 Brian Woodward
19
18
  require,limiter,MIT,Copyright 2011 John Hurliman
20
19
  require,lodash.sortby,MIT,Copyright JS Foundation and other contributors
@@ -30,6 +29,7 @@ require,retry,MIT,Copyright 2011 Tim Koschützki Felix Geisendörfer
30
29
  require,rfdc,MIT,Copyright 2019 David Mark Clements
31
30
  require,semver,ISC,Copyright Isaac Z. Schlueter and Contributors
32
31
  require,shell-quote,mit,Copyright (c) 2013 James Halliday
32
+ dev,@apollo/server,MIT,Copyright (c) 2016-2020 Apollo Graph, Inc. (Formerly Meteor Development Group, Inc.)
33
33
  dev,@types/node,MIT,Copyright Authors
34
34
  dev,autocannon,MIT,Copyright 2016 Matteo Collina
35
35
  dev,aws-sdk,Apache 2.0,Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
package/ext/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  declare const types: {
2
2
  HTTP: 'http'
3
+ SERVERLESS: 'serverless'
3
4
  WEB: 'web'
4
5
  }
5
6
 
package/ext/types.js CHANGED
@@ -2,5 +2,6 @@
2
2
 
3
3
  module.exports = {
4
4
  HTTP: 'http',
5
+ SERVERLESS: 'serverless',
5
6
  WEB: 'web'
6
7
  }
package/index.d.ts CHANGED
@@ -137,6 +137,11 @@ interface Tracer extends opentracing.Tracer {
137
137
  TracerProvider: tracer.opentelemetry.TracerProvider;
138
138
 
139
139
  dogstatsd: tracer.DogStatsD;
140
+
141
+ /**
142
+ * LLM Observability SDK
143
+ */
144
+ llmobs: tracer.llmobs.LLMObs;
140
145
  }
141
146
 
142
147
  // left out of the namespace, so it
@@ -147,7 +152,9 @@ interface Plugins {
147
152
  "amqp10": tracer.plugins.amqp10;
148
153
  "amqplib": tracer.plugins.amqplib;
149
154
  "apollo": tracer.plugins.apollo;
155
+ "avsc": tracer.plugins.avsc;
150
156
  "aws-sdk": tracer.plugins.aws_sdk;
157
+ "azure-functions": tracer.plugins.azure_functions;
151
158
  "bunyan": tracer.plugins.bunyan;
152
159
  "cassandra-driver": tracer.plugins.cassandra_driver;
153
160
  "child_process": tracer.plugins.child_process;
@@ -190,6 +197,7 @@ interface Plugins {
190
197
  "playwright": tracer.plugins.playwright;
191
198
  "pg": tracer.plugins.pg;
192
199
  "pino": tracer.plugins.pino;
200
+ "protobufjs": tracer.plugins.protobufjs;
193
201
  "redis": tracer.plugins.redis;
194
202
  "restify": tracer.plugins.restify;
195
203
  "rhea": tracer.plugins.rhea;
@@ -749,6 +757,11 @@ declare namespace tracer {
749
757
  */
750
758
  maxDepth?: number
751
759
  }
760
+
761
+ /**
762
+ * Configuration enabling LLM Observability. Enablement is superceded by the DD_LLMOBS_ENABLED environment variable.
763
+ */
764
+ llmobs?: llmobs.LLMObsEnableOptions
752
765
  }
753
766
 
754
767
  /**
@@ -1191,6 +1204,12 @@ declare namespace tracer {
1191
1204
  signature?: boolean;
1192
1205
  }
1193
1206
 
1207
+ /**
1208
+ * This plugin automatically patches the [avsc](https://github.com/mtth/avsc) module
1209
+ * to collect avro message schemas when Datastreams Monitoring is enabled.
1210
+ */
1211
+ interface avsc extends Integration {}
1212
+
1194
1213
  /**
1195
1214
  * This plugin automatically instruments the
1196
1215
  * [aws-sdk](https://github.com/aws/aws-sdk-js) module.
@@ -1229,6 +1248,12 @@ declare namespace tracer {
1229
1248
  [key: string]: boolean | Object | undefined;
1230
1249
  }
1231
1250
 
1251
+ /**
1252
+ * This plugin automatically instruments the
1253
+ * @azure/functions module.
1254
+ */
1255
+ interface azure_functions extends Instrumentation {}
1256
+
1232
1257
  /**
1233
1258
  * This plugin patches the [bunyan](https://github.com/trentm/node-bunyan)
1234
1259
  * to automatically inject trace identifiers in log records when the
@@ -1731,6 +1756,11 @@ declare namespace tracer {
1731
1756
  * on the tracer.
1732
1757
  */
1733
1758
  interface pino extends Integration {}
1759
+ /**
1760
+ * This plugin automatically patches the [protobufjs](https://protobufjs.github.io/protobuf.js/)
1761
+ * to collect protobuf message schemas when Datastreams Monitoring is enabled.
1762
+ */
1763
+ interface protobufjs extends Integration {}
1734
1764
 
1735
1765
  /**
1736
1766
  * This plugin automatically instruments the
@@ -2146,6 +2176,12 @@ declare namespace tracer {
2146
2176
  */
2147
2177
  maxContextOperations?: number,
2148
2178
 
2179
+ /**
2180
+ * Defines the pattern to ignore cookie names in the vulnerability hash calculation
2181
+ * @default ".{32,}"
2182
+ */
2183
+ cookieFilterPattern?: string,
2184
+
2149
2185
  /**
2150
2186
  * Whether to enable vulnerability deduplication
2151
2187
  */
@@ -2172,6 +2208,331 @@ declare namespace tracer {
2172
2208
  */
2173
2209
  telemetryVerbosity?: string
2174
2210
  }
2211
+
2212
+ export namespace llmobs {
2213
+ export interface LLMObs {
2214
+
2215
+ /**
2216
+ * Whether or not LLM Observability is enabled.
2217
+ */
2218
+ enabled: boolean,
2219
+
2220
+ /**
2221
+ * Enable LLM Observability tracing.
2222
+ */
2223
+ enable (options: LLMObsEnableOptions): void,
2224
+
2225
+ /**
2226
+ * Disable LLM Observability tracing.
2227
+ */
2228
+ disable (): void,
2229
+
2230
+ /**
2231
+ * Instruments a function by automatically creating a span activated on its
2232
+ * scope.
2233
+ *
2234
+ * The span will automatically be finished when one of these conditions is
2235
+ * met:
2236
+ *
2237
+ * * The function returns a promise, in which case the span will finish when
2238
+ * the promise is resolved or rejected.
2239
+ * * The function takes a callback as its second parameter, in which case the
2240
+ * span will finish when that callback is called.
2241
+ * * The function doesn't accept a callback and doesn't return a promise, in
2242
+ * which case the span will finish at the end of the function execution.
2243
+ * @param fn The function to instrument.
2244
+ * @param options Optional LLM Observability span options.
2245
+ * @returns The return value of the function.
2246
+ */
2247
+ trace<T> (options: LLMObsNamedSpanOptions, fn: (span: tracer.Span, done: (error?: Error) => void) => T): T
2248
+
2249
+ /**
2250
+ * Wrap a function to automatically create a span activated on its
2251
+ * scope when it's called.
2252
+ *
2253
+ * The span will automatically be finished when one of these conditions is
2254
+ * met:
2255
+ *
2256
+ * * The function returns a promise, in which case the span will finish when
2257
+ * the promise is resolved or rejected.
2258
+ * * The function takes a callback as its last parameter, in which case the
2259
+ * span will finish when that callback is called.
2260
+ * * The function doesn't accept a callback and doesn't return a promise, in
2261
+ * which case the span will finish at the end of the function execution.
2262
+ * @param fn The function to instrument.
2263
+ * @param options Optional LLM Observability span options.
2264
+ * @returns A new function that wraps the provided function with span creation.
2265
+ */
2266
+ wrap<T = (...args: any[]) => any> (options: LLMObsNamelessSpanOptions, fn: T): T
2267
+
2268
+ /**
2269
+ * Decorate a function in a javascript runtime that supports function decorators.
2270
+ * Note that this is **not** supported in the Node.js runtime, but is in TypeScript.
2271
+ *
2272
+ * In TypeScript, this decorator is only supported in contexts where general TypeScript
2273
+ * function decorators are supported.
2274
+ *
2275
+ * @param options Optional LLM Observability span options.
2276
+ */
2277
+ decorate (options: llmobs.LLMObsNamelessSpanOptions): any
2278
+
2279
+ /**
2280
+ * Returns a representation of a span to export its span and trace IDs.
2281
+ * If no span is provided, the current LLMObs-type span will be used.
2282
+ * @param span Optional span to export.
2283
+ * @returns An object containing the span and trace IDs.
2284
+ */
2285
+ exportSpan (span?: tracer.Span): llmobs.ExportedLLMObsSpan
2286
+
2287
+
2288
+ /**
2289
+ * Sets inputs, outputs, tags, metadata, and metrics as provided for a given LLM Observability span.
2290
+ * Note that with the exception of tags, this method will override any existing values for the provided fields.
2291
+ *
2292
+ * For example:
2293
+ * ```javascript
2294
+ * llmobs.trace({ kind: 'llm', name: 'myLLM', modelName: 'gpt-4o', modelProvider: 'openai' }, () => {
2295
+ * llmobs.annotate({
2296
+ * inputData: [{ content: 'system prompt, role: 'system' }, { content: 'user prompt', role: 'user' }],
2297
+ * outputData: { content: 'response', role: 'ai' },
2298
+ * metadata: { temperature: 0.7 },
2299
+ * tags: { host: 'localhost' },
2300
+ * metrics: { inputTokens: 10, outputTokens: 20, totalTokens: 30 }
2301
+ * })
2302
+ * })
2303
+ * ```
2304
+ *
2305
+ * @param span The span to annotate (defaults to the current LLM Observability span if not provided)
2306
+ * @param options An object containing the inputs, outputs, tags, metadata, and metrics to set on the span.
2307
+ */
2308
+ annotate (options: llmobs.AnnotationOptions): void
2309
+ annotate (span: tracer.Span | undefined, options: llmobs.AnnotationOptions): void
2310
+
2311
+ /**
2312
+ * Submits a custom evalutation metric for a given span ID and trace ID.
2313
+ * @param spanContext The span context of the span to submit the evaluation metric for.
2314
+ * @param options An object containing the label, metric type, value, and tags of the evaluation metric.
2315
+ */
2316
+ submitEvaluation (spanContext: llmobs.ExportedLLMObsSpan, options: llmobs.EvaluationOptions): void
2317
+
2318
+ /**
2319
+ * Flushes any remaining spans and evaluation metrics to LLM Observability.
2320
+ */
2321
+ flush (): void
2322
+ }
2323
+
2324
+ interface EvaluationOptions {
2325
+ /**
2326
+ * The name of the evalutation metric
2327
+ */
2328
+ label: string,
2329
+
2330
+ /**
2331
+ * The type of evaluation metric, one of 'categorical' or 'score'
2332
+ */
2333
+ metricType: 'categorical' | 'score',
2334
+
2335
+ /**
2336
+ * The value of the evaluation metric.
2337
+ * Must be string for 'categorical' metrics and number for 'score' metrics.
2338
+ */
2339
+ value: string | number,
2340
+
2341
+ /**
2342
+ * An object of string key-value pairs to tag the evaluation metric with.
2343
+ */
2344
+ tags?: { [key: string]: any },
2345
+
2346
+ /**
2347
+ * The name of the ML application
2348
+ */
2349
+ mlApp?: string,
2350
+
2351
+ /**
2352
+ * The timestamp in milliseconds when the evaluation metric result was generated.
2353
+ */
2354
+ timestampMs?: number
2355
+ }
2356
+
2357
+ interface Document {
2358
+ /**
2359
+ * Document text
2360
+ */
2361
+ text?: string,
2362
+
2363
+ /**
2364
+ * Document name
2365
+ */
2366
+ name?: string,
2367
+
2368
+ /**
2369
+ * Document ID
2370
+ */
2371
+ id?: string,
2372
+
2373
+ /**
2374
+ * Score of the document retrieval as a source of ground truth
2375
+ */
2376
+ score?: number
2377
+ }
2378
+
2379
+ /**
2380
+ * Represents a single LLM chat model message
2381
+ */
2382
+ interface Message {
2383
+ /**
2384
+ * Content of the message.
2385
+ */
2386
+ content: string,
2387
+
2388
+ /**
2389
+ * Role of the message (ie system, user, ai)
2390
+ */
2391
+ role?: string,
2392
+
2393
+ /**
2394
+ * Tool calls of the message
2395
+ */
2396
+ toolCalls?: ToolCall[],
2397
+ }
2398
+
2399
+ /**
2400
+ * Represents a single tool call for an LLM chat model message
2401
+ */
2402
+ interface ToolCall {
2403
+ /**
2404
+ * Name of the tool
2405
+ */
2406
+ name?: string,
2407
+
2408
+ /**
2409
+ * Arguments passed to the tool
2410
+ */
2411
+ arguments?: { [key: string]: any },
2412
+
2413
+ /**
2414
+ * The tool ID
2415
+ */
2416
+ toolId?: string,
2417
+
2418
+ /**
2419
+ * The tool type
2420
+ */
2421
+ type?: string
2422
+ }
2423
+
2424
+ /**
2425
+ * Annotation options for LLM Observability spans.
2426
+ */
2427
+ interface AnnotationOptions {
2428
+ /**
2429
+ * A single input string, object, or a list of objects based on the span kind:
2430
+ * 1. LLM spans: accepts a string, or an object of the form {content: "...", role: "..."}, or a list of objects with the same signature.
2431
+ * 2. Embedding spans: accepts a string, list of strings, or an object of the form {text: "...", ...}, or a list of objects with the same signature.
2432
+ * 3. Other: any JSON serializable type
2433
+ */
2434
+ inputData?: string | Message | Message[] | Document | Document[] | { [key: string]: any },
2435
+
2436
+ /**
2437
+ * A single output string, object, or a list of objects based on the span kind:
2438
+ * 1. LLM spans: accepts a string, or an object of the form {content: "...", role: "..."}, or a list of objects with the same signature.
2439
+ * 2. Retrieval spans: An object containing any of the key value pairs {name: str, id: str, text: str, source: number} or a list of dictionaries with the same signature.
2440
+ * 3. Other: any JSON serializable type
2441
+ */
2442
+ outputData?: string | Message | Message[] | Document | Document[] | { [key: string]: any },
2443
+
2444
+ /**
2445
+ * Object of JSON serializable key-value metadata pairs relevant to the input/output operation described by the LLM Observability span.
2446
+ */
2447
+ metadata?: { [key: string]: any },
2448
+
2449
+ /**
2450
+ * Object of JSON seraliazable key-value metrics (number) pairs, such as `{input,output,total}Tokens`
2451
+ */
2452
+ metrics?: { [key: string]: number },
2453
+
2454
+ /**
2455
+ * Object of JSON serializable key-value tag pairs to set or update on the LLM Observability span regarding the span's context.
2456
+ */
2457
+ tags?: { [key: string]: any }
2458
+ }
2459
+
2460
+ /**
2461
+ * An object containing the span ID and trace ID of interest
2462
+ */
2463
+ interface ExportedLLMObsSpan {
2464
+ /**
2465
+ * Trace ID associated with the span of interest
2466
+ */
2467
+ traceId: string,
2468
+
2469
+ /**
2470
+ * Span ID associated with the span of interest
2471
+ */
2472
+ spanId: string,
2473
+ }
2474
+
2475
+ interface LLMObsSpanOptions extends SpanOptions {
2476
+ /**
2477
+ * LLM Observability span kind. One of `agent`, `workflow`, `task`, `tool`, `retrieval`, `embedding`, or `llm`.
2478
+ */
2479
+ kind: llmobs.spanKind,
2480
+
2481
+ /**
2482
+ * The ID of the underlying user session. Required for tracking sessions.
2483
+ */
2484
+ sessionId?: string,
2485
+
2486
+ /**
2487
+ * The name of the ML application that the agent is orchestrating.
2488
+ * If not provided, the default value will be set to mlApp provided during initalization, or `DD_LLMOBS_ML_APP`.
2489
+ */
2490
+ mlApp?: string,
2491
+
2492
+ /**
2493
+ * The name of the invoked LLM or embedding model. Only used on `llm` and `embedding` spans.
2494
+ */
2495
+ modelName?: string,
2496
+
2497
+ /**
2498
+ * The name of the invoked LLM or embedding model provider. Only used on `llm` and `embedding` spans.
2499
+ * If not provided for LLM or embedding spans, a default value of 'custom' will be set.
2500
+ */
2501
+ modelProvider?: string,
2502
+ }
2503
+
2504
+ interface LLMObsNamedSpanOptions extends LLMObsSpanOptions {
2505
+ /**
2506
+ * The name of the traced operation. This is a required option.
2507
+ */
2508
+ name: string,
2509
+ }
2510
+
2511
+ interface LLMObsNamelessSpanOptions extends LLMObsSpanOptions {
2512
+ /**
2513
+ * The name of the traced operation.
2514
+ */
2515
+ name?: string,
2516
+ }
2517
+
2518
+ /**
2519
+ * Options for enabling LLM Observability tracing.
2520
+ */
2521
+ interface LLMObsEnableOptions {
2522
+ /**
2523
+ * The name of your ML application.
2524
+ */
2525
+ mlApp?: string,
2526
+
2527
+ /**
2528
+ * Set to `true` to disbale sending data that requires a Datadog Agent.
2529
+ */
2530
+ agentlessEnabled?: boolean,
2531
+ }
2532
+
2533
+ /** @hidden */
2534
+ type spanKind = 'agent' | 'workflow' | 'task' | 'tool' | 'retrieval' | 'embedding' | 'llm'
2535
+ }
2175
2536
  }
2176
2537
 
2177
2538
  /**
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "5.23.1",
3
+ "version": "5.25.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
7
7
  "scripts": {
8
+ "env": "bash ./plugin-env",
8
9
  "preinstall": "node scripts/preinstall.js",
9
10
  "bench": "node benchmark",
10
11
  "bench:profiler": "node benchmark/profiler",
@@ -12,16 +13,16 @@
12
13
  "bench:e2e:ci-visibility": "node benchmark/e2e-ci/benchmark-run.js",
13
14
  "type:doc": "cd docs && yarn && yarn build",
14
15
  "type:test": "cd docs && yarn && yarn test",
15
- "lint": "node scripts/check_licenses.js && eslint . && yarn audit --groups dependencies",
16
- "lint-fix": "node scripts/check_licenses.js && eslint . --fix && yarn audit --groups dependencies",
16
+ "lint": "node scripts/check_licenses.js && eslint . && yarn audit",
17
+ "lint-fix": "node scripts/check_licenses.js && eslint . --fix && yarn audit",
17
18
  "services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",
18
19
  "test": "SERVICES=* yarn services && mocha --expose-gc 'packages/dd-trace/test/setup/node.js' 'packages/*/test/**/*.spec.js'",
19
20
  "test:appsec": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" \"packages/dd-trace/test/appsec/**/*.spec.js\"",
20
21
  "test:appsec:ci": "nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" -- npm run test:appsec",
21
22
  "test:appsec:plugins": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/appsec/**/*.@($(echo $PLUGINS)).plugin.spec.js\"",
22
23
  "test:appsec:plugins:ci": "yarn services && nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" -- npm run test:appsec:plugins",
23
- "test:debugger": "tap packages/dd-trace/test/debugger/**/*.spec.js",
24
- "test:debugger:ci": "npm run test:debugger -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/debugger/**/*.js\"",
24
+ "test:debugger": "mocha -r 'packages/dd-trace/test/setup/mocha.js' 'packages/dd-trace/test/debugger/**/*.spec.js'",
25
+ "test:debugger:ci": "nyc --no-clean --include 'packages/dd-trace/src/debugger/**/*.js' -- npm run test:debugger",
25
26
  "test:trace:core": "tap packages/dd-trace/test/*.spec.js \"packages/dd-trace/test/{ci-visibility,datastreams,encode,exporters,opentelemetry,opentracing,plugins,service-naming,telemetry}/**/*.spec.js\"",
26
27
  "test:trace:core:ci": "npm run test:trace:core -- --coverage --nyc-arg=--include=\"packages/dd-trace/src/**/*.js\"",
27
28
  "test:instrumentations": "mocha -r 'packages/dd-trace/test/setup/mocha.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
@@ -30,6 +31,10 @@
30
31
  "test:core:ci": "npm run test:core -- --coverage --nyc-arg=--include=\"packages/datadog-core/src/**/*.js\"",
31
32
  "test:lambda": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/lambda/**/*.spec.js\"",
32
33
  "test:lambda:ci": "nyc --no-clean --include \"packages/dd-trace/src/lambda/**/*.js\" -- npm run test:lambda",
34
+ "test:llmobs:sdk": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" --exclude \"packages/dd-trace/test/llmobs/plugins/**/*.spec.js\" \"packages/dd-trace/test/llmobs/**/*.spec.js\" ",
35
+ "test:llmobs:sdk:ci": "nyc --no-clean --include \"packages/dd-trace/src/llmobs/**/*.js\" -- npm run test:llmobs:sdk",
36
+ "test:llmobs:plugins": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/llmobs/plugins/**/*.spec.js\"",
37
+ "test:llmobs:plugins:ci": "yarn services && nyc --no-clean --include \"packages/dd-trace/src/llmobs/**/*.js\" -- npm run test:llmobs:plugins",
33
38
  "test:plugins": "mocha -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-instrumentations/test/@($(echo $PLUGINS)).spec.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/**/*.spec.js\"",
34
39
  "test:plugins:ci": "yarn services && nyc --no-clean --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS)).js\" --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS))/**/*.js\" --include \"packages/datadog-plugin-@($(echo $PLUGINS))/src/**/*.js\" -- npm run test:plugins",
35
40
  "test:plugins:upstream": "node ./packages/dd-trace/test/plugins/suite.js",
@@ -76,11 +81,11 @@
76
81
  "node": ">=18"
77
82
  },
78
83
  "dependencies": {
79
- "@datadog/native-appsec": "8.1.1",
80
- "@datadog/native-iast-rewriter": "2.4.1",
81
- "@datadog/native-iast-taint-tracking": "3.1.0",
82
- "@datadog/native-metrics": "^2.0.0",
83
- "@datadog/pprof": "5.3.0",
84
+ "@datadog/native-appsec": "8.2.1",
85
+ "@datadog/native-iast-rewriter": "2.5.0",
86
+ "@datadog/native-iast-taint-tracking": "3.2.0",
87
+ "@datadog/native-metrics": "^3.0.1",
88
+ "@datadog/pprof": "5.4.1",
84
89
  "@datadog/sketches-js": "^2.1.0",
85
90
  "@opentelemetry/api": ">=1.0.0 <1.9.0",
86
91
  "@opentelemetry/core": "^1.14.0",
@@ -91,7 +96,6 @@
91
96
  "int64-buffer": "^0.1.9",
92
97
  "istanbul-lib-coverage": "3.2.0",
93
98
  "jest-docblock": "^29.7.0",
94
- "jsonpath-plus": "^9.0.0",
95
99
  "koalas": "^1.0.2",
96
100
  "limiter": "1.1.5",
97
101
  "lodash.sortby": "^4.7.0",
@@ -109,12 +113,13 @@
109
113
  "tlhunter-sorted-set": "^0.1.0"
110
114
  },
111
115
  "devDependencies": {
116
+ "@apollo/server": "^4.11.0",
112
117
  "@types/node": "^16.18.103",
113
118
  "autocannon": "^4.5.2",
114
119
  "aws-sdk": "^2.1446.0",
115
120
  "axios": "^1.7.4",
116
121
  "benchmark": "^2.1.4",
117
- "body-parser": "^1.20.2",
122
+ "body-parser": "^1.20.3",
118
123
  "chai": "^4.3.7",
119
124
  "chalk": "^5.3.0",
120
125
  "checksum": "^1.0.0",
@@ -140,7 +145,7 @@
140
145
  "nyc": "^15.1.0",
141
146
  "proxyquire": "^1.8.0",
142
147
  "rimraf": "^3.0.0",
143
- "sinon": "^15.2.0",
148
+ "sinon": "^16.1.3",
144
149
  "sinon-chai": "^3.7.0",
145
150
  "tap": "^16.3.7",
146
151
  "tiktoken": "^1.0.15"
@@ -0,0 +1,38 @@
1
+ 'use strict'
2
+
3
+ const { getUserLandFrames } = require('../dd-trace/src/plugins/util/stacktrace')
4
+
5
+ const limit = Number(process.env._DD_CODE_ORIGIN_MAX_USER_FRAMES) || 8
6
+
7
+ module.exports = {
8
+ entryTags,
9
+ exitTags
10
+ }
11
+
12
+ function entryTags (topOfStackFunc) {
13
+ return tag('entry', topOfStackFunc)
14
+ }
15
+
16
+ function exitTags (topOfStackFunc) {
17
+ return tag('exit', topOfStackFunc)
18
+ }
19
+
20
+ function tag (type, topOfStackFunc) {
21
+ const frames = getUserLandFrames(topOfStackFunc, limit)
22
+ const tags = {
23
+ '_dd.code_origin.type': type
24
+ }
25
+ for (let i = 0; i < frames.length; i++) {
26
+ const frame = frames[i]
27
+ tags[`_dd.code_origin.frames.${i}.file`] = frame.file
28
+ tags[`_dd.code_origin.frames.${i}.line`] = String(frame.line)
29
+ tags[`_dd.code_origin.frames.${i}.column`] = String(frame.column)
30
+ if (frame.method) {
31
+ tags[`_dd.code_origin.frames.${i}.method`] = frame.method
32
+ }
33
+ if (frame.type) {
34
+ tags[`_dd.code_origin.frames.${i}.type`] = frame.type
35
+ }
36
+ }
37
+ return tags
38
+ }
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
- const LocalStorage = require('./src/storage')
3
+ const { AsyncLocalStorage } = require('async_hooks')
4
4
 
5
- const storage = new LocalStorage()
5
+ const storage = new AsyncLocalStorage()
6
6
 
7
7
  module.exports = { storage }
@@ -0,0 +1,33 @@
1
+ 'use strict'
2
+
3
+ const digitRegex = /^\d+$/
4
+
5
+ /**
6
+ * Converts a flat object of tags into a nested object. For example:
7
+ * { 'a.b.c': 'value' } -> { a: { b: { c: 'value' } } }
8
+ * Also supports array-keys. For example:
9
+ * { 'a.0.b': 'value' } -> { a: [{ b: 'value' }] }
10
+ *
11
+ * @param {Object} tags - Key/value pairs of tags
12
+ * @returns Object - Parsed tags
13
+ */
14
+ module.exports = tags => {
15
+ const parsedTags = {}
16
+ for (const [tag, value] of Object.entries(tags)) {
17
+ const keys = tag.split('.')
18
+ let current = parsedTags
19
+ let depth = 0
20
+ for (const key of keys) {
21
+ if (!current[key]) {
22
+ if (depth === keys.length - 1) {
23
+ current[key] = value
24
+ break
25
+ }
26
+ current[key] = keys[depth + 1]?.match(digitRegex) ? [] : {}
27
+ }
28
+ current = current[key]
29
+ depth++
30
+ }
31
+ }
32
+ return parsedTags
33
+ }
@@ -96,7 +96,9 @@ module.exports.setup = function (build) {
96
96
 
97
97
  let pathToPackageJson
98
98
  try {
99
- pathToPackageJson = require.resolve(`${extracted.pkg}/package.json`, { paths: [args.resolveDir] })
99
+ // we can't use require.resolve('pkg/package.json') as ESM modules don't make the file available
100
+ pathToPackageJson = require.resolve(`${extracted.pkg}`, { paths: [args.resolveDir] })
101
+ pathToPackageJson = extractPackageAndModulePath(pathToPackageJson).pkgJson
100
102
  } catch (err) {
101
103
  if (err.code === 'MODULE_NOT_FOUND') {
102
104
  if (!internal) {
@@ -111,7 +113,7 @@ module.exports.setup = function (build) {
111
113
  }
112
114
  }
113
115
 
114
- const packageJson = require(pathToPackageJson)
116
+ const packageJson = JSON.parse(fs.readFileSync(pathToPackageJson).toString())
115
117
 
116
118
  if (DEBUG) console.log(`RESOLVE: ${args.path}@${packageJson.version}`)
117
119