dd-trace 5.108.0 → 5.110.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 (174) hide show
  1. package/ci/init.js +4 -3
  2. package/index.d.ts +88 -25
  3. package/loader-hook.mjs +88 -2
  4. package/package.json +19 -14
  5. package/packages/datadog-esbuild/index.js +26 -0
  6. package/packages/datadog-esbuild/src/utils.js +46 -3
  7. package/packages/datadog-instrumentations/src/ai.js +43 -48
  8. package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js-context-methods.js +18 -0
  9. package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js.js +111 -0
  10. package/packages/datadog-instrumentations/src/aws-sdk.js +3 -1
  11. package/packages/datadog-instrumentations/src/connect.js +4 -3
  12. package/packages/datadog-instrumentations/src/electron.js +1 -1
  13. package/packages/datadog-instrumentations/src/fastify.js +4 -12
  14. package/packages/datadog-instrumentations/src/graphql.js +17 -6
  15. package/packages/datadog-instrumentations/src/helpers/check-require-cache.js +81 -8
  16. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
  17. package/packages/datadog-instrumentations/src/helpers/instrument.js +27 -2
  18. package/packages/datadog-instrumentations/src/helpers/optional-peer-bundler.js +65 -0
  19. package/packages/datadog-instrumentations/src/helpers/register.js +6 -4
  20. package/packages/datadog-instrumentations/src/helpers/require-optional-peer.js +17 -0
  21. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/aws-durable-execution-sdk-js.js +31 -0
  22. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +1 -0
  23. package/packages/datadog-instrumentations/src/helpers/rewriter/loader.mjs +18 -2
  24. package/packages/datadog-instrumentations/src/http/client.js +12 -2
  25. package/packages/datadog-instrumentations/src/ioredis.js +0 -1
  26. package/packages/datadog-instrumentations/src/iovalkey.js +1 -2
  27. package/packages/datadog-instrumentations/src/koa.js +3 -2
  28. package/packages/datadog-instrumentations/src/mariadb.js +4 -2
  29. package/packages/datadog-instrumentations/src/mocha/main.js +3 -3
  30. package/packages/datadog-instrumentations/src/next.js +44 -10
  31. package/packages/datadog-instrumentations/src/openai.js +77 -18
  32. package/packages/datadog-instrumentations/src/otel-sdk-trace.js +7 -6
  33. package/packages/datadog-instrumentations/src/playwright.js +1 -1
  34. package/packages/datadog-instrumentations/src/redis.js +0 -1
  35. package/packages/datadog-instrumentations/src/restify.js +4 -3
  36. package/packages/datadog-instrumentations/src/router.js +18 -5
  37. package/packages/datadog-instrumentations/src/selenium.js +1 -2
  38. package/packages/datadog-instrumentations/src/tedious.js +28 -0
  39. package/packages/datadog-instrumentations/src/vitest.js +323 -7
  40. package/packages/datadog-plugin-avsc/src/schema_iterator.js +2 -2
  41. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/checkpoint.js +31 -0
  42. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/client.js +55 -0
  43. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/context.js +114 -0
  44. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/handler.js +128 -0
  45. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/index.js +19 -0
  46. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/trace-checkpoint.js +224 -0
  47. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/util.js +43 -0
  48. package/packages/datadog-plugin-aws-sdk/src/base.js +14 -16
  49. package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +43 -6
  50. package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +100 -37
  51. package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +108 -99
  52. package/packages/datadog-plugin-bullmq/src/filter.js +35 -0
  53. package/packages/datadog-plugin-bullmq/src/producer.js +84 -4
  54. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +9 -1
  55. package/packages/datadog-plugin-fs/src/index.js +1 -0
  56. package/packages/datadog-plugin-http/src/client.js +8 -3
  57. package/packages/datadog-plugin-http2/src/client.js +5 -2
  58. package/packages/datadog-plugin-mysql/src/index.js +7 -2
  59. package/packages/datadog-plugin-protobufjs/src/schema_iterator.js +2 -2
  60. package/packages/datadog-plugin-redis/src/index.js +1 -2
  61. package/packages/datadog-plugin-undici/src/index.js +5 -2
  62. package/packages/datadog-plugin-vitest/src/index.js +11 -2
  63. package/packages/datadog-webpack/index.js +17 -1
  64. package/packages/datadog-webpack/src/optional-peer-loader.js +17 -0
  65. package/packages/dd-trace/src/aiguard/channels.js +0 -1
  66. package/packages/dd-trace/src/aiguard/index.js +11 -49
  67. package/packages/dd-trace/src/aiguard/integrations/evaluate.js +46 -0
  68. package/packages/dd-trace/src/aiguard/integrations/openai.js +66 -0
  69. package/packages/dd-trace/src/aiguard/integrations/vercel-ai.js +78 -0
  70. package/packages/{datadog-instrumentations/src/helpers/ai-messages.js → dd-trace/src/aiguard/messages/openai.js} +85 -193
  71. package/packages/dd-trace/src/aiguard/messages/vercel-ai.js +185 -0
  72. package/packages/dd-trace/src/aiguard/sdk.js +13 -1
  73. package/packages/dd-trace/src/appsec/api_security/index.js +55 -0
  74. package/packages/dd-trace/src/appsec/api_security/sampler.js +147 -0
  75. package/packages/dd-trace/src/appsec/channels.js +1 -0
  76. package/packages/dd-trace/src/appsec/downstream_requests.js +111 -58
  77. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/ldap-sensitive-analyzer.js +54 -12
  78. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/url-sensitive-analyzer.js +5 -1
  79. package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +29 -4
  80. package/packages/dd-trace/src/appsec/index.js +10 -6
  81. package/packages/dd-trace/src/appsec/rasp/ssrf.js +19 -11
  82. package/packages/dd-trace/src/appsec/reporter.js +1 -0
  83. package/packages/dd-trace/src/appsec/telemetry/api_security.js +34 -0
  84. package/packages/dd-trace/src/appsec/telemetry/index.js +26 -0
  85. package/packages/dd-trace/src/ci-visibility/requests/request.js +1 -17
  86. package/packages/dd-trace/src/config/defaults.js +22 -3
  87. package/packages/dd-trace/src/config/generated-config-types.d.ts +538 -1
  88. package/packages/dd-trace/src/config/helper.js +133 -33
  89. package/packages/dd-trace/src/config/index.js +4 -1
  90. package/packages/dd-trace/src/config/parsers.js +19 -1
  91. package/packages/dd-trace/src/config/supported-configurations.json +45 -5
  92. package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +49 -35
  93. package/packages/dd-trace/src/debugger/devtools_client/index.js +31 -66
  94. package/packages/dd-trace/src/debugger/devtools_client/probe_sampler.js +83 -0
  95. package/packages/dd-trace/src/debugger/devtools_client/state.js +1 -0
  96. package/packages/dd-trace/src/debugger/index.js +5 -0
  97. package/packages/dd-trace/src/debugger/probe_sampler.js +112 -0
  98. package/packages/dd-trace/src/debugger/probe_sampler_constants.js +19 -0
  99. package/packages/dd-trace/src/dogstatsd.js +15 -8
  100. package/packages/dd-trace/src/encode/agentless-ci-visibility.js +77 -26
  101. package/packages/dd-trace/src/exporters/agentless/index.js +7 -5
  102. package/packages/dd-trace/src/exporters/agentless/intake.js +43 -0
  103. package/packages/dd-trace/src/exporters/agentless/writer.js +5 -4
  104. package/packages/dd-trace/src/exporters/common/request.js +1 -20
  105. package/packages/dd-trace/src/exporters/common/url.js +34 -0
  106. package/packages/dd-trace/src/exporters/span-stats/writer.js +1 -3
  107. package/packages/dd-trace/src/guardrails/index.js +8 -5
  108. package/packages/dd-trace/src/index.js +6 -4
  109. package/packages/dd-trace/src/llmobs/constants/tags.js +6 -0
  110. package/packages/dd-trace/src/llmobs/index.js +16 -5
  111. package/packages/dd-trace/src/llmobs/plugins/genai/util.js +3 -3
  112. package/packages/dd-trace/src/llmobs/plugins/langchain/index.js +5 -1
  113. package/packages/dd-trace/src/llmobs/sdk.js +5 -3
  114. package/packages/dd-trace/src/llmobs/span_processor.js +4 -0
  115. package/packages/dd-trace/src/llmobs/tagger.js +55 -0
  116. package/packages/dd-trace/src/llmobs/telemetry.js +1 -0
  117. package/packages/dd-trace/src/log/index.js +18 -20
  118. package/packages/dd-trace/src/openfeature/flagging_provider.js +3 -1
  119. package/packages/dd-trace/src/opentelemetry/bridge-span-base.js +5 -4
  120. package/packages/dd-trace/src/opentelemetry/metrics/instruments.js +2 -1
  121. package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +4 -3
  122. package/packages/dd-trace/src/opentelemetry/metrics/time.js +19 -0
  123. package/packages/dd-trace/src/opentelemetry/otlp/common.proto +2 -2
  124. package/packages/dd-trace/src/opentelemetry/otlp/logs.proto +1 -1
  125. package/packages/dd-trace/src/opentelemetry/otlp/logs_service.proto +1 -1
  126. package/packages/dd-trace/src/opentelemetry/otlp/metrics.proto +1 -1
  127. package/packages/dd-trace/src/opentelemetry/otlp/metrics_service.proto +1 -1
  128. package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +11 -4
  129. package/packages/dd-trace/src/opentelemetry/span-helpers.js +29 -13
  130. package/packages/dd-trace/src/opentelemetry/span.js +14 -3
  131. package/packages/dd-trace/src/opentelemetry/span_context.js +1 -0
  132. package/packages/dd-trace/src/opentelemetry/trace/index.js +2 -1
  133. package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +3 -2
  134. package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +26 -13
  135. package/packages/dd-trace/src/opentracing/propagation/text_map.js +3 -3
  136. package/packages/dd-trace/src/opentracing/span_context.js +17 -0
  137. package/packages/dd-trace/src/plugin_manager.js +7 -1
  138. package/packages/dd-trace/src/plugins/ci_plugin.js +36 -3
  139. package/packages/dd-trace/src/plugins/index.js +3 -0
  140. package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +276 -0
  141. package/packages/dd-trace/src/plugins/util/test.js +80 -0
  142. package/packages/dd-trace/src/plugins/util/url.js +68 -1
  143. package/packages/dd-trace/src/plugins/util/web.js +19 -36
  144. package/packages/dd-trace/src/priority_sampler.js +1 -13
  145. package/packages/dd-trace/src/profiling/config.js +129 -198
  146. package/packages/dd-trace/src/profiling/constants.js +4 -7
  147. package/packages/dd-trace/src/profiling/exporter_cli.js +10 -10
  148. package/packages/dd-trace/src/profiling/exporters/agent.js +23 -16
  149. package/packages/dd-trace/src/profiling/exporters/event_serializer.js +45 -14
  150. package/packages/dd-trace/src/profiling/exporters/file.js +16 -5
  151. package/packages/dd-trace/src/profiling/oom.js +71 -0
  152. package/packages/dd-trace/src/profiling/profiler.js +35 -23
  153. package/packages/dd-trace/src/profiling/profilers/events.js +14 -7
  154. package/packages/dd-trace/src/profiling/profilers/space.js +27 -18
  155. package/packages/dd-trace/src/profiling/profilers/wall.js +35 -25
  156. package/packages/dd-trace/src/ritm.js +4 -2
  157. package/packages/dd-trace/src/serverless.js +1 -2
  158. package/packages/dd-trace/src/service-naming/schemas/util.js +36 -5
  159. package/packages/dd-trace/src/service-naming/schemas/v0/serverless.js +12 -0
  160. package/packages/dd-trace/src/service-naming/schemas/v1/serverless.js +12 -0
  161. package/packages/dd-trace/src/service-naming/schemas/v1/web.js +5 -3
  162. package/packages/dd-trace/src/span_format.js +2 -1
  163. package/packages/dd-trace/src/span_processor.js +6 -0
  164. package/packages/dd-trace/src/telemetry/send-data.js +12 -10
  165. package/packages/dd-trace/src/tracer.js +15 -1
  166. package/packages/dd-trace/src/util.js +14 -0
  167. package/register.js +58 -1
  168. package/vendor/dist/@apm-js-collab/code-transformer/index.js +1 -1
  169. package/vendor/dist/@datadog/sketches-js/index.js +1 -1
  170. package/vendor/dist/pprof-format/index.js +1 -1
  171. package/vendor/dist/protobufjs/index.js +1 -1
  172. package/vendor/dist/protobufjs/minimal/index.js +1 -1
  173. package/packages/datadog-instrumentations/src/helpers/openai-ai-guard.js +0 -284
  174. package/packages/dd-trace/src/appsec/api_security_sampler.js +0 -117
