dd-trace 5.135.0 → 5.137.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/README.md +3 -0
- package/ci/cypress/support.js +2 -1
- package/ci/init.js +2 -22
- package/ci/vitest-no-worker-init-node-setup.mjs +2 -1
- package/ci/vitest-no-worker-init-runner-setup.mjs +2 -1
- package/ci/vitest-no-worker-init-setup.mjs +729 -724
- package/ci/vitest-no-worker-init-v5-setup.mjs +2 -1
- package/ext/exporters.js +0 -1
- package/index.d.ts +105 -5
- package/initialize.mjs +5 -2
- package/package.json +41 -36
- package/packages/datadog-esbuild/index.js +16 -70
- package/packages/datadog-esbuild/src/log.js +2 -29
- package/packages/datadog-instrumentations/src/ai.js +6 -1
- package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
- package/packages/datadog-instrumentations/src/cucumber.js +5 -2
- package/packages/datadog-instrumentations/src/cypress-config.js +20 -9
- 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 +20 -17
- package/packages/datadog-instrumentations/src/helpers/bundler-esm-exports.js +582 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-log.js +38 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +576 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
- package/packages/datadog-instrumentations/src/helpers/fetch.js +51 -6
- package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
- package/packages/datadog-instrumentations/src/helpers/hooks.js +3 -7
- package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +8 -0
- 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.js +0 -36
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-client.js +30 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-server.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +61 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/postgres.js +33 -4
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +80 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +23 -3
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms/postgres.js +122 -0
- 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/microgateway-core.js +1 -2
- package/packages/datadog-instrumentations/src/modelcontextprotocol-client.js +21 -0
- package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +7 -1
- package/packages/datadog-instrumentations/src/modelcontextprotocol-server.js +41 -0
- package/packages/datadog-instrumentations/src/next.js +203 -26
- 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/otel-sdk-trace.js +11 -9
- package/packages/datadog-instrumentations/src/router.js +35 -12
- package/packages/datadog-instrumentations/src/vitest-main.js +10 -2
- 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/arn.js +41 -0
- package/packages/datadog-plugin-aws-lambda/src/event-type-guards.js +170 -0
- package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
- package/packages/datadog-plugin-aws-lambda/src/trigger.js +339 -0
- package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +7 -0
- package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +32 -10
- package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +10 -1
- package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +4 -0
- package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +3 -0
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +50 -13
- package/packages/datadog-plugin-cypress/src/support.mjs +1353 -0
- package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
- package/packages/datadog-plugin-express/src/code_origin.js +2 -2
- package/packages/datadog-plugin-fastify/src/code_origin.js +2 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +20 -7
- package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +21 -52
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +11 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
- package/packages/datadog-plugin-google-cloud-pubsub/src/resource-names.js +24 -0
- package/packages/datadog-plugin-graphql/src/tools/transforms.js +1 -0
- package/packages/datadog-plugin-http/src/client.js +34 -10
- package/packages/datadog-plugin-http2/src/client.js +40 -14
- package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +28 -2
- package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +1 -0
- package/packages/datadog-plugin-mongodb-core/src/query.js +17 -1
- package/packages/datadog-plugin-next/src/index.js +112 -14
- package/packages/datadog-plugin-postgres/src/index.js +118 -41
- package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
- package/packages/datadog-plugin-supabase/src/supabase-auth-js-gotrueclient-getuser.js +18 -8
- package/packages/datadog-plugin-supabase/src/supabase-functions-js-functionsclient-invoke.js +49 -13
- package/packages/datadog-plugin-supabase/src/supabase-storage-js-handle-request.js +34 -9
- 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-undici/src/index.js +22 -7
- package/packages/datadog-plugin-vitest/src/index.js +3 -2
- package/packages/datadog-plugin-ws/src/close.js +3 -5
- package/packages/datadog-plugin-ws/src/producer.js +1 -4
- package/packages/datadog-plugin-ws/src/receiver.js +3 -5
- package/packages/datadog-plugin-ws/src/server.js +44 -13
- package/packages/datadog-turbopack/index.js +4 -28
- package/packages/datadog-turbopack/src/loader.js +14 -452
- package/packages/datadog-vite/index.js +537 -0
- package/packages/datadog-vite/src/log.js +5 -0
- package/packages/datadog-webpack/index.js +3 -55
- package/packages/datadog-webpack/src/log.js +2 -29
- package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
- package/packages/dd-trace/src/aiguard/index.js +1 -1
- package/packages/dd-trace/src/aiguard/integrations/index.js +6 -5
- package/packages/dd-trace/src/aiguard/sdk.js +8 -2
- package/packages/dd-trace/src/aiguard/tags.js +2 -0
- package/packages/dd-trace/src/appsec/blocking/index.js +21 -1
- package/packages/dd-trace/src/appsec/channels.js +7 -0
- package/packages/dd-trace/src/appsec/downstream_requests.js +105 -0
- package/packages/dd-trace/src/appsec/graphql.js +89 -7
- package/packages/dd-trace/src/appsec/handlers/auth.js +1 -3
- package/packages/dd-trace/src/appsec/handlers/http-request.js +60 -65
- package/packages/dd-trace/src/appsec/handlers/http-response.js +61 -7
- package/packages/dd-trace/src/appsec/handlers/payments.js +23 -27
- package/packages/dd-trace/src/appsec/index.js +6 -0
- package/packages/dd-trace/src/appsec/lambda.js +17 -17
- package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -4
- package/packages/dd-trace/src/appsec/rasp/index.js +8 -1
- package/packages/dd-trace/src/appsec/rasp/lfi.js +2 -2
- package/packages/dd-trace/src/appsec/rasp/sql_injection.js +7 -17
- package/packages/dd-trace/src/appsec/rasp/ssrf.js +80 -16
- package/packages/dd-trace/src/appsec/rasp/utils.js +33 -3
- package/packages/dd-trace/src/appsec/recommended.json +1358 -94
- package/packages/dd-trace/src/appsec/reporter.js +9 -0
- package/packages/dd-trace/src/appsec/sdk/set_user.js +3 -3
- package/packages/dd-trace/src/appsec/sdk/track_event.js +4 -4
- package/packages/dd-trace/src/appsec/sdk/user_blocking.js +1 -1
- package/packages/dd-trace/src/appsec/user_tracking.js +6 -8
- package/packages/dd-trace/src/appsec/waf/index.js +65 -6
- package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +33 -38
- package/packages/dd-trace/src/appsec/waf/waf_manager.js +18 -2
- 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 +15 -2
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +12 -34
- 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 +1 -2
- package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +1 -1
- package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
- package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +1 -1
- 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 +5 -0
- package/packages/dd-trace/src/config/generated-config-types.d.ts +46 -4
- package/packages/dd-trace/src/config/index.js +63 -31
- package/packages/dd-trace/src/config/parsers.js +44 -0
- package/packages/dd-trace/src/config/remote-config-layers.js +38 -0
- package/packages/dd-trace/src/config/remote_config.js +2 -1
- package/packages/dd-trace/src/config/supported-configurations.json +172 -10
- package/packages/dd-trace/src/constants.js +1 -0
- package/packages/dd-trace/src/datastreams/fnv.js +27 -0
- package/packages/dd-trace/src/datastreams/pathway.js +113 -28
- package/packages/dd-trace/src/datastreams/processor.js +5 -4
- package/packages/dd-trace/src/debugger/config.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/request-options.js +7 -9
- package/packages/dd-trace/src/debugger/devtools_client/send.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
- package/packages/dd-trace/src/debugger/devtools_client/tags.js +1 -1
- package/packages/dd-trace/src/debugger/index.js +2 -2
- package/packages/dd-trace/src/debugger/inspect-segment.js +3 -2
- package/packages/dd-trace/src/debugger/pause-duration-histogram.js +6 -2
- package/packages/dd-trace/src/debugger/probe_sampler.js +39 -17
- package/packages/dd-trace/src/debugger/unsupported-runtime.js +2 -0
- package/packages/dd-trace/src/exporter.js +0 -11
- package/packages/dd-trace/src/exporters/common/request.js +81 -48
- 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/git_metadata.js +2 -1
- package/packages/dd-trace/src/id.js +1 -1
- package/packages/dd-trace/src/index.js +6 -3
- package/packages/dd-trace/src/lambda/facade.js +75 -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 +2 -0
- package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
- package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
- package/packages/dd-trace/src/llmobs/plugins/genai/util.js +19 -6
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +54 -3
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +81 -1
- package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
- package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
- package/packages/dd-trace/src/llmobs/sdk.js +19 -0
- package/packages/dd-trace/src/llmobs/span_processor.js +9 -0
- package/packages/dd-trace/src/llmobs/tagger.js +22 -0
- package/packages/dd-trace/src/log/channels.js +4 -0
- package/packages/dd-trace/src/log/writer.js +6 -1
- package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +7 -0
- package/packages/dd-trace/src/openfeature/configuration_source.js +55 -27
- package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
- package/packages/dd-trace/src/openfeature/flagging_provider.js +19 -1
- package/packages/dd-trace/src/openfeature/writers/base.js +1 -3
- 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/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/opentracing/propagation/tracestate.js +77 -23
- package/packages/dd-trace/src/opentracing/tracer.js +24 -0
- package/packages/dd-trace/src/otel-thread-ctx.js +28 -31
- package/packages/dd-trace/src/plugin_manager.js +34 -7
- package/packages/dd-trace/src/plugins/ci_plugin.js +143 -17
- package/packages/dd-trace/src/plugins/index.js +8 -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 +52 -1
- package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
- package/packages/dd-trace/src/plugins/util/git.js +263 -82
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +80 -56
- 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 +92 -40
- package/packages/dd-trace/src/plugins/util/url.js +18 -7
- package/packages/dd-trace/src/plugins/util/user-provided-git.js +6 -6
- package/packages/dd-trace/src/plugins/util/web.js +65 -10
- package/packages/dd-trace/src/process-tags/index.js +1 -1
- package/packages/dd-trace/src/profiler.js +74 -12
- package/packages/dd-trace/src/profiling/profiler.js +30 -2
- package/packages/dd-trace/src/profiling/profilers/space.js +3 -1
- package/packages/dd-trace/src/profiling/profilers/wall.js +4 -4
- package/packages/dd-trace/src/profiling/remote-config.js +354 -0
- package/packages/dd-trace/src/profiling/runtime-capabilities.js +11 -0
- package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
- package/packages/dd-trace/src/propagation-hash/index.js +7 -0
- package/packages/dd-trace/src/proxy.js +46 -54
- package/packages/dd-trace/src/span_processor.js +20 -0
- package/packages/dd-trace/src/startup-log.js +8 -6
- package/packages/dd-trace/src/telemetry/metrics.js +2 -1
- package/packages/dd-trace/src/tracer.js +0 -2
- package/packages/dd-trace/src/web-tags-cache.js +8 -9
- package/register.js +2 -1
- package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
- package/vendor/dist/@datadog/flagging-core/LICENSE +221 -0
- 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/rules-based/LICENSE +3 -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 +220 -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/vite.d.ts +7 -0
- package/vite.js +3 -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 -18
- 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 -649
- 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/datadog-esbuild/src/utils.js +0 -318
- package/packages/datadog-plugin-cypress/src/support.js +0 -1348
- 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
|
@@ -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',
|
|
@@ -63,6 +64,7 @@ module.exports = {
|
|
|
63
64
|
DEFAULT_MODEL: 'custom',
|
|
64
65
|
|
|
65
66
|
INPUT_DOCUMENTS: '_ml_obs.meta.input.documents',
|
|
67
|
+
EXPERIMENT_EXPECTED_OUTPUT: '_ml_obs.meta.expected_output',
|
|
66
68
|
EXPERIMENT_INPUT: '_ml_obs.meta.input',
|
|
67
69
|
INPUT_MESSAGES: '_ml_obs.meta.input.messages',
|
|
68
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
|
})
|
|
@@ -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
|
|
@@ -101,20 +101,33 @@ 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
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const LLMObsPlugin = require('../base')
|
|
4
|
-
const { formatInput, formatOutput } = require('./utils')
|
|
4
|
+
const { formatInput, formatOutput, formatServerInput, getClientInfoTags, safeStringify } = require('./utils')
|
|
5
5
|
|
|
6
6
|
class McpToolCallLLMObsPlugin extends LLMObsPlugin {
|
|
7
7
|
static id = 'llmobs_mcp_tool_call'
|
|
@@ -61,8 +61,59 @@ class McpListToolsLLMObsPlugin extends LLMObsPlugin {
|
|
|
61
61
|
const span = ctx.currentStore?.span
|
|
62
62
|
if (!span || ctx.error) return
|
|
63
63
|
|
|
64
|
-
this._tagger.tagTextIO(span, null,
|
|
64
|
+
this._tagger.tagTextIO(span, null, safeStringify(ctx.result))
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
class McpServerRequestLLMObsPlugin extends LLMObsPlugin {
|
|
69
|
+
static id = 'llmobs_mcp_server_request'
|
|
70
|
+
static integration = 'modelcontextprotocol-sdk'
|
|
71
|
+
static prefix = 'tracing:apm:mcp:server:request'
|
|
72
|
+
|
|
73
|
+
getLLMObsSpanRegisterOptions (ctx) {
|
|
74
|
+
const { request } = ctx
|
|
75
|
+
if (request?.method === 'tools/call') {
|
|
76
|
+
return { kind: 'tool', name: request.params?.name || 'unknown_tool' }
|
|
77
|
+
}
|
|
78
|
+
return { kind: 'task', name: `mcp.${request?.method ?? 'unknown'}` }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
setLLMObsTags (ctx) {
|
|
82
|
+
const span = ctx.currentStore?.span
|
|
83
|
+
if (!span) return
|
|
84
|
+
|
|
85
|
+
const { request, extra, server } = ctx
|
|
86
|
+
const spanTags = {
|
|
87
|
+
mcp_method: request?.method,
|
|
88
|
+
...getClientInfoTags(extra?.mcpReq?.envelope, server),
|
|
89
|
+
}
|
|
90
|
+
const sessionId = extra?.sessionId ?? server?.transport?.sessionId
|
|
91
|
+
if (sessionId) spanTags.mcp_session_id = String(sessionId)
|
|
92
|
+
if (request?.method === 'tools/call') {
|
|
93
|
+
spanTags.mcp_tool = request.params?.name || 'unknown_tool'
|
|
94
|
+
spanTags.mcp_tool_kind = 'server'
|
|
95
|
+
}
|
|
96
|
+
this._tagger.tagSpanTags(span, spanTags)
|
|
97
|
+
|
|
98
|
+
const output = ctx.error ? undefined : safeStringify(ctx.result)
|
|
99
|
+
this._tagger.tagTextIO(span, formatServerInput(request, extra?.mcpReq), output)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
class McpToolCallV2LLMObsPlugin extends McpToolCallLLMObsPlugin {
|
|
104
|
+
static id = 'llmobs_mcp_tool_call_v2'
|
|
105
|
+
static prefix = 'tracing:orchestrion:@modelcontextprotocol/client:Client_callTool'
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
class McpListToolsV2LLMObsPlugin extends McpListToolsLLMObsPlugin {
|
|
109
|
+
static id = 'llmobs_mcp_list_tools_v2'
|
|
110
|
+
static prefix = 'tracing:orchestrion:@modelcontextprotocol/client:Client_listTools'
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
module.exports = [
|
|
114
|
+
McpToolCallLLMObsPlugin,
|
|
115
|
+
McpListToolsLLMObsPlugin,
|
|
116
|
+
McpToolCallV2LLMObsPlugin,
|
|
117
|
+
McpListToolsV2LLMObsPlugin,
|
|
118
|
+
McpServerRequestLLMObsPlugin,
|
|
119
|
+
]
|
|
@@ -52,4 +52,84 @@ function formatOutput (result) {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
const DISTRIBUTED_TRACE_META_KEY = '_dd_trace_context'
|
|
56
|
+
const CLIENT_INFO_META_KEY = 'io.modelcontextprotocol/clientInfo'
|
|
57
|
+
const MAX_CLIENT_INFO_TAG_LENGTH = 256
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {unknown} value
|
|
61
|
+
*/
|
|
62
|
+
function safeStringify (value) {
|
|
63
|
+
if (value === undefined) return
|
|
64
|
+
try {
|
|
65
|
+
return JSON.stringify(value)
|
|
66
|
+
} catch {}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Copies `_meta` keys except the trace context.
|
|
71
|
+
* @param {Record<string, unknown>} target
|
|
72
|
+
* @param {Record<string, unknown>} [source]
|
|
73
|
+
*/
|
|
74
|
+
function copyMetaKeys (target, source) {
|
|
75
|
+
if (!source) return false
|
|
76
|
+
|
|
77
|
+
let copied = false
|
|
78
|
+
for (const key of Object.keys(source)) {
|
|
79
|
+
if (key === DISTRIBUTED_TRACE_META_KEY) continue
|
|
80
|
+
target[key] = source[key]
|
|
81
|
+
copied = true
|
|
82
|
+
}
|
|
83
|
+
return copied
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Formats a server request as JSON-RPC without the trace context. Before a handler runs, SDK 2.x moves the reserved
|
|
88
|
+
* `io.modelcontextprotocol/*` `_meta` keys into `mcpReq.envelope` and drops the JSON-RPC id. Both are put back, so the
|
|
89
|
+
* input matches the request that the client sent.
|
|
90
|
+
* @param {{ method?: string, id?: string|number, params?: { _meta?: Record<string, unknown> } }} [request]
|
|
91
|
+
* @param {{ id?: string|number, envelope?: Record<string, unknown> }} [mcpReq]
|
|
92
|
+
*/
|
|
93
|
+
function formatServerInput (request, mcpReq) {
|
|
94
|
+
let params = request?.params
|
|
95
|
+
const meta = {}
|
|
96
|
+
const hasEnvelopeKeys = copyMetaKeys(meta, mcpReq?.envelope)
|
|
97
|
+
const hasRequestKeys = copyMetaKeys(meta, params?._meta)
|
|
98
|
+
|
|
99
|
+
const rest = {}
|
|
100
|
+
let hasRest = false
|
|
101
|
+
if (params) {
|
|
102
|
+
for (const [key, value] of Object.entries(params)) {
|
|
103
|
+
if (key === '_meta') continue
|
|
104
|
+
rest[key] = value
|
|
105
|
+
hasRest = true
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (hasEnvelopeKeys || hasRequestKeys) {
|
|
109
|
+
params = { ...rest, _meta: meta }
|
|
110
|
+
} else if (params?._meta !== undefined) {
|
|
111
|
+
// `_meta` held only the trace context that the client tracer added, so drop `params` if nothing else is left.
|
|
112
|
+
params = hasRest ? rest : undefined
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return safeStringify({ method: request?.method, params, jsonrpc: '2.0', id: request?.id ?? mcpReq?.id })
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Client identity comes from the request envelope on stateless requests and from the handshake otherwise.
|
|
120
|
+
* @param {Record<string, unknown>} [envelope]
|
|
121
|
+
* @param {{ getClientVersion?: () => unknown }} [server]
|
|
122
|
+
*/
|
|
123
|
+
function getClientInfoTags (envelope, server) {
|
|
124
|
+
const clientInfo = envelope?.[CLIENT_INFO_META_KEY] ?? server?.getClientVersion?.()
|
|
125
|
+
const tags = {}
|
|
126
|
+
if (!clientInfo || typeof clientInfo !== 'object') return tags
|
|
127
|
+
|
|
128
|
+
for (const field of ['name', 'title', 'version']) {
|
|
129
|
+
const value = clientInfo[field]
|
|
130
|
+
if (value) tags[`mcp_client_${field}`] = String(value).slice(0, MAX_CLIENT_INFO_TAG_LENGTH)
|
|
131
|
+
}
|
|
132
|
+
return tags
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
module.exports = { formatInput, formatOutput, formatServerInput, getClientInfoTags, safeStringify }
|
|
@@ -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
|
/**
|
|
@@ -187,9 +187,17 @@ function extractMetrics (result) {
|
|
|
187
187
|
const tokenCounts = response.usageMetadata
|
|
188
188
|
const metrics = {}
|
|
189
189
|
if (tokenCounts) {
|
|
190
|
-
|
|
191
|
-
|
|
190
|
+
const { thoughtsTokenCount, toolUsePromptTokenCount, cachedContentTokenCount } = tokenCounts
|
|
191
|
+
// Gemini reports thinking and tool-use prompt tokens outside the prompt/candidates counts.
|
|
192
|
+
metrics.inputTokens = toolUsePromptTokenCount
|
|
193
|
+
? (tokenCounts.promptTokenCount || 0) + toolUsePromptTokenCount
|
|
194
|
+
: tokenCounts.promptTokenCount
|
|
195
|
+
metrics.outputTokens = thoughtsTokenCount
|
|
196
|
+
? (tokenCounts.candidatesTokenCount || 0) + thoughtsTokenCount
|
|
197
|
+
: tokenCounts.candidatesTokenCount
|
|
192
198
|
metrics.totalTokens = tokenCounts.totalTokenCount
|
|
199
|
+
if (cachedContentTokenCount) metrics.cacheReadTokens = cachedContentTokenCount
|
|
200
|
+
if (thoughtsTokenCount) metrics.reasoningOutputTokens = thoughtsTokenCount
|
|
193
201
|
}
|
|
194
202
|
|
|
195
203
|
return metrics
|
|
@@ -361,6 +361,23 @@ class LLMObs extends NoopLLMObs {
|
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
+
/**
|
|
365
|
+
* Annotates an experiment row span with its inputs, outputs, and expected output.
|
|
366
|
+
*
|
|
367
|
+
* @param {import('../opentracing/span')} span
|
|
368
|
+
* @param {{
|
|
369
|
+
* inputData: unknown,
|
|
370
|
+
* outputData: unknown,
|
|
371
|
+
* expectedOutput: unknown,
|
|
372
|
+
* metadata: object,
|
|
373
|
+
* tags: object
|
|
374
|
+
* }} options
|
|
375
|
+
*/
|
|
376
|
+
_annotateExperimentSpan (span, options) {
|
|
377
|
+
this.annotate(span, options)
|
|
378
|
+
this._tagger.tagExperimentExpectedOutput(span, options.expectedOutput)
|
|
379
|
+
}
|
|
380
|
+
|
|
364
381
|
exportSpan (span) {
|
|
365
382
|
span ||= this._active()
|
|
366
383
|
let err = ''
|
|
@@ -728,6 +745,7 @@ class LLMObs extends NoopLLMObs {
|
|
|
728
745
|
mlApp,
|
|
729
746
|
version,
|
|
730
747
|
_decorator,
|
|
748
|
+
_experimentTags,
|
|
731
749
|
...spanOptions
|
|
732
750
|
} = options
|
|
733
751
|
|
|
@@ -747,6 +765,7 @@ class LLMObs extends NoopLLMObs {
|
|
|
747
765
|
sessionId,
|
|
748
766
|
agentVersion,
|
|
749
767
|
_decorator,
|
|
768
|
+
_experimentTags,
|
|
750
769
|
spanOptions,
|
|
751
770
|
}
|
|
752
771
|
}
|