dd-trace 5.134.0 → 5.136.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.
- package/LICENSE-3rdparty.csv +0 -1
- package/ci/cypress/support.js +15 -1
- package/ci/init.js +2 -22
- package/ci/test-annotations.d.ts +5 -0
- package/ci/test-annotations.js +5 -0
- package/ci/vitest-no-worker-init-annotations.mjs +4 -0
- package/ci/vitest-no-worker-init-node-setup.mjs +22 -0
- package/ci/vitest-no-worker-init-runner-setup.mjs +7 -32
- package/ci/vitest-no-worker-init-setup.mjs +34 -12
- package/ci/vitest-no-worker-init-v5-setup.mjs +6 -0
- package/ext/exporters.js +1 -1
- package/index.d.ts +124 -5
- package/initialize.mjs +5 -2
- package/lambda.d.ts +39 -0
- package/lambda.js +3 -0
- package/loader-hook.mjs +53 -0
- package/openfeature/exposure-hook.d.ts +66 -0
- package/openfeature/exposure-hook.js +5 -0
- package/package.json +19 -15
- package/packages/datadog-core/src/storage.js +1 -1
- package/packages/datadog-esbuild/index.js +78 -62
- package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
- package/packages/datadog-instrumentations/src/cucumber.js +56 -19
- package/packages/datadog-instrumentations/src/cypress-config.js +163 -15
- package/packages/datadog-instrumentations/src/elevenlabs/activity.js +114 -0
- package/packages/datadog-instrumentations/src/elevenlabs/audio.js +104 -0
- package/packages/datadog-instrumentations/src/elevenlabs/index.js +288 -0
- package/packages/datadog-instrumentations/src/elevenlabs/session.js +444 -0
- package/packages/datadog-instrumentations/src/graphql.js +29 -20
- package/packages/datadog-instrumentations/src/grpc/server.js +23 -6
- package/packages/{datadog-esbuild/src/utils.js → datadog-instrumentations/src/helpers/bundler-esm-exports.js} +282 -40
- package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +573 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
- package/packages/datadog-instrumentations/src/helpers/fetch.js +5 -1
- package/packages/datadog-instrumentations/src/helpers/graphql-jit-runtime.js +30 -8
- package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
- package/packages/datadog-instrumentations/src/helpers/hooks.js +4 -8
- package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +18 -6
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +26 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/async-mutex.js +41 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/elevenlabs.js +25 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +3 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +0 -36
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +40 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/react-router.js +49 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/typesafe.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +12 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +58 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.js +19 -2
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +25 -3
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
- package/packages/datadog-instrumentations/src/ioredis.js +101 -3
- package/packages/datadog-instrumentations/src/jest.js +265 -82
- package/packages/datadog-instrumentations/src/mariadb-bundle.js +69 -11
- package/packages/datadog-instrumentations/src/mariadb.js +13 -6
- package/packages/datadog-instrumentations/src/mocha/common.js +89 -8
- package/packages/datadog-instrumentations/src/mocha/main.js +11 -2
- package/packages/datadog-instrumentations/src/mocha/utils.js +58 -12
- package/packages/datadog-instrumentations/src/mocha/worker.js +1 -1
- package/packages/datadog-instrumentations/src/next.js +19 -6
- package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
- package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
- package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
- package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
- package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
- package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
- package/packages/datadog-instrumentations/src/oracledb.js +33 -0
- package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
- package/packages/datadog-instrumentations/src/pg.js +2 -1
- package/packages/datadog-instrumentations/src/playwright.js +81 -28
- package/packages/datadog-instrumentations/src/react-router.js +106 -0
- package/packages/datadog-instrumentations/src/typesafe.js +89 -0
- package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +84 -48
- package/packages/datadog-instrumentations/src/vitest-main.js +26 -0
- package/packages/datadog-instrumentations/src/vitest-test-annotations.js +20 -0
- package/packages/datadog-instrumentations/src/vitest-worker.js +39 -17
- package/packages/datadog-instrumentations/src/vitest.js +10 -8
- package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
- package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
- package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
- package/packages/datadog-plugin-cucumber/src/index.js +5 -0
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +296 -55
- package/packages/datadog-plugin-cypress/src/index.js +1 -1
- package/packages/datadog-plugin-cypress/src/lifecycle-owner.js +20 -0
- package/packages/datadog-plugin-cypress/src/plugin.js +10 -0
- package/packages/datadog-plugin-cypress/src/retry-config-observer.js +281 -0
- package/packages/datadog-plugin-cypress/src/setup-handoff.js +125 -0
- package/packages/datadog-plugin-cypress/src/support.js +1217 -439
- package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -7
- package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +19 -52
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +4 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
- package/packages/datadog-plugin-graphql/src/execute.js +2 -2
- package/packages/datadog-plugin-graphql/src/utils.js +5 -5
- package/packages/datadog-plugin-http/src/client.js +32 -9
- package/packages/datadog-plugin-http2/src/client.js +38 -13
- package/packages/datadog-plugin-jest/src/index.js +25 -3
- package/packages/datadog-plugin-mocha/src/index.js +47 -6
- package/packages/datadog-plugin-next/src/index.js +112 -14
- package/packages/datadog-plugin-oracledb/src/connection-parser.js +21 -11
- package/packages/datadog-plugin-playwright/src/index.js +4 -0
- package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
- package/packages/datadog-plugin-react-router/src/index.js +118 -0
- package/packages/datadog-plugin-trpc/src/index.js +15 -0
- package/packages/datadog-plugin-trpc/src/procedure.js +48 -0
- package/packages/datadog-plugin-trpc/src/request.js +81 -0
- package/packages/datadog-plugin-typesafe/src/index.js +17 -0
- package/packages/datadog-plugin-typesafe/src/tracing.js +31 -0
- package/packages/datadog-plugin-undici/src/index.js +22 -7
- package/packages/datadog-plugin-vitest/src/index.js +8 -0
- package/packages/datadog-turbopack/index.js +4 -28
- package/packages/datadog-turbopack/src/loader.js +14 -452
- package/packages/datadog-webpack/index.js +3 -55
- package/packages/dd-trace/src/agent/info.js +2 -1
- package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
- package/packages/dd-trace/src/aiguard/sdk.js +8 -13
- package/packages/dd-trace/src/aiguard/tags.js +2 -0
- package/packages/dd-trace/src/appsec/blocking/index.js +4 -0
- package/packages/dd-trace/src/appsec/graphql.js +91 -6
- package/packages/dd-trace/src/appsec/recommended.json +1287 -90
- package/packages/dd-trace/src/before-exit.js +32 -0
- package/packages/dd-trace/src/bootstrap.js +5 -3
- package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +24 -18
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +16 -36
- package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +41 -13
- package/packages/dd-trace/src/ci-visibility/exporters/request.js +2 -3
- package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +10 -18
- package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +10 -15
- package/packages/dd-trace/src/ci-visibility/requests/route.js +44 -0
- package/packages/dd-trace/src/ci-visibility/telemetry-logs.js +5 -0
- package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
- package/packages/dd-trace/src/ci-visibility/test-annotations.js +72 -0
- package/packages/dd-trace/src/ci-visibility/test-declaration-annotations.js +170 -0
- package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +10 -17
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +9 -134
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +11 -156
- package/packages/dd-trace/src/config/config-types.d.ts +3 -0
- package/packages/dd-trace/src/config/defaults.js +9 -3
- package/packages/dd-trace/src/config/generated-config-types.d.ts +46 -2
- package/packages/dd-trace/src/config/index.js +111 -43
- package/packages/dd-trace/src/config/parsers.js +18 -1
- package/packages/dd-trace/src/config/supported-configurations.json +174 -4
- package/packages/dd-trace/src/constants.js +1 -0
- package/packages/dd-trace/src/debugger/pause-duration-histogram.js +2 -1
- package/packages/dd-trace/src/debugger/probe_sampler.js +6 -6
- package/packages/dd-trace/src/encode/0.4.js +2 -2
- package/packages/dd-trace/src/esm-module-load.js +58 -0
- package/packages/dd-trace/src/exporter.js +23 -15
- package/packages/dd-trace/src/exporters/agent/index.js +3 -1
- package/packages/dd-trace/src/exporters/agentless/index.js +3 -1
- package/packages/dd-trace/src/exporters/common/request.js +83 -50
- package/packages/dd-trace/src/exporters/common/retry.js +12 -7
- package/packages/dd-trace/src/exporters/common/url.js +1 -1
- package/packages/dd-trace/src/exporters/llmobs/index.js +135 -0
- package/packages/dd-trace/src/exporters/log/index.js +4 -3
- package/packages/dd-trace/src/id.js +1 -1
- package/packages/dd-trace/src/lambda/facade.js +74 -0
- package/packages/dd-trace/src/lambda/handler.js +3 -41
- package/packages/dd-trace/src/lambda/index.js +38 -15
- package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
- package/packages/dd-trace/src/lambda/wrap.js +44 -0
- package/packages/dd-trace/src/llmobs/constants/tags.js +3 -0
- package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
- package/packages/dd-trace/src/llmobs/experiments/index.js +2 -3
- package/packages/dd-trace/src/llmobs/experiments/noop.js +5 -2
- package/packages/dd-trace/src/llmobs/index.js +13 -2
- package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
- package/packages/dd-trace/src/llmobs/plugins/genai/index.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/genai/util.js +27 -10
- package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
- package/packages/dd-trace/src/llmobs/plugins/typesafe/index.js +102 -0
- package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
- package/packages/dd-trace/src/llmobs/prompts/cache.js +3 -1
- package/packages/dd-trace/src/llmobs/sdk.js +21 -1
- package/packages/dd-trace/src/llmobs/span_processor.js +219 -12
- package/packages/dd-trace/src/llmobs/tagger.js +25 -0
- package/packages/dd-trace/src/llmobs/writers/util.js +3 -3
- package/packages/dd-trace/src/log/channels.js +4 -0
- package/packages/dd-trace/src/log/writer.js +13 -2
- package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +68 -6
- package/packages/dd-trace/src/openfeature/configuration_source.js +41 -17
- package/packages/dd-trace/src/openfeature/debug-logging-hook.js +66 -3
- package/packages/dd-trace/src/openfeature/exposure-hook.js +185 -0
- package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
- package/packages/dd-trace/src/openfeature/flagging_provider.js +58 -14
- package/packages/dd-trace/src/openfeature/remote_config.js +16 -3
- package/packages/dd-trace/src/openfeature/writers/base.js +63 -30
- package/packages/dd-trace/src/openfeature/writers/exposures.js +161 -1
- package/packages/dd-trace/src/openfeature/writers/flag-eval-evp-hook.js +5 -0
- package/packages/dd-trace/src/openfeature/writers/flag-evaluation-aggregation.js +9 -4
- package/packages/dd-trace/src/openfeature/writers/flag-evaluation-payload.js +2 -0
- package/packages/dd-trace/src/openfeature/writers/flag-evaluation-pii.js +2 -0
- package/packages/dd-trace/src/openfeature/writers/split-features.js +25 -0
- package/packages/dd-trace/src/opentelemetry/logs/index.js +11 -0
- package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/index.js +7 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +4 -1
- package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +2 -2
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +19 -1
- package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +5 -1
- package/packages/dd-trace/src/opentelemetry/span-helpers.js +6 -1
- package/packages/dd-trace/src/opentelemetry/span.js +2 -2
- package/packages/dd-trace/src/opentelemetry/startup-config.js +174 -0
- package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +7 -1
- package/packages/dd-trace/src/opentelemetry/tracer_provider.js +5 -1
- package/packages/dd-trace/src/opentracing/propagation/tracestate.js +77 -23
- package/packages/dd-trace/src/opentracing/tracer.js +33 -13
- package/packages/dd-trace/src/otel-thread-ctx.js +72 -49
- package/packages/dd-trace/src/plugin_manager.js +34 -7
- package/packages/dd-trace/src/plugins/ci_plugin.js +45 -14
- package/packages/dd-trace/src/plugins/index.js +9 -0
- package/packages/dd-trace/src/plugins/plugin.js +4 -2
- package/packages/dd-trace/src/plugins/tracing.js +1 -1
- package/packages/dd-trace/src/plugins/util/ci.js +18 -1
- package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
- package/packages/dd-trace/src/plugins/util/git.js +273 -86
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +77 -50
- package/packages/dd-trace/src/plugins/util/inferred_proxy.js +12 -4
- package/packages/dd-trace/src/plugins/util/status-validator.js +23 -10
- package/packages/dd-trace/src/plugins/util/tags.js +6 -0
- package/packages/dd-trace/src/plugins/util/test.js +90 -45
- package/packages/dd-trace/src/plugins/util/url.js +10 -2
- package/packages/dd-trace/src/plugins/util/user-provided-git.js +2 -2
- package/packages/dd-trace/src/plugins/util/web.js +81 -10
- package/packages/dd-trace/src/process-tags/index.js +1 -1
- package/packages/dd-trace/src/profiling/config.js +6 -3
- package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
- package/packages/dd-trace/src/proxy.js +48 -57
- package/packages/dd-trace/src/serverless.js +3 -2
- package/packages/dd-trace/src/span_processor.js +41 -9
- package/packages/dd-trace/src/span_stats.js +28 -2
- package/packages/dd-trace/src/startup-log.js +8 -5
- package/packages/dd-trace/src/tagger.js +7 -5
- package/packages/dd-trace/src/telemetry/dependencies.js +4 -0
- package/packages/dd-trace/src/telemetry/index.js +3 -0
- package/packages/dd-trace/src/telemetry/logs/index.js +21 -2
- package/packages/dd-trace/src/telemetry/logs/log-collector.js +1 -0
- package/packages/dd-trace/src/telemetry/metrics.js +2 -1
- package/packages/dd-trace/src/telemetry/telemetry.js +10 -3
- package/packages/dd-trace/src/tracer.js +0 -2
- package/packages/dd-trace/src/util.js +1 -1
- package/packages/dd-trace/src/web-tags-cache.js +8 -9
- package/register.js +4 -2
- package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
- package/vendor/dist/{@opentelemetry/resources → @datadog/flagging-core}/LICENSE +22 -2
- package/vendor/dist/@datadog/flagging-core/index.js +1 -0
- package/vendor/dist/@datadog/openfeature-node-server/LICENSE +21 -1
- package/vendor/dist/@datadog/openfeature-node-server/index.js +1 -1
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +3 -1
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.d.ts +78 -0
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/index.js +1 -1
- package/vendor/dist/@datadog/sketches-js/LICENSE +263 -0
- package/vendor/dist/@datadog/source-map/LICENSE +1 -0
- package/vendor/dist/@isaacs/ttlcache/LICENSE +13 -0
- package/vendor/dist/@opentelemetry/core/LICENSE +209 -1
- package/vendor/dist/@opentelemetry/core/index.js +1 -1
- package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
- package/vendor/dist/escape-string-regexp/LICENSE +13 -0
- package/vendor/dist/esquery/LICENSE +2 -0
- package/vendor/dist/https-proxy-agent/LICENSE +80 -1
- package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
- package/vendor/dist/jest-docblock/LICENSE +16 -0
- package/vendor/dist/jsonpath-plus/LICENSE +13 -0
- package/vendor/dist/limiter/LICENSE +2 -0
- package/vendor/dist/lodash.sortby/LICENSE +2 -0
- package/vendor/dist/lru-cache/LICENSE +13 -0
- package/vendor/dist/meriyah/LICENSE +13 -0
- package/vendor/dist/module-details-from-path/LICENSE +2 -0
- package/vendor/dist/mutexify/promise/LICENSE +28 -0
- package/vendor/dist/pprof-format/LICENSE +13 -0
- package/vendor/dist/pprof-format/index.js +1 -1
- package/vendor/dist/protobufjs/LICENSE +219 -0
- package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
- package/vendor/dist/proxy-from-env/LICENSE +13 -0
- package/vendor/dist/retry/LICENSE +2 -0
- package/vendor/dist/rfdc/LICENSE +2 -0
- package/vendor/dist/semifies/LICENSE +3 -1
- package/vendor/dist/shell-quote/LICENSE +3 -1
- package/vendor/dist/source-map/LICENSE +1 -0
- package/vendor/dist/source-map/lib/util/LICENSE +1 -0
- package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
- package/vendor/dist/ttl-set/LICENSE +28 -0
- package/ci/diagnose.js +0 -2215
- package/ci/runbook.md +0 -299
- package/ci/test-optimization-validation/approval-artifacts.js +0 -175
- package/ci/test-optimization-validation/approval.js +0 -386
- package/ci/test-optimization-validation/artifact-id.js +0 -19
- package/ci/test-optimization-validation/blocker-category.js +0 -24
- package/ci/test-optimization-validation/bounded-json.js +0 -120
- package/ci/test-optimization-validation/ci-command-candidate.js +0 -77
- package/ci/test-optimization-validation/ci-discovery.js +0 -192
- package/ci/test-optimization-validation/ci-package-scripts.js +0 -169
- package/ci/test-optimization-validation/ci-remediation.js +0 -283
- package/ci/test-optimization-validation/cli.js +0 -954
- package/ci/test-optimization-validation/command-blocker.js +0 -377
- package/ci/test-optimization-validation/command-output-policy.js +0 -188
- package/ci/test-optimization-validation/command-runner.js +0 -650
- package/ci/test-optimization-validation/environment.js +0 -88
- package/ci/test-optimization-validation/executable-approval.js +0 -47
- package/ci/test-optimization-validation/executable.js +0 -244
- package/ci/test-optimization-validation/execution-lock.js +0 -70
- package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +0 -3
- package/ci/test-optimization-validation/framework-adapters/cucumber.js +0 -767
- package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -99
- package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -175
- package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -513
- package/ci/test-optimization-validation/generated-file-policy.js +0 -63
- package/ci/test-optimization-validation/generated-files.js +0 -425
- package/ci/test-optimization-validation/generated-test-contract.js +0 -284
- package/ci/test-optimization-validation/generated-verifier.js +0 -235
- package/ci/test-optimization-validation/literal-environment.js +0 -56
- package/ci/test-optimization-validation/literal-glob.js +0 -52
- package/ci/test-optimization-validation/manifest-loader.js +0 -116
- package/ci/test-optimization-validation/manifest-scaffold.js +0 -1276
- package/ci/test-optimization-validation/manifest-schema.js +0 -695
- package/ci/test-optimization-validation/offline-fixtures.js +0 -335
- package/ci/test-optimization-validation/offline-output.js +0 -406
- package/ci/test-optimization-validation/package-check.js +0 -97
- package/ci/test-optimization-validation/payload-normalizer.js +0 -72
- package/ci/test-optimization-validation/plan-writer.js +0 -541
- package/ci/test-optimization-validation/preflight-runner.js +0 -186
- package/ci/test-optimization-validation/project-build-artifact.js +0 -31
- package/ci/test-optimization-validation/redaction.js +0 -319
- package/ci/test-optimization-validation/report-writer.js +0 -666
- package/ci/test-optimization-validation/result-semantics.js +0 -103
- package/ci/test-optimization-validation/runner-command.js +0 -264
- package/ci/test-optimization-validation/runner-contract.js +0 -695
- package/ci/test-optimization-validation/safe-files.js +0 -202
- package/ci/test-optimization-validation/scenarios/auto-test-retries.js +0 -171
- package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -407
- package/ci/test-optimization-validation/scenarios/ci-wiring.js +0 -666
- package/ci/test-optimization-validation/scenarios/early-flake-detection.js +0 -142
- package/ci/test-optimization-validation/scenarios/helpers.js +0 -621
- package/ci/test-optimization-validation/scenarios/test-management.js +0 -219
- package/ci/test-optimization-validation/source-text.js +0 -84
- package/ci/test-optimization-validation/static-diagnosis.js +0 -166
- package/ci/test-optimization-validation/test-output.js +0 -120
- package/ci/test-optimization-validation/validation-blocker.js +0 -21
- package/ci/validate-test-optimization.js +0 -3
- package/packages/datadog-esbuild/src/resolver.js +0 -284
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -156
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -287
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +0 -84
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -368
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +0 -59
- package/vendor/dist/@opentelemetry/resources/index.js +0 -1
|
@@ -1,22 +1,45 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const { channel } = require('dc-polyfill')
|
|
4
4
|
|
|
5
|
-
const log = require('../log')
|
|
6
5
|
const { getEnvironmentVariable, getValueFromEnvSources } = require('../config/helper')
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
|
|
7
|
+
const loadChannel = channel('dd-trace:instrumentation:load')
|
|
8
|
+
let initialized = false
|
|
9
|
+
|
|
10
|
+
// Called during tracer configuration so importing the facade early does not freeze Lambda detection.
|
|
11
|
+
module.exports = function initialize () {
|
|
12
|
+
if (initialized || getEnvironmentVariable('AWS_LAMBDA_FUNCTION_NAME') === undefined ||
|
|
13
|
+
isDisabled(getValueFromEnvSources('DD_TRACE_DISABLED_INSTRUMENTATIONS'))) return
|
|
14
|
+
|
|
15
|
+
registerHooks()
|
|
16
|
+
initialized = true
|
|
17
|
+
|
|
18
|
+
// Plugin disabling must leave the legacy shim's timeout hooks active. Handle the legacy alias
|
|
19
|
+
// here without changing the plugin manager's disabled-plugin registry.
|
|
20
|
+
if (!isDisabled(getValueFromEnvSources('DD_TRACE_DISABLED_PLUGINS'))) {
|
|
21
|
+
loadChannel.publish({ name: 'aws-lambda' })
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** @param {string | undefined} value Disabled integration names. */
|
|
26
|
+
function isDisabled (value) {
|
|
27
|
+
return value?.split(',').some(name => ['lambda', 'aws-lambda'].includes(name.trim())) ?? false
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function registerHooks () {
|
|
31
|
+
// Keep handler-loading dependencies lazy outside Lambda and when instrumentation is disabled.
|
|
32
|
+
const path = require('node:path')
|
|
33
|
+
|
|
34
|
+
const Hook = require('../../../datadog-instrumentations/src/helpers/hook')
|
|
35
|
+
const instrumentations = require('../../../datadog-instrumentations/src/helpers/instrumentations')
|
|
36
|
+
const { filename, pathSepExpr } = require('../../../datadog-instrumentations/src/helpers/register')
|
|
37
|
+
const log = require('../log')
|
|
38
|
+
const {
|
|
39
|
+
extractModuleNameAndHandlerPath,
|
|
40
|
+
extractModuleRootAndHandler,
|
|
41
|
+
getLambdaFilePaths,
|
|
42
|
+
} = require('./handler-paths')
|
|
20
43
|
const lambdaTaskRoot = getEnvironmentVariable('LAMBDA_TASK_ROOT')
|
|
21
44
|
const originalLambdaHandler = getValueFromEnvSources('DD_LAMBDA_HANDLER')
|
|
22
45
|
|
|
@@ -4,6 +4,7 @@ const path = require('path')
|
|
|
4
4
|
const { types: { isModuleNamespaceObject } } = require('node:util')
|
|
5
5
|
|
|
6
6
|
const { datadog } = require('../handler')
|
|
7
|
+
const { withTimeoutMonitor } = require('../wrap')
|
|
7
8
|
const { addHook } = require('../../../../datadog-instrumentations/src/helpers/instrument')
|
|
8
9
|
const shimmer = require('../../../../datadog-shimmer')
|
|
9
10
|
const { getEnvironmentVariable, getValueFromEnvSources } = require('../../config/helper')
|
|
@@ -21,7 +22,9 @@ function patchDatadogLambdaModule (datadogLambdaModule) {
|
|
|
21
22
|
|
|
22
23
|
/** @param {Function} datadogHandler */
|
|
23
24
|
function patchDatadogLambdaHandler (datadogHandler) {
|
|
24
|
-
return
|
|
25
|
+
return function (userHandler, ...args) {
|
|
26
|
+
return Reflect.apply(datadogHandler, this, [instrumentLambdaHandler(userHandler, args[0]), ...args])
|
|
27
|
+
}
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
/**
|
|
@@ -46,7 +49,7 @@ function patchLambdaModule (handlerPath) {
|
|
|
46
49
|
if (!descriptor.configurable && !descriptor.writable) return lambdaModule
|
|
47
50
|
// The monitor copies Lambda metadata without invoking application accessors or Proxy traps.
|
|
48
51
|
// Generic shimmer wrapping would copy the original properties back onto that safe wrapper.
|
|
49
|
-
descriptor.value =
|
|
52
|
+
descriptor.value = instrumentLambdaHandler(descriptor.value)
|
|
50
53
|
// Native ESM namespaces reject replacement even when their export reports writable: true.
|
|
51
54
|
const exports = isModuleNamespaceObject(lambdaModule)
|
|
52
55
|
? Object.create(lambdaModule, Object.getOwnPropertyDescriptors(lambdaModule))
|
|
@@ -54,10 +57,23 @@ function patchLambdaModule (handlerPath) {
|
|
|
54
57
|
Object.defineProperty(exports, handlerPath, descriptor)
|
|
55
58
|
return exports
|
|
56
59
|
}
|
|
57
|
-
return shimmer.wrap(lambdaModule, handlerPath,
|
|
60
|
+
return shimmer.wrap(lambdaModule, handlerPath, instrumentLambdaHandler)
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Only internal migration builds may delegate invocation-span ownership from the final shim.
|
|
66
|
+
* Old shims retain timeout monitoring, including their selected-completion helper hooks.
|
|
67
|
+
* Explicit facade wrapping is opt-in and independent of the automatic hooks.
|
|
68
|
+
*
|
|
69
|
+
* @param {Function} handler Customer handler.
|
|
70
|
+
* @param {Record<string, unknown>} [config] Per-handler overrides.
|
|
71
|
+
* @returns {Function} Monitored or invocation-wrapped handler.
|
|
72
|
+
*/
|
|
73
|
+
function instrumentLambdaHandler (handler, config) {
|
|
74
|
+
return withTimeoutMonitor(handler) // Import and return `wrapLambdaHandler(handler, config)` for migration testing.
|
|
75
|
+
}
|
|
76
|
+
|
|
61
77
|
const lambdaTaskRoot = getEnvironmentVariable('LAMBDA_TASK_ROOT')
|
|
62
78
|
const originalLambdaHandler = getValueFromEnvSources('DD_LAMBDA_HANDLER')
|
|
63
79
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { getWrappedHandler, wrapHandler } = require('../../../datadog-instrumentations/src/aws-lambda')
|
|
4
|
+
const { datadog: monitor } = require('./handler')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Reuses a raw timeout monitor, or its invocation wrapper after facade promotion.
|
|
8
|
+
*
|
|
9
|
+
* @param {Function} handler Customer handler.
|
|
10
|
+
* @returns {Function} Monitored handler.
|
|
11
|
+
*/
|
|
12
|
+
function withTimeoutMonitor (handler) {
|
|
13
|
+
if (typeof handler !== 'function') throw new TypeError('AWS Lambda handler must be a function')
|
|
14
|
+
// Share handler identity across tracer copies without modifying customer functions.
|
|
15
|
+
const ddGlobal = globalThis[Symbol.for('dd-trace')] ??= { beforeExitHandlers: new Set() }
|
|
16
|
+
const lambda = ddGlobal.lambda ??= {}
|
|
17
|
+
const monitors = lambda.monitors ??= new WeakMap()
|
|
18
|
+
const originals = lambda.originals ??= new WeakMap()
|
|
19
|
+
const original = originals.get(handler) || handler
|
|
20
|
+
const wrapped = getWrappedHandler(original)
|
|
21
|
+
if (wrapped) return wrapped
|
|
22
|
+
const existing = monitors.get(original)
|
|
23
|
+
if (existing) return existing
|
|
24
|
+
const monitored = monitor(original)
|
|
25
|
+
monitors.set(original, monitored)
|
|
26
|
+
originals.set(monitored, original)
|
|
27
|
+
return monitored
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Composes invocation scope -> timeout monitor -> selected completion -> customer handler.
|
|
32
|
+
*
|
|
33
|
+
* @param {Function} handler Customer handler or a monitor-only hook wrapper.
|
|
34
|
+
* @param {Record<string, unknown>} [config] Per-handler overrides.
|
|
35
|
+
* @returns {Function} Instrumented handler.
|
|
36
|
+
*/
|
|
37
|
+
function wrapLambdaHandler (handler, config) {
|
|
38
|
+
// Normalize the original so a hook-first call has the same completion boundary as facade-first.
|
|
39
|
+
// forceWrap(raw) replaces its wrapper; explicitly force-wrapping a span wrapper still nests it.
|
|
40
|
+
const originals = globalThis[Symbol.for('dd-trace')]?.lambda?.originals
|
|
41
|
+
return wrapHandler(originals?.get(handler) || handler, config, monitor)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = { withTimeoutMonitor, wrapLambdaHandler }
|
|
@@ -17,6 +17,7 @@ module.exports = {
|
|
|
17
17
|
SPAN_KINDS: ['llm', 'agent', 'workflow', 'task', 'tool', 'embedding', 'retrieval', 'experiment'],
|
|
18
18
|
SPAN_KIND: '_ml_obs.meta.span.kind',
|
|
19
19
|
SESSION_ID: '_ml_obs.session_id',
|
|
20
|
+
EXPERIMENT_TAGS: '_ml_obs.experiment_tags',
|
|
20
21
|
SESSION_ID_TRACE_DEFAULT_KEY: '_ml_obs.trace_session_id',
|
|
21
22
|
DECORATOR: '_ml_obs.decorator',
|
|
22
23
|
INTEGRATION: '_ml_obs.integration',
|
|
@@ -51,6 +52,7 @@ module.exports = {
|
|
|
51
52
|
LLMOBS_TRACE_ID_BRIDGE_KEY: 'llmobs_trace_id',
|
|
52
53
|
LLMOBS_PARENT_ID_BRIDGE_KEY: 'llmobs_parent_id',
|
|
53
54
|
LLMOBS_SUBMITTED_TAG_KEY: '_dd.llmobs.submitted',
|
|
55
|
+
LLMOBS_META_STRUCT_KEY: '_llmobs',
|
|
54
56
|
ROOT_PARENT_ID: 'undefined',
|
|
55
57
|
DEFAULT_PROMPT_NAME: 'unnamed-prompt',
|
|
56
58
|
INTERNAL_CONTEXT_VARIABLE_KEYS: '_dd_context_variable_keys',
|
|
@@ -62,6 +64,7 @@ module.exports = {
|
|
|
62
64
|
DEFAULT_MODEL: 'custom',
|
|
63
65
|
|
|
64
66
|
INPUT_DOCUMENTS: '_ml_obs.meta.input.documents',
|
|
67
|
+
EXPERIMENT_EXPECTED_OUTPUT: '_ml_obs.meta.expected_output',
|
|
65
68
|
EXPERIMENT_INPUT: '_ml_obs.meta.input',
|
|
66
69
|
INPUT_MESSAGES: '_ml_obs.meta.input.messages',
|
|
67
70
|
INPUT_VALUE: '_ml_obs.meta.input.value',
|
|
@@ -888,17 +888,19 @@ class Experiment {
|
|
|
888
888
|
let errorType = null
|
|
889
889
|
let errorMessage = null
|
|
890
890
|
|
|
891
|
-
|
|
891
|
+
// Inherited by every span the task creates, so the multi-run rollups count their tokens and cost.
|
|
892
|
+
// Same key set Python propagates; the record id stays on the experiment span only.
|
|
893
|
+
const experimentTags = {
|
|
892
894
|
experiment_id: experimentId,
|
|
893
895
|
run_id: runId,
|
|
894
896
|
run_iteration: runIteration,
|
|
895
897
|
project_id: projectId,
|
|
896
898
|
dataset_id: datasetId,
|
|
897
|
-
dataset_record_id: datasetRecordId,
|
|
898
899
|
dataset_name: this.#dataset.name(),
|
|
899
900
|
experiment_name: this.#name,
|
|
900
901
|
}
|
|
901
|
-
if (this.#projectName !== undefined)
|
|
902
|
+
if (this.#projectName !== undefined) experimentTags.project_name = this.#projectName
|
|
903
|
+
const autoTags = { ...experimentTags, dataset_record_id: datasetRecordId }
|
|
902
904
|
const tags = mergeTags(this.#tags, { ...recordTagsToObject(record.tags), ...autoTags })
|
|
903
905
|
|
|
904
906
|
const execute = () => this.#runWithRetries(
|
|
@@ -912,22 +914,25 @@ class Experiment {
|
|
|
912
914
|
await this.#llmobs.trace({
|
|
913
915
|
kind: 'experiment',
|
|
914
916
|
name: this.#task.name || this.#name,
|
|
917
|
+
_experimentTags: experimentTags,
|
|
915
918
|
}, async (span) => {
|
|
916
919
|
spanContext = this.#llmobs.exportSpan(span)
|
|
917
920
|
try {
|
|
918
921
|
output = await execute()
|
|
919
922
|
} catch (err) {
|
|
920
|
-
this.#llmobs.
|
|
923
|
+
this.#llmobs._annotateExperimentSpan(span, {
|
|
921
924
|
inputData: record.input,
|
|
922
925
|
outputData: output,
|
|
926
|
+
expectedOutput: record.expectedOutput,
|
|
923
927
|
metadata: buildSpanMetadata(record.metadata, this.#config),
|
|
924
928
|
tags,
|
|
925
929
|
})
|
|
926
930
|
throw err
|
|
927
931
|
}
|
|
928
|
-
this.#llmobs.
|
|
932
|
+
this.#llmobs._annotateExperimentSpan(span, {
|
|
929
933
|
inputData: record.input,
|
|
930
934
|
outputData: output,
|
|
935
|
+
expectedOutput: record.expectedOutput,
|
|
931
936
|
metadata: buildSpanMetadata(record.metadata, this.#config),
|
|
932
937
|
tags,
|
|
933
938
|
})
|
|
@@ -115,7 +115,7 @@ class Experiments {
|
|
|
115
115
|
// wait until that many records are readable. Pass `tags` to filter records by
|
|
116
116
|
// dataset record tags.
|
|
117
117
|
async pullDataset (name, options = {}) {
|
|
118
|
-
const { expectedRecordCount, maxWaitMs = 30_000, projectName, tags, version } = options
|
|
118
|
+
const { expectedRecordCount, maxWaitMs = 30_000, projectName, tags, version: datasetVersion = null } = options
|
|
119
119
|
const filterTags = validateTagsList(tags)
|
|
120
120
|
const client = this.#clientForOperation(projectName)
|
|
121
121
|
const resolvedProjectName = projectName ?? this.#projectName
|
|
@@ -123,7 +123,6 @@ class Experiments {
|
|
|
123
123
|
|
|
124
124
|
let pulledDataset = null
|
|
125
125
|
let records = []
|
|
126
|
-
const datasetVersion = version ?? null
|
|
127
126
|
let latestVersion = null
|
|
128
127
|
let lastError = ''
|
|
129
128
|
|
|
@@ -247,7 +246,7 @@ function createExperiments (config, llmobs) {
|
|
|
247
246
|
if (!config.llmobs?.DD_LLMOBS_ENABLED) {
|
|
248
247
|
return new NoopExperiments('LLM Observability is not enabled')
|
|
249
248
|
}
|
|
250
|
-
if (
|
|
249
|
+
if (config.DD_API_KEY === undefined || config.DD_APP_KEY === undefined) {
|
|
251
250
|
log.warn('LLMObs experiments: missing api and/or app keys, set DD_API_KEY and DD_APP_KEY')
|
|
252
251
|
return new NoopExperiments('DD_API_KEY and DD_APP_KEY are required for experiments')
|
|
253
252
|
}
|
|
@@ -256,8 +256,11 @@ class NoopExperiment {
|
|
|
256
256
|
class NoopExperiments {
|
|
257
257
|
#reason
|
|
258
258
|
|
|
259
|
-
|
|
260
|
-
|
|
259
|
+
/**
|
|
260
|
+
* @param {string} [reason]
|
|
261
|
+
*/
|
|
262
|
+
constructor (reason = 'LLMObs experiments are not available') {
|
|
263
|
+
this.#reason = reason
|
|
261
264
|
}
|
|
262
265
|
|
|
263
266
|
#warn () {
|
|
@@ -35,6 +35,7 @@ const { INCOMPATIBLE_INITIALIZATION } = require('./constants/text')
|
|
|
35
35
|
const { llmObsTraceIdToWire } = require('./util')
|
|
36
36
|
|
|
37
37
|
const spanFinishCh = channel('dd-trace:span:finish')
|
|
38
|
+
const traceSampledCh = channel('dd-trace:trace:sampled')
|
|
38
39
|
const evalMetricAppendCh = channel('llmobs:eval-metric:append')
|
|
39
40
|
const flushCh = channel('llmobs:writers:flush')
|
|
40
41
|
const injectCh = channel('dd-trace:span:inject')
|
|
@@ -80,9 +81,13 @@ function enable (config) {
|
|
|
80
81
|
const retiredEvalWriter = evalWriter
|
|
81
82
|
const isReinitializing = Boolean(retiredSpanWriter || retiredEvalWriter)
|
|
82
83
|
unregisterTelemetryFlusher?.()
|
|
84
|
+
spanProcessor?.destroy()
|
|
83
85
|
retireWriters(retiredSpanWriter, retiredEvalWriter)
|
|
84
86
|
|
|
85
87
|
const startTime = performance.now()
|
|
88
|
+
// Register the processor lifecycle first so pending events reach the writers before they shut down.
|
|
89
|
+
spanProcessor = new LLMObsSpanProcessor(config)
|
|
90
|
+
|
|
86
91
|
// create writers and eval writer append and flush channels
|
|
87
92
|
// span writer append is handled by the span processor
|
|
88
93
|
evalWriter = new LLMObsEvalMetricsWriter(config)
|
|
@@ -97,10 +102,9 @@ function enable (config) {
|
|
|
97
102
|
evalMetricAppendCh.subscribe(handleEvalMetricAppend)
|
|
98
103
|
flushCh.subscribe(handleFlush)
|
|
99
104
|
registerUserSpanProcessorCh.subscribe(handleRegisterProcessor)
|
|
105
|
+
traceSampledCh.subscribe(handleTraceSampled)
|
|
100
106
|
}
|
|
101
107
|
|
|
102
|
-
// span processing
|
|
103
|
-
spanProcessor = new LLMObsSpanProcessor(config)
|
|
104
108
|
spanProcessor.setWriter(spanWriter)
|
|
105
109
|
if (!isReinitializing) spanFinishCh.subscribe(handleSpanProcess)
|
|
106
110
|
|
|
@@ -131,11 +135,13 @@ function disable () {
|
|
|
131
135
|
if (evalMetricAppendCh.hasSubscribers) evalMetricAppendCh.unsubscribe(handleEvalMetricAppend)
|
|
132
136
|
if (flushCh.hasSubscribers) flushCh.unsubscribe(handleFlush)
|
|
133
137
|
if (spanFinishCh.hasSubscribers) spanFinishCh.unsubscribe(handleSpanProcess)
|
|
138
|
+
if (traceSampledCh.hasSubscribers) traceSampledCh.unsubscribe(handleTraceSampled)
|
|
134
139
|
if (injectCh.hasSubscribers) injectCh.unsubscribe(handleLLMObsInjection)
|
|
135
140
|
if (registerUserSpanProcessorCh.hasSubscribers) registerUserSpanProcessorCh.unsubscribe(handleRegisterProcessor)
|
|
136
141
|
|
|
137
142
|
const retiredSpanWriter = spanWriter
|
|
138
143
|
const retiredEvalWriter = evalWriter
|
|
144
|
+
spanProcessor?.destroy()
|
|
139
145
|
spanProcessor?.setWriter(null)
|
|
140
146
|
unregisterTelemetryFlusher?.()
|
|
141
147
|
unregisterTelemetryFlusher = undefined
|
|
@@ -261,6 +267,7 @@ function flushWriters (done, currentSpanWriter = spanWriter, currentEvalWriter =
|
|
|
261
267
|
}
|
|
262
268
|
|
|
263
269
|
function handleFlush () {
|
|
270
|
+
spanProcessor.processPending()
|
|
264
271
|
const err = flushWriters() ? 'writer_flush_error' : ''
|
|
265
272
|
telemetry.recordUserFlush(err)
|
|
266
273
|
}
|
|
@@ -273,6 +280,10 @@ function handleSpanProcess (span) {
|
|
|
273
280
|
spanProcessor.process(span)
|
|
274
281
|
}
|
|
275
282
|
|
|
283
|
+
function handleTraceSampled (trace) {
|
|
284
|
+
spanProcessor.processTrace(trace)
|
|
285
|
+
}
|
|
286
|
+
|
|
276
287
|
function handleEvalMetricAppend ({ payload, routing }) {
|
|
277
288
|
try {
|
|
278
289
|
evalWriter.append(payload, routing)
|
|
@@ -9,7 +9,7 @@ const SYSTEM_PROMPT_DYNAMIC_BOUNDARY = '__SYSTEM_PROMPT_DYNAMIC_BOUNDARY__'
|
|
|
9
9
|
const subagentToolIds = new Set()
|
|
10
10
|
|
|
11
11
|
function normalizeToolOutputString (raw) {
|
|
12
|
-
const footerIndex = raw.search(/agentId: \S+ \(use SendMessage\b
|
|
12
|
+
const footerIndex = raw.search(/agentId: \S+ \(use SendMessage\b|(?:^|\n)agentId: \S+\n<usage>/)
|
|
13
13
|
if (footerIndex === -1) return raw
|
|
14
14
|
|
|
15
15
|
return raw.slice(0, footerIndex).trimEnd()
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { pcm16ToWav } = require('../audio-codec')
|
|
4
|
+
const { fitsInlineAudioBudget, formatAudioPartWithGuard } = require('../audio-utils')
|
|
5
|
+
const { AUDIO_FALLBACK, LLMOBS_AUDIO_INLINE_MAX_BYTES } = require('../constants/audio')
|
|
6
|
+
const { SESSION_ID } = require('../constants/tags')
|
|
7
|
+
const { storage } = require('../storage')
|
|
8
|
+
const LLMObsPlugin = require('./base')
|
|
9
|
+
|
|
10
|
+
/** @typedef {import('../../../../datadog-instrumentations/src/elevenlabs/session').Scope} Scope */
|
|
11
|
+
/** @typedef {import('../../../../datadog-core/src/storage').Store<unknown>} Store */
|
|
12
|
+
|
|
13
|
+
class ElevenLabsLLMObsPlugin extends LLMObsPlugin {
|
|
14
|
+
static id = 'elevenlabs_llmobs'
|
|
15
|
+
static integration = 'elevenlabs'
|
|
16
|
+
static prefix = 'tracing:apm:elevenlabs:span'
|
|
17
|
+
static emitsGenAiApmTags = false
|
|
18
|
+
|
|
19
|
+
constructor (...args) {
|
|
20
|
+
super(...args)
|
|
21
|
+
this.addSub('dd-trace:elevenlabs:audio', () => {})
|
|
22
|
+
this.addSub('dd-trace:elevenlabs:capture-context', message => {
|
|
23
|
+
const scope = /** @type {Scope} */ (message)
|
|
24
|
+
// An absent store intentionally restores an explicit root context.
|
|
25
|
+
const store = /** @type {Store} */ (storage.getStore())
|
|
26
|
+
const previous = scope.runInContext ?? (fn => fn())
|
|
27
|
+
scope.runInContext = fn => previous(() => storage.run(store, fn))
|
|
28
|
+
})
|
|
29
|
+
this.addSub('apm:elevenlabs:annotate', ctx => this.setLLMObsTags(ctx))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @param {object} ctx */
|
|
33
|
+
getLLMObsSpanRegisterOptions (ctx) {
|
|
34
|
+
const options = {
|
|
35
|
+
kind: ctx.kind,
|
|
36
|
+
name: ctx.name,
|
|
37
|
+
sessionId: ctx.session.sessionId,
|
|
38
|
+
}
|
|
39
|
+
if (ctx.kind === 'llm') {
|
|
40
|
+
options.modelName = ctx.turn.model
|
|
41
|
+
options.modelProvider = 'elevenlabs'
|
|
42
|
+
}
|
|
43
|
+
return options
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Annotation is owned by the APM pre-finish signal; the base asyncEnd would tag after serialization.
|
|
47
|
+
asyncEnd () {}
|
|
48
|
+
|
|
49
|
+
/** @param {object} ctx */
|
|
50
|
+
setLLMObsTags (ctx) {
|
|
51
|
+
const span = ctx.currentStore?.span
|
|
52
|
+
if (!span) return
|
|
53
|
+
this._tagger._setTag(span, SESSION_ID, ctx.session.sessionId)
|
|
54
|
+
const { turn } = ctx
|
|
55
|
+
const metadata = { ...turn.metadata }
|
|
56
|
+
if (ctx.activity !== undefined) metadata.user_speech_activity = ctx.activity
|
|
57
|
+
this._tagger.tagMetadata(span, metadata)
|
|
58
|
+
if (ctx.kind === 'tool') {
|
|
59
|
+
this._tagger.tagTextIO(span, JSON.stringify(ctx.parameters), ctx.output)
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
if (ctx.kind !== 'llm') {
|
|
63
|
+
if (ctx.name === 'elevenlabs audio turn') this._tagger.tagTextIO(span, turn.userText, turn.text)
|
|
64
|
+
else this._tagger.tagTextIO(span, undefined, ctx.transcript)
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
if (turn.model) this._tagger.tagModelName(span, turn.model)
|
|
68
|
+
const input = { role: 'user', content: turn.userText || '' }
|
|
69
|
+
const output = { role: 'assistant', content: turn.text || '' }
|
|
70
|
+
if (turn.calls.size) output.toolCalls = [...turn.calls.values()]
|
|
71
|
+
if (turn.results.size) input.toolResults = [...turn.results.values()]
|
|
72
|
+
// Leave room for the serialized UTF-8 text, tools, metadata, and audio-part wrappers before
|
|
73
|
+
// spending one event budget across both complete WAVs.
|
|
74
|
+
let budget = Math.max(0, LLMOBS_AUDIO_INLINE_MAX_BYTES -
|
|
75
|
+
Buffer.byteLength(JSON.stringify([[input], [output], metadata])) - 256)
|
|
76
|
+
for (const [message, audio, rate] of [
|
|
77
|
+
[input, turn.input, turn.inputRate], [output, turn.output, turn.outputRate],
|
|
78
|
+
]) {
|
|
79
|
+
if (rate && audio.size && !audio.overflow && fitsInlineAudioBudget(audio.size + 44, budget)) {
|
|
80
|
+
const part = formatAudioPartWithGuard(pcm16ToWav(audio.bytes(), rate), 'audio/wav', budget)
|
|
81
|
+
if (part) {
|
|
82
|
+
message.audioParts = [part]
|
|
83
|
+
budget -= part.content.length
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (audio.present && !message.audioParts) {
|
|
87
|
+
metadata.audio_omitted = true
|
|
88
|
+
message.content ||= AUDIO_FALLBACK
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
this._tagger.tagMetadata(span, metadata)
|
|
92
|
+
this._tagger.tagLLMIO(span, [input], [output])
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
module.exports = ElevenLabsLLMObsPlugin
|
|
@@ -92,7 +92,7 @@ class GenAiLLMObsPlugin extends LLMObsPlugin {
|
|
|
92
92
|
const inputMessages = formatInputMessages(inputs.contents)
|
|
93
93
|
|
|
94
94
|
const metadata = extractMetadata(config)
|
|
95
|
-
this._tagger.tagMetadata(span, metadata)
|
|
95
|
+
if (metadata) this._tagger.tagMetadata(span, metadata)
|
|
96
96
|
|
|
97
97
|
const toolDefinitions = extractToolDefinitions(config)
|
|
98
98
|
if (toolDefinitions.length > 0) this._tagger.tagToolDefinitions(span, toolDefinitions)
|
|
@@ -101,30 +101,43 @@ function extractMetrics (response) {
|
|
|
101
101
|
|
|
102
102
|
if (!tokenUsage) return metrics
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
// Gemini reports thinking tokens (`thoughtsTokenCount`) and tool-use prompt tokens
|
|
105
|
+
// (`toolUsePromptTokenCount`) outside of `candidatesTokenCount` / `promptTokenCount`.
|
|
106
|
+
const { thoughtsTokenCount, toolUsePromptTokenCount, cachedContentTokenCount } = tokenUsage
|
|
107
|
+
const inputTokens = (tokenUsage.promptTokenCount || 0) + (toolUsePromptTokenCount || 0)
|
|
108
|
+
const outputTokens = (tokenUsage.candidatesTokenCount || 0) + (thoughtsTokenCount || 0)
|
|
109
|
+
|
|
110
|
+
if (inputTokens) {
|
|
111
|
+
metrics.inputTokens = inputTokens
|
|
106
112
|
}
|
|
107
113
|
|
|
108
|
-
if (
|
|
109
|
-
metrics.outputTokens =
|
|
114
|
+
if (outputTokens) {
|
|
115
|
+
metrics.outputTokens = outputTokens
|
|
110
116
|
}
|
|
111
117
|
|
|
112
|
-
const totalTokens = tokenUsage.totalTokenCount ||
|
|
113
|
-
(tokenUsage.promptTokenCount || 0) + (tokenUsage.candidatesTokenCount || 0)
|
|
118
|
+
const totalTokens = tokenUsage.totalTokenCount || inputTokens + outputTokens
|
|
114
119
|
if (totalTokens) {
|
|
115
120
|
metrics.totalTokens = totalTokens
|
|
116
121
|
}
|
|
117
122
|
|
|
123
|
+
if (cachedContentTokenCount) {
|
|
124
|
+
metrics.cacheReadTokens = cachedContentTokenCount
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (thoughtsTokenCount) {
|
|
128
|
+
metrics.reasoningOutputTokens = thoughtsTokenCount
|
|
129
|
+
}
|
|
130
|
+
|
|
118
131
|
return metrics
|
|
119
132
|
}
|
|
120
133
|
|
|
121
134
|
/**
|
|
122
135
|
* Extract metadata from config
|
|
123
136
|
* @param {object} config
|
|
124
|
-
* @returns {object}
|
|
137
|
+
* @returns {object | undefined}
|
|
125
138
|
*/
|
|
126
139
|
function extractMetadata (config) {
|
|
127
|
-
if (!config) return
|
|
140
|
+
if (!config) return
|
|
128
141
|
|
|
129
142
|
const fieldMap = {
|
|
130
143
|
temperature: 'temperature',
|
|
@@ -143,9 +156,13 @@ function extractMetadata (config) {
|
|
|
143
156
|
automatic_function_calling: 'automaticFunctionCalling',
|
|
144
157
|
}
|
|
145
158
|
|
|
146
|
-
|
|
159
|
+
let metadata
|
|
147
160
|
for (const [metadataKey, configKey] of Object.entries(fieldMap)) {
|
|
148
|
-
|
|
161
|
+
const value = config[configKey]
|
|
162
|
+
if (value != null) {
|
|
163
|
+
metadata ??= {}
|
|
164
|
+
metadata[metadataKey] = value
|
|
165
|
+
}
|
|
149
166
|
}
|
|
150
167
|
|
|
151
168
|
return metadata
|
|
@@ -120,26 +120,53 @@ function buildMessage (role, side, maxAudioBytes) {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
|
-
* @param {{
|
|
123
|
+
* @param {{
|
|
124
|
+
* input_tokens?: number, output_tokens?: number, total_tokens?: number,
|
|
125
|
+
* input_token_details?: {
|
|
126
|
+
* audio_tokens?: number, text_tokens?: number, image_tokens?: number, cached_tokens?: number,
|
|
127
|
+
* cached_tokens_details?: { audio_tokens?: number, text_tokens?: number, image_tokens?: number }
|
|
128
|
+
* },
|
|
129
|
+
* output_token_details?: { audio_tokens?: number, text_tokens?: number }
|
|
130
|
+
* } | undefined} usage
|
|
124
131
|
* @returns {Record<string, number> | undefined}
|
|
125
132
|
*/
|
|
126
133
|
function usageMetrics (usage) {
|
|
127
134
|
if (!usage) return
|
|
128
135
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
136
|
+
// Named modality and cache counts are subsets of the inclusive totals.
|
|
137
|
+
// Missing details stay absent; never infer text or a cache intersection.
|
|
138
|
+
const inputDetails = usage.input_token_details
|
|
139
|
+
const counts = {
|
|
140
|
+
input_tokens: usage.input_tokens,
|
|
141
|
+
output_tokens: usage.output_tokens,
|
|
142
|
+
total_tokens: usage.total_tokens,
|
|
143
|
+
cache_read_input_tokens: inputDetails?.cached_tokens,
|
|
144
|
+
input_audio_tokens: inputDetails?.audio_tokens,
|
|
145
|
+
input_text_tokens: inputDetails?.text_tokens,
|
|
146
|
+
input_image_tokens: inputDetails?.image_tokens,
|
|
147
|
+
output_audio_tokens: usage.output_token_details?.audio_tokens,
|
|
148
|
+
output_text_tokens: usage.output_token_details?.text_tokens,
|
|
149
|
+
cache_audio_read_tokens: inputDetails?.cached_tokens_details?.audio_tokens,
|
|
150
|
+
cache_text_read_tokens: inputDetails?.cached_tokens_details?.text_tokens,
|
|
151
|
+
cache_image_read_tokens: inputDetails?.cached_tokens_details?.image_tokens,
|
|
152
|
+
}
|
|
132
153
|
/** @type {Record<string, number>} */
|
|
133
154
|
const metrics = {}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
155
|
+
let hasMetrics = false
|
|
156
|
+
for (const [key, value] of Object.entries(counts)) {
|
|
157
|
+
if (typeof value === 'number' && Number.isSafeInteger(value) && value >= 0) {
|
|
158
|
+
metrics[key] = value
|
|
159
|
+
hasMetrics = true
|
|
160
|
+
}
|
|
139
161
|
}
|
|
140
|
-
if (totalTokens != null) metrics.total_tokens = totalTokens
|
|
141
162
|
|
|
142
|
-
|
|
163
|
+
// Preserve the existing total fallback only when no total was supplied. Both
|
|
164
|
+
// components and their sum must be valid; an invalid reported total stays absent.
|
|
165
|
+
if (usage.total_tokens == null && metrics.input_tokens !== undefined && metrics.output_tokens !== undefined) {
|
|
166
|
+
const total = metrics.input_tokens + metrics.output_tokens
|
|
167
|
+
if (Number.isSafeInteger(total)) metrics.total_tokens = total
|
|
168
|
+
}
|
|
169
|
+
return hasMetrics ? metrics : undefined
|
|
143
170
|
}
|
|
144
171
|
|
|
145
172
|
/**
|