package/ci/init.js CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  /* eslint-disable no-console */
4
4
  const tracer = require('../packages/dd-trace')
5
- const { isTrue, isFalse } = require('../packages/dd-trace/src/util')
6
5
  const log = require('../packages/dd-trace/src/log')
7
6
  const { getEnvironmentVariable, getValueFromEnvSources } = require('../packages/dd-trace/src/config/helper')
8
7
 
@@ -43,8 +42,10 @@ const baseOptions = {
43
42
  flushInterval: isJestWorker ? JEST_FLUSH_INTERVAL : DEFAULT_FLUSH_INTERVAL,
44
43
  }
45
44
 
46
- let shouldInit = !isFalse(getValueFromEnvSources('DD_CIVISIBILITY_ENABLED'))
47
- const isAgentlessEnabled = isTrue(getValueFromEnvSources('DD_CIVISIBILITY_AGENTLESS_ENABLED'))
45
+ // skipDefault: CI visibility stays on unless DD_CIVISIBILITY_ENABLED is explicitly false; the
46
+ // registered default (false) would otherwise turn it off whenever the variable is unset.
47
+ let shouldInit = getValueFromEnvSources('DD_CIVISIBILITY_ENABLED', true) !== false
48
+ const isAgentlessEnabled = getValueFromEnvSources('DD_CIVISIBILITY_AGENTLESS_ENABLED')
48
49
 
