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
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const LLMObsPlugin = require('../base')
|
|
4
|
+
|
|
5
|
+
const TYPESAFE_MODEL_PROVIDER = 'typesafe'
|
|
6
|
+
const OPENROUTER_MODEL_PROVIDER = 'openrouter'
|
|
7
|
+
const DECISION_PROVIDER_TAG = 'decision_provider'
|
|
8
|
+
const DECISION_PROVIDER = 'typesafe'
|
|
9
|
+
|
|
10
|
+
class TypeSafeLLMObsPlugin extends LLMObsPlugin {
|
|
11
|
+
static integration = 'typesafe' // used for llmobs telemetry
|
|
12
|
+
static id = 'typesafe'
|
|
13
|
+
static prefix = 'tracing:orchestrion:@typesafe-ai/sdk:TypeSafeClient_systemOne'
|
|
14
|
+
|
|
15
|
+
getLLMObsSpanRegisterOptions (ctx) {
|
|
16
|
+
return {
|
|
17
|
+
kind: 'llm',
|
|
18
|
+
modelName: getModelName(ctx),
|
|
19
|
+
modelProvider: getModelProvider(ctx.self?.baseURL),
|
|
20
|
+
name: 'typesafe.request',
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @override
|
|
26
|
+
*/
|
|
27
|
+
getGenAiApmEndTags (ctx) {
|
|
28
|
+
return { modelName: ctx.result?.model, metrics: extractMetrics(ctx.result) }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
setLLMObsTags (ctx) {
|
|
32
|
+
const span = ctx.currentStore?.span
|
|
33
|
+
if (!span) return
|
|
34
|
+
|
|
35
|
+
this._tagger.tagSpanTags(span, { [DECISION_PROVIDER_TAG]: DECISION_PROVIDER })
|
|
36
|
+
|
|
37
|
+
const { result, responseText } = ctx
|
|
38
|
+
const inputMessages = [{ role: 'user', content: serializeRequest(ctx) ?? '' }]
|
|
39
|
+
|
|
40
|
+
if (ctx.error || responseText === undefined) {
|
|
41
|
+
this._tagger.tagLLMIO(span, inputMessages, [{ content: '' }])
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
this._tagger.tagLLMIO(span, inputMessages, [{ role: 'assistant', content: responseText }])
|
|
46
|
+
|
|
47
|
+
const metrics = extractMetrics(result)
|
|
48
|
+
if (metrics) this._tagger.tagMetrics(span, metrics)
|
|
49
|
+
|
|
50
|
+
if (result?.model) this._tagger.tagModelName(span, result.model)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {object} ctx
|
|
56
|
+
* @returns {string|undefined}
|
|
57
|
+
*/
|
|
58
|
+
function getModelName (ctx) {
|
|
59
|
+
return ctx.arguments?.[0]?.model ?? ctx.self?.defaultModel
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The SDK can be pointed at OpenRouter, which serves the same System One API.
|
|
64
|
+
*
|
|
65
|
+
* @param {string} [baseURL]
|
|
66
|
+
*/
|
|
67
|
+
function getModelProvider (baseURL = '') {
|
|
68
|
+
return baseURL.toLowerCase().includes(OPENROUTER_MODEL_PROVIDER) ? OPENROUTER_MODEL_PROVIDER : TYPESAFE_MODEL_PROVIDER
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @param {object} [result]
|
|
73
|
+
* @returns {Record<string, number>|undefined}
|
|
74
|
+
*/
|
|
75
|
+
function extractMetrics (result) {
|
|
76
|
+
const usage = result?.usage
|
|
77
|
+
if (!usage) return
|
|
78
|
+
|
|
79
|
+
const { input_tokens: inputTokens, output_tokens: outputTokens } = usage
|
|
80
|
+
const metrics = {}
|
|
81
|
+
if (inputTokens != null) metrics.inputTokens = inputTokens
|
|
82
|
+
if (outputTokens != null) metrics.outputTokens = outputTokens
|
|
83
|
+
// A total is only known when both counts are
|
|
84
|
+
if (inputTokens != null && outputTokens != null) metrics.totalTokens = inputTokens + outputTokens
|
|
85
|
+
return metrics
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The request as `systemOne` received it, with the model the SDK fills in. Serialized at finish, after the SDK has
|
|
90
|
+
* serialized it to send.
|
|
91
|
+
*
|
|
92
|
+
* @param {object} ctx
|
|
93
|
+
*/
|
|
94
|
+
function serializeRequest (ctx) {
|
|
95
|
+
const { request } = ctx
|
|
96
|
+
if (!request) return
|
|
97
|
+
try {
|
|
98
|
+
return JSON.stringify({ ...request, model: request.model ?? ctx.self?.defaultModel })
|
|
99
|
+
} catch {}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module.exports = TypeSafeLLMObsPlugin
|
|
@@ -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
|
|
@@ -171,7 +171,9 @@ class WarmCache {
|
|
|
171
171
|
#deserialize (data) {
|
|
172
172
|
const validTemplate = typeof data?.template === 'string' || (
|
|
173
173
|
Array.isArray(data?.template) && data.template.every(message => {
|
|
174
|
-
return message &&
|
|
174
|
+
return message && (message.type === 'placeholder'
|
|
175
|
+
? typeof message.name === 'string'
|
|
176
|
+
: typeof message.role === 'string' && typeof message.content === 'string')
|
|
175
177
|
})
|
|
176
178
|
)
|
|
177
179
|
if (
|
|
@@ -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 = ''
|
|
@@ -657,7 +674,8 @@ class LLMObs extends NoopLLMObs {
|
|
|
657
674
|
flush () {
|
|
658
675
|
if (!this.enabled) return
|
|
659
676
|
|
|
660
|
-
flushCh.publish()
|
|
677
|
+
flushCh.publish() // communicates with llmobs-specific writers
|
|
678
|
+
this._tracer.flushAll?.() // trigger any flushes for meta_struct-bound llmobs spans
|
|
661
679
|
}
|
|
662
680
|
|
|
663
681
|
#autoAnnotate (span, kind, input, output) {
|
|
@@ -727,6 +745,7 @@ class LLMObs extends NoopLLMObs {
|
|
|
727
745
|
mlApp,
|
|
728
746
|
version,
|
|
729
747
|
_decorator,
|
|
748
|
+
_experimentTags,
|
|
730
749
|
...spanOptions
|
|
731
750
|
} = options
|
|
732
751
|
|
|
@@ -746,6 +765,7 @@ class LLMObs extends NoopLLMObs {
|
|
|
746
765
|
sessionId,
|
|
747
766
|
agentVersion,
|
|
748
767
|
_decorator,
|
|
768
|
+
_experimentTags,
|
|
749
769
|
spanOptions,
|
|
750
770
|
}
|
|
751
771
|
}
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const util = require('node:util')
|
|
4
4
|
|
|
5
|
+
const { AUTO_REJECT } = require('../../../../ext/priority')
|
|
5
6
|
const tracerVersion = require('../../../../package.json').version
|
|
6
7
|
const logger = require('../log')
|
|
8
|
+
const LLMObsExporter = require('../exporters/llmobs')
|
|
9
|
+
const { getEnvironmentVariable } = require('../config/helper')
|
|
7
10
|
const {
|
|
8
11
|
ERROR_MESSAGE,
|
|
9
12
|
ERROR_TYPE,
|
|
@@ -13,6 +16,7 @@ const {
|
|
|
13
16
|
SPAN_KIND,
|
|
14
17
|
MODEL_NAME,
|
|
15
18
|
MODEL_PROVIDER,
|
|
19
|
+
EXPERIMENT_EXPECTED_OUTPUT,
|
|
16
20
|
METADATA,
|
|
17
21
|
COST_TAGS,
|
|
18
22
|
AGENT_MANIFEST,
|
|
@@ -44,6 +48,7 @@ const {
|
|
|
44
48
|
SAMPLE_RATE,
|
|
45
49
|
SAMPLING_DECISION,
|
|
46
50
|
TRACE_ID,
|
|
51
|
+
LLMOBS_META_STRUCT_KEY,
|
|
47
52
|
DEFAULT_MODEL,
|
|
48
53
|
} = require('./constants/tags')
|
|
49
54
|
const { UNSERIALIZABLE_VALUE_TEXT } = require('./constants/text')
|
|
@@ -72,6 +77,11 @@ class LLMObservabilitySpan {
|
|
|
72
77
|
}
|
|
73
78
|
|
|
74
79
|
class LLMObsSpanProcessor {
|
|
80
|
+
/** @type {Map<import('../opentracing/span'), object>} */
|
|
81
|
+
#cachedEvents = new Map()
|
|
82
|
+
|
|
83
|
+
#destroyer
|
|
84
|
+
|
|
75
85
|
/** @type {import('../config/config-base')} */
|
|
76
86
|
#config
|
|
77
87
|
|
|
@@ -83,6 +93,9 @@ class LLMObsSpanProcessor {
|
|
|
83
93
|
|
|
84
94
|
constructor (config) {
|
|
85
95
|
this.#config = config
|
|
96
|
+
|
|
97
|
+
this.#destroyer = this.destroy.bind(this)
|
|
98
|
+
globalThis[Symbol.for('dd-trace')].beforeExitHandlers.add(this.#destroyer)
|
|
86
99
|
}
|
|
87
100
|
|
|
88
101
|
setUserSpanProcessor (userSpanProcessor) {
|
|
@@ -115,18 +128,18 @@ class LLMObsSpanProcessor {
|
|
|
115
128
|
site: mlObsTags[ROUTING_SITE],
|
|
116
129
|
}
|
|
117
130
|
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
131
|
+
const metaStructTags = {
|
|
132
|
+
mlApp: mlObsTags[ML_APP],
|
|
133
|
+
sampleRate: mlObsTags[SAMPLE_RATE],
|
|
134
|
+
samplingDecision: mlObsTags[SAMPLING_DECISION],
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const trace = span.context()._trace
|
|
138
|
+
const useApmIntake = span.tracer()._exporter instanceof LLMObsExporter
|
|
139
|
+
if (!useApmIntake || this.#config.DD_TRACE_ENABLED === false || !trace || trace.record === false) {
|
|
140
|
+
this.#appendToWriter(span, formattedEvent, routing)
|
|
141
|
+
} else {
|
|
142
|
+
this.#cachedEvents.set(span, { event: formattedEvent, metaStructTags, routing })
|
|
130
143
|
}
|
|
131
144
|
} catch (e) {
|
|
132
145
|
// this should be a rare case
|
|
@@ -139,6 +152,59 @@ class LLMObsSpanProcessor {
|
|
|
139
152
|
}
|
|
140
153
|
}
|
|
141
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Routes cached events once the APM processor has finalized whether the trace chunk can be exported.
|
|
157
|
+
* @param {{
|
|
158
|
+
* spans: import('../opentracing/span')[],
|
|
159
|
+
* willExport: boolean,
|
|
160
|
+
* }} trace
|
|
161
|
+
*/
|
|
162
|
+
processTrace ({ spans, willExport }) {
|
|
163
|
+
for (const span of spans) {
|
|
164
|
+
const cached = this.#cachedEvents.get(span)
|
|
165
|
+
if (!cached) continue
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
const { event, metaStructTags, routing } = cached
|
|
169
|
+
if (this.#shouldAttachMetaStruct(span, routing, event, willExport)) {
|
|
170
|
+
this.#attachMetaStruct(span, event, metaStructTags)
|
|
171
|
+
this.#cachedEvents.delete(span)
|
|
172
|
+
} else {
|
|
173
|
+
this.#cachedEvents.delete(span)
|
|
174
|
+
this.#appendToWriter(span, event, routing)
|
|
175
|
+
}
|
|
176
|
+
} catch {
|
|
177
|
+
this.#cachedEvents.delete(span)
|
|
178
|
+
try {
|
|
179
|
+
this.#appendToWriter(span, cached.event, cached.routing)
|
|
180
|
+
} catch (appendError) {
|
|
181
|
+
this.#logAppendError(appendError)
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Routes events still awaiting an APM decision through the traditional LLMObs writer. */
|
|
188
|
+
processPending () {
|
|
189
|
+
for (const [span, cached] of this.#cachedEvents) {
|
|
190
|
+
this.#cachedEvents.delete(span)
|
|
191
|
+
|
|
192
|
+
try {
|
|
193
|
+
this.#appendToWriter(span, cached.event, cached.routing)
|
|
194
|
+
} catch (error) {
|
|
195
|
+
this.#logAppendError(error)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
destroy () {
|
|
201
|
+
if (!this.#destroyer) return
|
|
202
|
+
|
|
203
|
+
globalThis[Symbol.for('dd-trace')].beforeExitHandlers.delete(this.#destroyer)
|
|
204
|
+
this.processPending()
|
|
205
|
+
this.#destroyer = undefined
|
|
206
|
+
}
|
|
207
|
+
|
|
142
208
|
format (span) {
|
|
143
209
|
let inputType, outputType
|
|
144
210
|
|
|
@@ -202,6 +268,11 @@ class LLMObsSpanProcessor {
|
|
|
202
268
|
const isExperiment = spanKind === 'experiment'
|
|
203
269
|
const hasExperimentInput = isExperiment && Object.hasOwn(mlObsTags, EXPERIMENT_INPUT)
|
|
204
270
|
const hasExperimentOutput = isExperiment && Object.hasOwn(mlObsTags, EXPERIMENT_OUTPUT)
|
|
271
|
+
const hasExperimentExpectedOutput = isExperiment && Object.hasOwn(mlObsTags, EXPERIMENT_EXPECTED_OUTPUT)
|
|
272
|
+
|
|
273
|
+
if (hasExperimentExpectedOutput) {
|
|
274
|
+
llmObsSpan.expectedOutput = mlObsTags[EXPERIMENT_EXPECTED_OUTPUT]
|
|
275
|
+
}
|
|
205
276
|
|
|
206
277
|
if (hasExperimentInput) {
|
|
207
278
|
llmObsSpan.input = [{ role: '', content: mlObsTags[EXPERIMENT_INPUT] }]
|
|
@@ -253,6 +324,9 @@ class LLMObsSpanProcessor {
|
|
|
253
324
|
const [processedOutput] = processedSpan.output
|
|
254
325
|
if (hasExperimentInput && processedInput !== undefined) meta.input = processedInput.content
|
|
255
326
|
if (hasExperimentOutput && processedOutput !== undefined) meta.output = processedOutput.content
|
|
327
|
+
if (Object.hasOwn(processedSpan, 'expectedOutput') && processedSpan.expectedOutput !== undefined) {
|
|
328
|
+
meta.expected_output = processedSpan.expectedOutput
|
|
329
|
+
}
|
|
256
330
|
} else {
|
|
257
331
|
if (processedSpan.input) {
|
|
258
332
|
if (inputType === 'messages') {
|
|
@@ -320,6 +394,124 @@ class LLMObsSpanProcessor {
|
|
|
320
394
|
return llmObsSpanEvent
|
|
321
395
|
}
|
|
322
396
|
|
|
397
|
+
/**
|
|
398
|
+
* @param {import('../opentracing/span')} span
|
|
399
|
+
* @param {{ apiKey?: string, site?: string }} routing
|
|
400
|
+
* @param {object} event
|
|
401
|
+
* @param {boolean} willExport
|
|
402
|
+
*/
|
|
403
|
+
#shouldAttachMetaStruct (span, routing, event, willExport) {
|
|
404
|
+
const priority = span.context()._sampling?.priority
|
|
405
|
+
const predictedDrop = priority != null && priority <= AUTO_REJECT
|
|
406
|
+
|
|
407
|
+
return willExport &&
|
|
408
|
+
!predictedDrop &&
|
|
409
|
+
!routing.apiKey &&
|
|
410
|
+
!routing.site &&
|
|
411
|
+
!getEnvironmentVariable('_DD_LLMOBS_OVERRIDE_ORIGIN') &&
|
|
412
|
+
// TODO(sabrenner): remove below check once upstream ingestion allows array of "k:v" tags
|
|
413
|
+
!this.#hasCollidingTagKeys(event.tags)
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* @param {import('../opentracing/span')} span
|
|
418
|
+
* @param {object} event
|
|
419
|
+
* @param {{ apiKey?: string, site?: string }} routing
|
|
420
|
+
*/
|
|
421
|
+
#appendToWriter (span, event, routing) {
|
|
422
|
+
const enqueued = this.#writer.append(event, routing)
|
|
423
|
+
if (enqueued) span.context().setTag(LLMOBS_SUBMITTED_TAG_KEY, '1')
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** @param {Error} error */
|
|
427
|
+
#logAppendError (error) {
|
|
428
|
+
logger.warn(`
|
|
429
|
+
Failed to append span to LLM Observability writer, likely due to an unserializable property.
|
|
430
|
+
Span won't be sent to LLM Observability: ${error.message}
|
|
431
|
+
`)
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* The meta_struct tag map cannot losslessly represent repeated keys or keys
|
|
436
|
+
* that collide after agentless normalization.
|
|
437
|
+
* @param {string[]} tags
|
|
438
|
+
*/
|
|
439
|
+
#hasCollidingTagKeys (tags) {
|
|
440
|
+
const keys = new Set()
|
|
441
|
+
for (const tag of tags) {
|
|
442
|
+
const separatorIndex = tag.indexOf(':')
|
|
443
|
+
if (separatorIndex === -1) continue
|
|
444
|
+
|
|
445
|
+
const key = tag.slice(0, separatorIndex).replaceAll('.', '_')
|
|
446
|
+
if (keys.has(key)) return true
|
|
447
|
+
keys.add(key)
|
|
448
|
+
}
|
|
449
|
+
return false
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* @param {import('../opentracing/span')} span
|
|
454
|
+
* @param {object} event
|
|
455
|
+
* @param {{ mlApp?: string, sampleRate?: string, samplingDecision?: string }} metaStructTags
|
|
456
|
+
*/
|
|
457
|
+
#attachMetaStruct (span, event, metaStructTags) {
|
|
458
|
+
span.meta_struct ??= {}
|
|
459
|
+
span.meta_struct[LLMOBS_META_STRUCT_KEY] = this.#formatMetaStruct(event, metaStructTags)
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* @param {object} event
|
|
464
|
+
* @param {{ mlApp?: string, sampleRate?: string, samplingDecision?: string }} metaStructTags
|
|
465
|
+
*/
|
|
466
|
+
#formatMetaStruct (event, metaStructTags) {
|
|
467
|
+
const dd = {}
|
|
468
|
+
if (metaStructTags.sampleRate !== undefined) dd.sample_rate = metaStructTags.sampleRate
|
|
469
|
+
if (metaStructTags.samplingDecision !== undefined) dd.sampling_decision = metaStructTags.samplingDecision
|
|
470
|
+
if (event._dd?.scope !== undefined) dd.scope = event._dd.scope
|
|
471
|
+
|
|
472
|
+
const metaStruct = {
|
|
473
|
+
trace_id: event.trace_id,
|
|
474
|
+
tags: this.#stringArrayTagsToObjectTags(event.tags),
|
|
475
|
+
meta: this.#formatMetaStructMeta(event.meta),
|
|
476
|
+
metrics: event.metrics,
|
|
477
|
+
_dd: dd,
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (event.parent_id !== undefined) metaStruct.parent_id = event.parent_id
|
|
481
|
+
if (event.name !== undefined) metaStruct.name = event.name
|
|
482
|
+
if (metaStructTags.mlApp) metaStruct.ml_app = metaStructTags.mlApp
|
|
483
|
+
if (event.session_id) metaStruct.session_id = event.session_id
|
|
484
|
+
|
|
485
|
+
return metaStruct
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/** @param {object} eventMeta */
|
|
489
|
+
#formatMetaStructMeta (eventMeta) {
|
|
490
|
+
const meta = {}
|
|
491
|
+
|
|
492
|
+
for (const [key, value] of Object.entries(eventMeta)) {
|
|
493
|
+
if (key === 'span.kind') {
|
|
494
|
+
meta.span = { kind: value }
|
|
495
|
+
} else if (key === ERROR_MESSAGE) {
|
|
496
|
+
this.#getMetaStructError(meta).message = value
|
|
497
|
+
} else if (key === ERROR_TYPE) {
|
|
498
|
+
this.#getMetaStructError(meta).type = value
|
|
499
|
+
} else if (key === ERROR_STACK) {
|
|
500
|
+
this.#getMetaStructError(meta).stack = value
|
|
501
|
+
} else {
|
|
502
|
+
meta[key] = value
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
return meta
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** @param {object} meta */
|
|
510
|
+
#getMetaStructError (meta) {
|
|
511
|
+
if (!meta.error) meta.error = {}
|
|
512
|
+
return meta.error
|
|
513
|
+
}
|
|
514
|
+
|
|
323
515
|
/**
|
|
324
516
|
* @param {import('../opentracing/span')} span
|
|
325
517
|
*/
|
|
@@ -441,6 +633,21 @@ class LLMObsSpanProcessor {
|
|
|
441
633
|
return out
|
|
442
634
|
}
|
|
443
635
|
|
|
636
|
+
/**
|
|
637
|
+
* @param {string[]} tags
|
|
638
|
+
* @returns {Record<string, string>}
|
|
639
|
+
*/
|
|
640
|
+
#stringArrayTagsToObjectTags (tags) {
|
|
641
|
+
const out = {}
|
|
642
|
+
for (const tag of tags) {
|
|
643
|
+
const separatorIndex = tag.indexOf(':')
|
|
644
|
+
if (separatorIndex === -1) continue
|
|
645
|
+
|
|
646
|
+
out[tag.slice(0, separatorIndex)] = tag.slice(separatorIndex + 1)
|
|
647
|
+
}
|
|
648
|
+
return out
|
|
649
|
+
}
|
|
650
|
+
|
|
444
651
|
/**
|
|
445
652
|
* Runs the user span processor, emitting telemetry and adding some guardrails against invalid return types
|
|
446
653
|
* @param {LLMObservabilitySpan} span
|
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
const log = require('../log')
|
|
4
4
|
const Sampler = require('../sampler')
|
|
5
5
|
const { formatKnuthRate } = require('../util')
|
|
6
|
+
const { SPAN_TYPE } = require('../../../../ext/tags')
|
|
6
7
|
const {
|
|
7
8
|
MODEL_NAME,
|
|
8
9
|
MODEL_PROVIDER,
|
|
9
10
|
SESSION_ID,
|
|
11
|
+
EXPERIMENT_TAGS,
|
|
10
12
|
SESSION_ID_TRACE_DEFAULT_KEY,
|
|
11
13
|
ML_APP,
|
|
12
14
|
SPAN_KIND,
|
|
15
|
+
EXPERIMENT_EXPECTED_OUTPUT,
|
|
13
16
|
EXPERIMENT_INPUT,
|
|
14
17
|
EXPERIMENT_OUTPUT,
|
|
15
18
|
INPUT_VALUE,
|
|
@@ -120,6 +123,7 @@ class LLMObsTagger {
|
|
|
120
123
|
integration,
|
|
121
124
|
agentVersion,
|
|
122
125
|
_decorator,
|
|
126
|
+
_experimentTags,
|
|
123
127
|
} = {}) {
|
|
124
128
|
// Do not register it in the map if it does not have an LLMObs span kind.
|
|
125
129
|
if (!this.#config.llmobs.DD_LLMOBS_ENABLED || !kind) return
|
|
@@ -187,6 +191,15 @@ class LLMObsTagger {
|
|
|
187
191
|
const tags = annotationContext?.tags
|
|
188
192
|
if (tags) this.tagSpanTags(span, tags)
|
|
189
193
|
|
|
194
|
+
// Experiment context flows down the span tree, matching Python, which carries it on the span context.
|
|
195
|
+
// It stays out of annotationContext and is applied after its tags, so a user's nested
|
|
196
|
+
// annotationContext({ tags }) can neither replace it nor reassign the span to another run.
|
|
197
|
+
const experimentTags = _experimentTags ?? registry.get(parent)?.[EXPERIMENT_TAGS]
|
|
198
|
+
if (experimentTags) {
|
|
199
|
+
this._setTag(span, EXPERIMENT_TAGS, experimentTags)
|
|
200
|
+
this.tagSpanTags(span, experimentTags)
|
|
201
|
+
}
|
|
202
|
+
|
|
190
203
|
// apply after tags so only keys present at span start are accepted.
|
|
191
204
|
if (annotationContext?.costTags != null) {
|
|
192
205
|
this.tagCostTags(span, annotationContext.costTags, 'annotation_context')
|
|
@@ -341,6 +354,16 @@ class LLMObsTagger {
|
|
|
341
354
|
this.#tagExperimentValue(span, outputData, EXPERIMENT_OUTPUT, 'output')
|
|
342
355
|
}
|
|
343
356
|
|
|
357
|
+
/**
|
|
358
|
+
* Stores the expected output for an experiment span.
|
|
359
|
+
*
|
|
360
|
+
* @param {import('../opentracing/span')} span
|
|
361
|
+
* @param {unknown} expectedOutput
|
|
362
|
+
*/
|
|
363
|
+
tagExperimentExpectedOutput (span, expectedOutput) {
|
|
364
|
+
this.#tagExperimentValue(span, expectedOutput, EXPERIMENT_EXPECTED_OUTPUT, 'expected output')
|
|
365
|
+
}
|
|
366
|
+
|
|
344
367
|
tagTextIO (span, inputData, outputData) {
|
|
345
368
|
this.#tagText(span, inputData, INPUT_VALUE)
|
|
346
369
|
this.#tagText(span, outputData, OUTPUT_VALUE)
|
|
@@ -1021,6 +1044,8 @@ class LLMObsTagger {
|
|
|
1021
1044
|
return
|
|
1022
1045
|
}
|
|
1023
1046
|
|
|
1047
|
+
span.setTag(SPAN_TYPE, 'llm')
|
|
1048
|
+
|
|
1024
1049
|
registry.set(span, {})
|
|
1025
1050
|
}
|
|
1026
1051
|
|
|
@@ -7,7 +7,7 @@ const { fetchAgentInfo } = require('../../agent/info')
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @param {import('../../config/config-base')} config
|
|
10
|
-
* @param {(agentless: boolean) => void} setWritersAgentlessValue
|
|
10
|
+
* @param {(agentless: boolean, agentAvailable?: boolean) => void} setWritersAgentlessValue
|
|
11
11
|
*/
|
|
12
12
|
function setAgentStrategy (config, setWritersAgentlessValue) {
|
|
13
13
|
const agentlessEnabled = config.llmobs.DD_LLMOBS_AGENTLESS_ENABLED
|
|
@@ -19,7 +19,7 @@ function setAgentStrategy (config, setWritersAgentlessValue) {
|
|
|
19
19
|
|
|
20
20
|
fetchAgentInfo(config.url, (err, agentInfo) => {
|
|
21
21
|
if (err) {
|
|
22
|
-
setWritersAgentlessValue(true)
|
|
22
|
+
setWritersAgentlessValue(true, false)
|
|
23
23
|
return
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -28,7 +28,7 @@ function setAgentStrategy (config, setWritersAgentlessValue) {
|
|
|
28
28
|
const hasEndpoint = Array.isArray(endpoints) &&
|
|
29
29
|
endpoints.some(endpoint => typeof endpoint === 'string' && endpoint.startsWith(EVP_PROXY_AGENT_BASE_PATH))
|
|
30
30
|
setWritersAgentlessValue(!hasEndpoint)
|
|
31
|
-
})
|
|
31
|
+
}, { keepProcessAlive: true })
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
function parseResponseAndLog (err, code, eventsLength, url, eventType) {
|
|
@@ -25,6 +25,10 @@ class LogChannel {
|
|
|
25
25
|
this._level = getChannelLogLevel(level)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
getLevel () {
|
|
29
|
+
return Object.keys(Level).find(name => Level[name] === this._level) ?? 'none'
|
|
30
|
+
}
|
|
31
|
+
|
|
28
32
|
subscribe (logger) {
|
|
29
33
|
if (Level.trace >= this._level) {
|
|
30
34
|
traceChannel.subscribe(logger.trace)
|
|
@@ -17,7 +17,13 @@ let logger = defaultLogger
|
|
|
17
17
|
let logChannel = new LogChannel()
|
|
18
18
|
|
|
19
19
|
function withNoop (fn) {
|
|
20
|
-
legacyStorage.run({ noop: true },
|
|
20
|
+
legacyStorage.run({ noop: true }, () => {
|
|
21
|
+
// The diagnostics channel rethrows a subscriber error as an uncaught exception, so a
|
|
22
|
+
// throwing configured logger would otherwise terminate the application.
|
|
23
|
+
try {
|
|
24
|
+
fn()
|
|
25
|
+
} catch {}
|
|
26
|
+
})
|
|
21
27
|
}
|
|
22
28
|
|
|
23
29
|
function toggleSubscription (enable, level) {
|
|
@@ -59,4 +65,9 @@ function trace (log) {
|
|
|
59
65
|
withNoop(() => logger.debug(log))
|
|
60
66
|
}
|
|
61
67
|
|
|
62
|
-
|
|
68
|
+
function getLogLevel () {
|
|
69
|
+
if (!enabled) return 'none'
|
|
70
|
+
return logChannel.getLevel()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = { configure, error, warn, info, debug, trace, getLogLevel }
|