49
50
  if (!isTestWorker && isPackageManager()) {
50
51
  log.debug('dd-trace is not initialized in a package manager.')
package/index.d.ts CHANGED
@@ -235,6 +235,7 @@ interface Plugins {
235
235
  "anthropic": tracer.plugins.anthropic;
236
236
  "apollo": tracer.plugins.apollo;
237
237
  "avsc": tracer.plugins.avsc;
238
+ "aws-durable-execution-sdk-js": tracer.plugins.aws_durable_execution_sdk_js;
238
239
  "aws-sdk": tracer.plugins.aws_sdk;
239
240
  "azure-cosmos": tracer.plugins.azure_cosmos;
240
241
  "azure-event-hubs": tracer.plugins.azure_event_hubs;
@@ -425,7 +426,7 @@ declare namespace tracer {
425
426
  */
426
427
  export interface SamplingRule {
427
428
  /**
428
- * Sampling rate for this rule.
429
+ * Sampling rate for this rule. A range between 0 and 1 representing the percent of traces sampled.
429
430
  */
430
431
  sampleRate: number
431
432
 
@@ -438,6 +439,22 @@ declare namespace tracer {
438
439
  * Operation name on which to apply this rule. The rule will apply to all operation names if not provided.
439
440
  */
440
441
  name?: string | RegExp
442
+
443
+ /**
444
+ * Resource name on which to apply this rule. The rule will apply to all resource names if not provided.
445
+ */
446
+ resource?: string | RegExp
447
+
448
+ /**
449
+ * Span tags on which to apply this rule, keyed by tag name. Each value is a glob pattern or regular
450
+ * expression, and the rule only applies when every entry matches the span's tags.
451
+ */
452
+ tags?: { [key: string]: string | RegExp }
453
+
454
+ /**
455
+ * Maximum number of traces matching this rule to sample per second.
456
+ */
457
+ maxPerSecond?: number
441
458
  }
442
459
 
443
460
  /**
@@ -619,10 +636,10 @@ declare namespace tracer {
619
636
  rateLimit?: number,
620
637
 
621
638
  /**
622
- * Sampling rules to apply to priority sampling. Each rule is a JSON,
623
- * consisting of `service` and `name`, which are regexes to match against
624
- * a trace's `service` and `name`, and a corresponding `sampleRate`. If not
625
- * specified, will defer to global sampling rate for all spans.
639
+ * Sampling rules to apply to priority sampling. Each rule matches against a trace's
640
+ * `service`, `name`, `resource`, and `tags`, and applies the rule's `sampleRate`. Use a
641
+ * `sampleRate` of `0` to drop matching traces (for example to filter out unwanted resources).
642
+ * If not specified, will defer to global sampling rate for all spans.
626
643
  * @default []
627
644
  * @env DD_TRACE_SAMPLING_RULES
628
645
  * Programmatic configuration takes precedence over the environment variables listed above.
@@ -659,25 +676,25 @@ declare namespace tracer {
659
676
  */
660
677
  runtimeMetrics?: boolean | {
661
678
 
662
- /**
679
+ /**
663
680
  * @env DD_RUNTIME_METRICS_ENABLED
664
681
  * Programmatic configuration takes precedence over the environment variables listed above.
665
682
  */
666
683
  enabled?: boolean,
667
684
 
668
- /**
685
+ /**
669
686
  * @env DD_RUNTIME_METRICS_GC_ENABLED
670
687
  * Programmatic configuration takes precedence over the environment variables listed above.
671
688
  */
672
689
  gc?: boolean,
673
690
 
674
- /**
691
+ /**
675
692
  * @env DD_RUNTIME_METRICS_EVENT_LOOP_ENABLED
676
693
  * Programmatic configuration takes precedence over the environment variables listed above.
677
694
  */
678
695
  eventLoop?: boolean,
679
696
 
680
- /**
697
+ /**
681
698
  * Whether to use native metrics. When set to false, forces the JS implementation
682
699
  * @default true
683
700
  * @env DD_RUNTIME_METRICS_NATIVE
@@ -2351,11 +2368,25 @@ declare namespace tracer {
2351
2368
  */
2352
2369
  interface avsc extends Integration {}
2353
2370
 
2371
+ /**
2372
+ * This plugin automatically instruments the
2373
+ * [aws-durable-execution-sdk-js](https://github.com/aws/aws-durable-execution-sdk-js) module.
2374
+ */
2375
+ interface aws_durable_execution_sdk_js extends Integration {}
2376
+
2354
2377
  /**
2355
2378
  * This plugin automatically instruments the
2356
2379
  * [aws-sdk](https://github.com/aws/aws-sdk-js) module.
2357
2380
  */
2358
2381
  interface aws_sdk extends Instrumentation {
2382
+ /**
2383
+ * The service name to be used for this plugin. When a function is used it is called with the AWS
2384
+ * request parameters (e.g. `{ TableName }` for DynamoDB, `{ Bucket }` for S3) and its return value
2385
+ * is used as the service name. Returning a nullish value falls back to the default service name, so
2386
+ * individual resources can be mapped without renaming every call to the service.
2387
+ */
2388
+ service?: string | ((params: anyObject) => string | undefined | null);
2389
+
2359
2390
  /**
2360
2391
  * Whether to inject all messages during batch AWS SQS, Kinesis, and SNS send operations. Normal
2361
2392
  * behavior is to inject the first message in batch send operations.
@@ -2428,7 +2459,21 @@ declare namespace tracer {
2428
2459
  * This plugin automatically instruments the
2429
2460
  * [bullmq](https://github.com/npmjs/package/bullmq) message queue library.
2430
2461
  */
2431
- interface bullmq extends Instrumentation {}
2462
+ interface bullmq extends Instrumentation {
2463
+ /**
2464
+ * Filter applied to BullMQ producer operations (`Queue.add`, `Queue.addBulk`,
2465
+ * `FlowProducer.add`). Return `false` to skip span creation, trace context
2466
+ * injection, and DSM checkpoint handling for the matching job. Consumer-side
2467
+ * (`Worker`) instrumentation is unaffected.
2468
+ *
2469
+ * @param job.name - The BullMQ job name.
2470
+ * @param job.data - The BullMQ job data.
2471
+ * @param job.opts - The BullMQ job options.
2472
+ * @param job.queueName - The name of the queue the job is being added to.
2473
+ * @returns true to instrument the producer operation, false to skip it.
2474
+ */
2475
+ producerFilter?: (job: { name?: string; data?: unknown; opts?: unknown; queueName?: string }) => boolean;
2476
+ }
2432
2477
 
2433
2478
  interface bunyan extends Integration {}
2434
2479
 
@@ -2560,24 +2605,24 @@ declare namespace tracer {
2560
2605
  * This plugin automatically instruments the
2561
2606
  * [@google-cloud/vertexai](https://github.com/googleapis/nodejs-vertexai) module.
2562
2607
  */
2563
- interface google_cloud_vertexai extends Integration {}
2608
+ interface google_cloud_vertexai extends Integration {}
2564
2609
 
2565
- /**
2610
+ /**
2566
2611
  * This plugin automatically instruments the
2567
2612
  * [@google-genai](https://github.com/googleapis/js-genai) module.
2568
2613
  */
2569
- interface google_genai extends Integration {}
2570
-
2571
- /** @hidden */
2572
- interface ExecutionArgs {
2573
- schema: any,
2574
- document: any,
2575
- rootValue?: any,
2576
- contextValue?: any,
2577
- variableValues?: any,
2578
- operationName?: string,
2579
- fieldResolver?: any,
2580
- typeResolver?: any,
2614
+ interface google_genai extends Integration {}
2615
+
2616
+ /** @hidden */
2617
+ interface ExecutionArgs {
2618
+ schema: any,
2619
+ document: any,
2620
+ rootValue?: any,
2621
+ contextValue?: any,
2622
+ variableValues?: any,
2623
+ operationName?: string,
2624
+ fieldResolver?: any,
2625
+ typeResolver?: any,
2581
2626
  }
2582
2627
 
2583
2628
  /**
@@ -3196,7 +3241,16 @@ declare namespace tracer {
3196
3241
  * This plugin automatically instruments the
3197
3242
  * [router](https://github.com/pillarjs/router) module.
3198
3243
  */
3199
- interface router extends Integration {}
3244
+ interface router extends Integration {
3245
+ /**
3246
+ * Whether to enable instrumentation of router.middleware spans.
3247
+ * When set to `false`, middleware spans are suppressed but route
3248
+ * tracking (resource name, `http.route` tag) is still performed.
3249
+ *
3250
+ * @default true
3251
+ */
3252
+ middleware?: boolean;
3253
+ }
3200
3254
 
3201
3255
  /**
3202
3256
  * This plugin automatically instruments the
@@ -4180,6 +4234,15 @@ declare namespace tracer {
4180
4234
  * Programmatic configuration takes precedence over the environment variables listed above.
4181
4235
  */
4182
4236
  agentlessEnabled?: boolean,
4237
+
4238
+ /**
4239
+ * The proportion of LLM Observability traces to sample, between `0` and `1` (inclusive).
4240
+ * The decision is computed once per trace, propagated across services, and recorded on every
4241
+ * span; spans are always sent and the decision is honored at ingestion time. Defaults to `1`.
4242
+ * @env DD_LLMOBS_SAMPLE_RATE
4243
+ * Programmatic configuration takes precedence over the environment variables listed above.
4244
+ */
4245
+ sampleRate?: number,
4183
4246
  }
4184
4247
  /** @hidden */
4185
4248
  type spanKind = 'agent' | 'workflow' | 'task' | 'tool' | 'retrieval' | 'embedding' | 'llm'
package/loader-hook.mjs CHANGED
@@ -1,3 +1,9 @@
1
+ /* eslint n/no-unsupported-features/node-builtins: ['error', { ignores: ['module.registerHooks'] }] */
2
+
3
+ import * as Module from 'node:module'
4
+ import { pathToFileURL } from 'node:url'
5
+
6
+ import { createHook, supportsSyncHooks } from 'import-in-the-middle/create-hook.mjs'
1
7
  import { initialize as origInitialize, load as origLoad, resolve } from 'import-in-the-middle/hook.mjs'
2
8
  import regexpEscapeModule from './vendor/dist/escape-string-regexp/index.js'
3
9
  import hooks from './packages/datadog-instrumentations/src/helpers/hooks.js'
@@ -8,11 +14,18 @@ import { isRelativeRequire } from './packages/datadog-instrumentations/src/helpe
8
14
  // This file must support Node.js 12.0.0 syntax
9
15
 
10
16
  const regexpEscape = regexpEscapeModule.default
17
+ const require = Module.createRequire(import.meta.url)
18
+ let syncImportInTheMiddleHook
11
19
 
12
20
  // For some reason `getEnvironmentVariable` is not otherwise available to ESM.
13
21
  const env = configHelper.getEnvironmentVariable
14
22
 
15
23
  function initialize (data = {}) {
24
+ prepareImportInTheMiddleOptions(data)
25
+ return origInitialize(data)
26
+ }
27
+
28
+ function prepareImportInTheMiddleOptions (data = {}) {
16
29
  if (data.include == null) data.include = []
17
30
  if (data.exclude == null) data.exclude = []
18
31
 
@@ -20,13 +33,86 @@ function initialize (data = {}) {
20
33
  addSecurityControls(data)
21
34
  addExclusions(data)
22
35
 
23
- return origInitialize(data)
36
+ return data
24
37
  }
25
38
 
26
39
  function load (url, context, nextLoad) {
27
40
  return rewriterLoader.load(url, context, (url, context) => origLoad(url, context, nextLoad))
28
41
  }
29
42
 
43
+ function loadSync (url, context, nextLoad) {
44
+ if (isCommonJSLoad(context)) {
45
+ return getSyncImportInTheMiddleHook().loadSync(url, context, nextLoad)
46
+ }
47
+
48
+ return rewriterLoader.loadSync(url, context, (url, context) => {
49
+ return getSyncImportInTheMiddleHook().loadSync(url, context, nextLoad)
50
+ })
51
+ }
52
+
53
+ function isCommonJSLoad (context) {
54
+ if (context.format) return context.format === 'commonjs'
55
+
56
+ // Sync hooks report CommonJS require() dependency loads with a `require`
57
+ // condition but no format. If a format is present, trust it instead: ESM
58
+ // loaded through require() reports `format: 'module'` and still needs rewrite.
59
+ const conditions = context.conditions
60
+ if (!conditions) return false
61
+
62
+ for (let i = 0; i < conditions.length; i++) {
63
+ if (conditions[i] === 'require') return true
64
+ }
65
+
66
+ return false
67
+ }
68
+
69
+ function getSyncImportInTheMiddleHook () {
70
+ if (syncImportInTheMiddleHook) {
71
+ return syncImportInTheMiddleHook
72
+ }
73
+
74
+ const importInTheMiddleRegisterHooksUrl = pathToFileURL(
75
+ require.resolve('import-in-the-middle/register-hooks.mjs')
76
+ ).href
77
+ syncImportInTheMiddleHook = createHook({ url: importInTheMiddleRegisterHooksUrl })
78
+ return syncImportInTheMiddleHook
79
+ }
80
+
81
+ function registerSyncLoaderHooks (data = {}) {
82
+ // The synchronous loader strips the source of a require() pulled into the iitm
83
+ // ESM graph so Node loads it natively, but module.registerHooks rejected that
84
+ // nullish CommonJS source until nodejs/node#59929 (released in 22.22.3, 24.11.1,
85
+ // 25.1.0 and 26.0.0). On versions that ship registerHooks but predate the fix,
86
+ // fall back to the asynchronous loader instead of crashing mid-graph.
87
+ if (!supportsSyncHooks()) {
88
+ return false
89
+ }
90
+
91
+ const syncHook = getSyncImportInTheMiddleHook()
92
+
93
+ if (
94
+ typeof Module.registerHooks !== 'function' ||
95
+ typeof syncHook.applyOptions !== 'function' ||
96
+ typeof syncHook.loadSync !== 'function' ||
97
+ typeof syncHook.resolveSync !== 'function'
98
+ ) {
99
+ return false
100
+ }
101
+
102
+ // Node built-ins are instrumented under the synchronous loader as well: iitm
103
+ // reads a built-in's exports through process.getBuiltinModule(), which
104
+ // bypasses the registered hooks and therefore cannot re-enter them. The
105
+ // synchronous and asynchronous loaders share the same option preparation so
106
+ // that `import http from 'node:http'` is wrapped on both paths.
107
+ syncHook.applyOptions(prepareImportInTheMiddleOptions(data))
108
+ Module.registerHooks({
109
+ resolve: syncHook.resolveSync,
110
+ load: loadSync,
111
+ })
112
+
113
+ return true
114
+ }
115
+
30
116
  function addInstrumentations (data) {
31
117
  const instrumentations = Object.keys(hooks)
32
118
 
@@ -74,4 +160,4 @@ export const iitmExclusions = [
74
160
  /@anthropic-ai\/sdk\/_shims/,
75
161
  ]
76
162
 
77
- export { initialize, load, resolve }
163
+ export { initialize, load, registerSyncLoaderHooks, resolve }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "5.108.0",
3
+ "version": "5.110.0",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -23,6 +23,7 @@
23
23
  "lint:inspect": "npx @eslint/config-inspector@latest",
24
24
  "lint:codeowners": "codeowners-audit",
25
25
  "lint:codeowners:ci": "codeowners-audit --glob='**/*.spec.js' --glob='benchmark/sirun/**' --glob='.agents/**' --glob='.claude/**'",
26
+ "lint:editorconfig": "editorconfig-checker",
26
27
  "release:proposal": "node scripts/release/proposal",
27
28
  "services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",
28
29
  "test": "echo '\nError: The root \"npm test\" command is intentionally disabled.\n\nInstead, run specific test suites:\n - npm run test:trace:core\n - npm run test:appsec\n - etc.\n\nOr run individual test files:\n npx mocha path/to/test.spec.js\n\nSee CONTRIBUTING.md (Testing section) for more details.\n' && exit 1",
@@ -102,6 +103,8 @@
102
103
  "test:integration:plugins": "yarn services && mocha \"packages/datadog-plugin-@(${PLUGINS})/test/integration-test/**/${SPEC:-*}*.spec.js\"",
103
104
  "test:integration:plugins:coverage": "yarn services && node ./integration-tests/coverage/run-suite.js \"packages/datadog-plugin-@(${PLUGINS})/test/integration-test/**/${SPEC:-*}*.spec.js\"",
104
105
  "test:unit:plugins": "mocha \"packages/datadog-instrumentations/test/@(${PLUGINS}).spec.js\" \"packages/datadog-plugin-@(${PLUGINS})/test/**/*.spec.js\" --exclude \"packages/datadog-plugin-@(${PLUGINS})/test/integration-test/**/*.spec.js\"",
106
+ "test:release": "mocha \"scripts/release/**/*.spec.js\"",
107
+ "test:scripts": "mocha \"scripts/helpers/**/*.spec.js\"",
105
108
  "test:shimmer": "mocha \"packages/datadog-shimmer/test/**/*.spec.js\"",
106
109
  "test:shimmer:ci": "nyc --silent node init && nyc -- npm run test:shimmer",
107
110
  "verify:workflow-job-names": "node scripts/verify-workflow-job-names.js",
@@ -128,8 +131,9 @@
128
131
  },
129
132
  "homepage": "https://github.com/DataDog/dd-trace-js#readme",
130
133
  "engines": {
131
- "node": ">=18 <27"
134
+ "node": ">=18"
132
135
  },
136
+ "nodeMaxMajor": 27,
133
137
  "files": [
134
138
  "/package.json",
135
139
  "ci/**/*",
@@ -160,7 +164,7 @@
160
164
  ],
161
165
  "dependencies": {
162
166
  "dc-polyfill": "^0.1.11",
163
- "import-in-the-middle": "^3.0.1",
167
+ "import-in-the-middle": "^3.1.0",
164
168
  "opentracing": ">=0.14.7"
165
169
  },
166
170
  "optionalDependencies": {
@@ -169,7 +173,7 @@
169
173
  "@datadog/native-iast-taint-tracking": "4.2.0",
170
174
  "@datadog/native-metrics": "3.1.2",
171
175
  "@datadog/openfeature-node-server": "2.0.0",
172
- "@datadog/pprof": "5.15.0",
176
+ "@datadog/pprof": "5.15.1",
173
177
  "@datadog/wasm-js-rewriter": "5.0.1",
174
178
  "@opentelemetry/api": ">=1.0.0 <1.10.0",
175
179
  "@opentelemetry/api-logs": "<1.0.0",
@@ -178,29 +182,30 @@
178
182
  "devDependencies": {
179
183
  "@actions/core": "^3.0.1",
180
184
  "@actions/github": "^9.1.1",
181
- "@babel/helpers": "^7.29.7",
185
+ "@babel/helpers": "^8.0.0",
182
186
  "@eslint/eslintrc": "^3.3.5",
183
187
  "@eslint/js": "^9.39.2",
184
188
  "@msgpack/msgpack": "^3.1.3",
185
- "@openfeature/core": "^1.10.0",
186
- "@openfeature/server-sdk": "~1.21.0",
189
+ "@openfeature/core": "^1.11.0",
190
+ "@openfeature/server-sdk": "~1.22.0",
187
191
  "@stylistic/eslint-plugin": "^5.10.0",
188
192
  "@types/mocha": "^10.0.10",
189
193
  "@types/node": "^18.19.106",
190
194
  "@types/sinon": "^21.0.1",
191
- "axios": "^1.17.0",
195
+ "axios": "^1.18.0",
192
196
  "benchmark": "^2.1.4",
193
- "body-parser": "^2.2.2",
197
+ "body-parser": "^2.3.0",
194
198
  "bun": "1.3.14",
195
199
  "codeowners-audit": "^2.9.0",
200
+ "editorconfig-checker": "^6.1.1",
196
201
  "eslint": "^9.39.2",
197
202
  "eslint-plugin-cypress": "^6.4.1",
198
203
  "eslint-plugin-import": "^2.32.0",
199
- "eslint-plugin-jsdoc": "^63.0.1",
204
+ "eslint-plugin-jsdoc": "^63.0.6",
200
205
  "eslint-plugin-mocha": "^11.3.0",
201
- "eslint-plugin-n": "^18.0.1",
206
+ "eslint-plugin-n": "^18.1.0",
202
207
  "eslint-plugin-promise": "^7.3.0",
203
- "eslint-plugin-sonarjs": "^4.0.3",
208
+ "eslint-plugin-sonarjs": "^4.1.0",
204
209
  "eslint-plugin-unicorn": "^64.0.0",
205
210
  "express": "^5.1.0",
206
211
  "glob": "^10.4.5",
@@ -213,7 +218,7 @@
213
218
  "mocha": "^11.7.6",
214
219
  "mocha-junit-reporter": "^2.2.1",
215
220
  "mocha-multi-reporters": "^1.5.1",
216
- "multer": "^2.1.1",
221
+ "multer": "^2.2.0",
217
222
  "nock": "^14.0.15",
218
223
  "node-preload": "^0.2.1",
219
224
  "nyc": "^18.0.0",
@@ -222,7 +227,7 @@
222
227
  "proxyquire": "^2.1.3",
223
228
  "retry": "^0.13.1",
224
229
  "semifies": "^1.0.0",
225
- "semver": "^7.8.2",
230
+ "semver": "^7.8.4",
226
231
  "sinon": "^22.0.0",
227
232
  "tiktoken": "^1.0.21",
228
233
  "typescript": "^6.0.3",
@@ -8,6 +8,11 @@ const { pathToFileURL, fileURLToPath } = require('node:url')
8
8
  const instrumentations = require('../datadog-instrumentations/src/helpers/instrumentations')
9
9
  const extractPackageAndModulePath = require('../datadog-instrumentations/src/helpers/extract-package-and-module-path')
10
10
  const hooks = require('../datadog-instrumentations/src/helpers/hooks')
11
+ const {
12
+ OPTIONAL_PEER_FILTER,
13
+ matchesOptionalPeerFile,
14
+ rewriteOptionalPeerLoads,
15
+ } = require('../datadog-instrumentations/src/helpers/optional-peer-bundler')
11
16
  const { processModule, isESMFile } = require('./src/utils')
12
17
  const log = require('./src/log')
13
18
 
@@ -128,6 +133,11 @@ module.exports.setup = function (build) {
128
133
  ${build.initialOptions.banner.js}`
129
134
  }
130
135
 
136
+ // Keep the build from failing on the optional `@openfeature/core` peer of
137
+ // `@openfeature/server-sdk` when it is not installed (#8635). esbuild follows the chain
138
+ // whenever `@openfeature/server-sdk` is reachable -- the app importing it directly, or the
139
+ // bundled provider when the optional peer is present -- so mark `@openfeature/core` external
140
+ // when it is absent rather than erroring at bundle time.
131
141
  try {
132
142
  // eslint-disable-next-line n/no-unpublished-require
133
143
  require.resolve('@openfeature/core')
@@ -172,6 +182,22 @@ ${build.initialOptions.banner.js}`
172
182
  log.warn('No git metadata available - skipping injection')
173
183
  }
174
184
 
185
+ // Rewrite optional-peer loads so installed peers get bundled and survive the bundle being
186
+ // relocated without them on disk (#8980). Registered before the generic onLoad so it wins for
187
+ // these files. Absent peers stay opaque, so a build that does not opt into the feature does not
188
+ // follow their dependency chain (#8635).
189
+ build.onLoad({ filter: OPTIONAL_PEER_FILTER }, args => {
190
+ const normalizedPath = args.path.replaceAll('\\', '/')
191
+ if (!matchesOptionalPeerFile(normalizedPath)) return
192
+
193
+ log.debug('INLINE: optional-peer loader applied to %s', normalizedPath)
194
+ return {
195
+ contents: rewriteOptionalPeerLoads(fs.readFileSync(args.path, 'utf8'), path.dirname(args.path)),
196
+ loader: 'js',
197
+ resolveDir: path.dirname(args.path),
198
+ }
199
+ })
200
+
175
201
  // first time is intercepted, proxy should be created, next time the original should be loaded
176
202
  const interceptedESMModules = new Set()
177
203
 
@@ -6,6 +6,9 @@ const fs = require('node:fs')
6
6
  const path = require('node:path')
7
7
  const { NODE_MAJOR, NODE_MINOR } = require('../../../version.js')
8
8
 
9
+ const LOAD_OPERATION = 0
10
+ const RESOLVE_OPERATION = 1
11
+
9
12
  const getExportsImporting = (url) => import(url).then(Object.keys)
10
13
  let getExportsModulePromise
11
14
 
@@ -19,7 +22,11 @@ const loadGetExportsModule = () => {
19
22
  const getExports = NODE_MAJOR >= 20 || (NODE_MAJOR === 18 && NODE_MINOR >= 19)
20
23
  ? async (srcUrl, context, getSource) => {
21
24
  const mod = await loadGetExportsModule()
22
- return mod.getExports(srcUrl, context, getSource)
25
+ const exportNames = mod.getExports(srcUrl, context, getSource)
26
+ if (exportNames?.next) {
27
+ return driveGetExportsGenerator(exportNames, getSource)
28
+ }
29
+ return exportNames
23
30
  }
24
31
  : getExportsImporting
25
32
 
@@ -78,14 +85,50 @@ function getSource (url, { format }) {
78
85
  }
79
86
  }
80
87
 
88
+ /**
89
+ * Drives the generator returned by import-in-the-middle >=3.1.0 export discovery.
90
+ *
91
+ * @param {Generator<Array, Set<string>>} exportsGenerator Generator returned by getExports
92
+ * @param {(url: URL, context: object) => { source: string, format: string }} getSource
93
+ * Function that loads module source
94
+ * @returns {Set<string>}
95
+ */
96
+ function driveGetExportsGenerator (exportsGenerator, getSource) {
97
+ let next = exportsGenerator.next()
98
+ while (next.done === false) {
99
+ let result
100
+ let error
101
+ let threw = false
102
+
103
+ try {
104
+ const operation = next.value
105
+ const operationType = operation[0]
106
+
107
+ if (operationType === LOAD_OPERATION) {
108
+ result = getSource(operation[1], operation[2])
109
+ } else if (operationType === RESOLVE_OPERATION) {
110
+ result = resolve(operation[1], operation[2])
111
+ } else {
112
+ throw new Error(`Unsupported import-in-the-middle getExports operation: ${operationType}`)
113
+ }
114
+ } catch (err) {
115
+ threw = true
116
+ error = err
117
+ }
118
+
119
+ next = threw ? exportsGenerator.throw(error) : exportsGenerator.next(result)
120
+ }
121
+ return next.value
122
+ }
123
+
81
124
  /**
82
125
  * Generates the pieces of code for the proxy module before the path
83
126
  *
84
127
  * @param {object} moduleData
85
128
  * @param {string} moduleData.path
86
- * @param {boolean} [moduleData.internal]
129
+ * @param {boolean} [moduleData.internal]
87
130
  * @param {object} moduleData.context
88
- * @param {boolean} [moduleData.excludeDefault]
131
+ * @param {boolean} [moduleData.excludeDefault]
89
132
  * @returns {Promise<Map>}
90
133
  */
91
134
  async function processModule ({ path, internal = false, context, excludeDefault = false }) {