dd-trace 6.15.0 → 6.17.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 +15 -0
- package/ci/diagnose.js +0 -23
- package/ci/test-optimization-validation/approval-artifacts.js +0 -3
- package/ci/test-optimization-validation/approval.js +0 -6
- package/ci/test-optimization-validation/artifact-id.js +0 -1
- package/ci/test-optimization-validation/bounded-json.js +0 -1
- package/ci/test-optimization-validation/cli.js +0 -12
- package/ci/test-optimization-validation/command-output-policy.js +0 -1
- package/ci/test-optimization-validation/command-runner.js +0 -3
- package/ci/test-optimization-validation/environment.js +0 -4
- package/ci/test-optimization-validation/executable-approval.js +0 -1
- package/ci/test-optimization-validation/executable.js +0 -5
- package/ci/test-optimization-validation/framework-adapters/cucumber.js +4 -8
- package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -3
- package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -6
- package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -4
- package/ci/test-optimization-validation/generated-test-contract.js +0 -5
- package/ci/test-optimization-validation/generated-verifier.js +0 -1
- package/ci/test-optimization-validation/literal-environment.js +0 -1
- package/ci/test-optimization-validation/manifest-scaffold.js +0 -17
- package/ci/test-optimization-validation/manifest-schema.js +0 -21
- package/ci/test-optimization-validation/offline-fixtures.js +0 -4
- package/ci/test-optimization-validation/package-check.js +4 -1
- package/ci/test-optimization-validation/plan-writer.js +0 -11
- package/ci/test-optimization-validation/preflight-runner.js +0 -1
- package/ci/test-optimization-validation/redaction.js +0 -4
- package/ci/test-optimization-validation/report-writer.js +0 -16
- package/ci/test-optimization-validation/runner-command.js +0 -3
- package/ci/test-optimization-validation/runner-contract.js +0 -4
- package/ci/test-optimization-validation/safe-files.js +0 -1
- package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -1
- package/ci/test-optimization-validation/scenarios/ci-wiring.js +1 -2
- package/ci/test-optimization-validation/source-text.js +0 -3
- package/ci/vitest-no-worker-init-setup.mjs +41 -16
- package/index.d.ts +169 -0
- package/next.d.ts +27 -0
- package/next.js +3 -0
- package/package.json +28 -23
- package/packages/datadog-esbuild/index.js +14 -1
- package/packages/datadog-esbuild/src/resolver.js +284 -0
- package/packages/datadog-esbuild/src/utils.js +162 -120
- package/packages/datadog-instrumentations/src/aerospike.js +28 -6
- package/packages/datadog-instrumentations/src/ai.js +39 -97
- package/packages/datadog-instrumentations/src/anthropic.js +76 -134
- package/packages/datadog-instrumentations/src/aws-durable-execution-sdk-js.js +1 -3
- package/packages/datadog-instrumentations/src/aws-sdk.js +0 -2
- package/packages/datadog-instrumentations/src/azure-cosmos.js +1 -1
- package/packages/datadog-instrumentations/src/azure-durable-functions.js +23 -9
- package/packages/datadog-instrumentations/src/azure-functions.js +48 -0
- package/packages/datadog-instrumentations/src/bullmq.js +1 -1
- package/packages/datadog-instrumentations/src/claude-agent-sdk.js +1 -3
- package/packages/datadog-instrumentations/src/console.js +97 -0
- package/packages/datadog-instrumentations/src/cucumber.js +72 -12
- package/packages/datadog-instrumentations/src/cypress-config.js +0 -23
- package/packages/datadog-instrumentations/src/dd-trace-api.js +2 -2
- package/packages/datadog-instrumentations/src/graphql.js +1 -1
- package/packages/datadog-instrumentations/src/helpers/bundler-register.js +39 -14
- package/packages/datadog-instrumentations/src/helpers/channel.js +0 -2
- package/packages/datadog-instrumentations/src/helpers/graphql-jit-runtime.js +0 -5
- package/packages/datadog-instrumentations/src/helpers/hooks.js +8 -0
- package/packages/datadog-instrumentations/src/helpers/instrument.js +25 -8
- package/packages/datadog-instrumentations/src/helpers/instrumentation-utils.js +69 -0
- package/packages/datadog-instrumentations/src/helpers/pool-acquire.js +0 -6
- package/packages/datadog-instrumentations/src/helpers/register.js +13 -64
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +109 -29
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +39 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/azure-durable-functions.js +17 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +3 -16
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/playwright.js +12 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/postgres.js +36 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/supabase.js +128 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/webdriverio.js +6 -7
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +17 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms/postgres.js +388 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +99 -75
- package/packages/datadog-instrumentations/src/helpers/router-helper.js +0 -1
- package/packages/datadog-instrumentations/src/jest.js +141 -51
- package/packages/datadog-instrumentations/src/knex.js +0 -1
- package/packages/datadog-instrumentations/src/langchain.js +1 -1
- package/packages/datadog-instrumentations/src/langgraph.js +1 -1
- package/packages/datadog-instrumentations/src/mariadb-bundle.js +0 -24
- package/packages/datadog-instrumentations/src/mariadb.js +0 -2
- package/packages/datadog-instrumentations/src/mercurius.js +1 -1
- package/packages/datadog-instrumentations/src/mocha/common.js +0 -1
- package/packages/datadog-instrumentations/src/mocha/main.js +22 -25
- package/packages/datadog-instrumentations/src/mocha/utils.js +119 -49
- package/packages/datadog-instrumentations/src/mocha/webdriverio-protocol.js +0 -6
- package/packages/datadog-instrumentations/src/mocha/worker.js +14 -17
- package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +1 -1
- package/packages/datadog-instrumentations/src/mysql2.js +0 -2
- package/packages/datadog-instrumentations/src/openai-agents.js +1 -1
- package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +241 -0
- package/packages/datadog-instrumentations/src/openai-realtime/events.js +76 -0
- package/packages/datadog-instrumentations/src/openai-realtime/index.js +301 -0
- package/packages/datadog-instrumentations/src/openai-realtime/session.js +998 -0
- package/packages/datadog-instrumentations/src/openai-realtime/turns.js +211 -0
- package/packages/datadog-instrumentations/src/openai.js +97 -80
- package/packages/datadog-instrumentations/src/oracledb.js +9 -3
- package/packages/datadog-instrumentations/src/playwright-reporter.js +3 -16
- package/packages/datadog-instrumentations/src/playwright.js +238 -55
- package/packages/datadog-instrumentations/src/postgres.js +7 -0
- package/packages/datadog-instrumentations/src/router.js +0 -2
- package/packages/datadog-instrumentations/src/rum-browser-scripts.js +0 -2
- package/packages/datadog-instrumentations/src/sequelize.js +0 -1
- package/packages/datadog-instrumentations/src/supabase.js +15 -0
- package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +18 -18
- package/packages/datadog-instrumentations/src/vitest-main.js +37 -17
- package/packages/datadog-instrumentations/src/vitest-util.js +7 -1
- package/packages/datadog-instrumentations/src/vitest-worker.js +56 -23
- package/packages/datadog-instrumentations/src/webdriverio.js +23 -42
- package/packages/datadog-instrumentations/src/ws.js +0 -1
- package/packages/datadog-plugin-ai/src/utils.js +0 -2
- package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/trace-checkpoint.js +0 -1
- package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/util.js +0 -2
- package/packages/datadog-plugin-aws-sdk/src/base.js +0 -1
- package/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js +7 -2
- package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +0 -1
- package/packages/datadog-plugin-aws-sdk/src/util.js +0 -1
- package/packages/datadog-plugin-azure-cosmos/src/index.js +1 -1
- package/packages/datadog-plugin-azure-durable-functions/src/index.js +95 -1
- package/packages/datadog-plugin-cucumber/src/index.js +10 -0
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +171 -75
- package/packages/datadog-plugin-cypress/src/finalization.js +0 -3
- package/packages/datadog-plugin-cypress/src/source-map-utils.js +0 -4
- package/packages/datadog-plugin-cypress/src/support.js +52 -7
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +2 -24
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +2 -36
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +31 -0
- package/packages/datadog-plugin-graphql/src/resolve-error.js +32 -11
- package/packages/datadog-plugin-graphql/src/utils.js +0 -5
- package/packages/datadog-plugin-jest/src/index.js +13 -0
- package/packages/datadog-plugin-kafkajs/src/producer.js +0 -1
- package/packages/datadog-plugin-mocha/src/index.js +39 -11
- package/packages/datadog-plugin-mongodb-core/src/query.js +0 -1
- package/packages/datadog-plugin-openai/src/index.js +16 -1
- package/packages/datadog-plugin-openai/src/realtime.js +144 -0
- package/packages/datadog-plugin-openai-agents/src/integration.js +0 -4
- package/packages/datadog-plugin-openai-agents/src/util.js +0 -1
- package/packages/datadog-plugin-playwright/src/index.js +76 -9
- package/packages/datadog-plugin-postgres/src/index.js +167 -0
- package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +0 -1
- package/packages/datadog-plugin-redis/src/index.js +15 -1
- package/packages/datadog-plugin-supabase/src/error.js +18 -0
- package/packages/datadog-plugin-supabase/src/index.js +21 -0
- package/packages/datadog-plugin-supabase/src/supabase-auth-js-gotrueclient-getuser.js +69 -0
- package/packages/datadog-plugin-supabase/src/supabase-functions-js-functionsclient-invoke.js +70 -0
- package/packages/datadog-plugin-supabase/src/supabase-postgrest-js-postgrestbuilder-then.js +122 -0
- package/packages/datadog-plugin-supabase/src/supabase-realtime-js-realtimechannel-send.js +66 -0
- package/packages/datadog-plugin-supabase/src/supabase-storage-js-handle-request.js +93 -0
- package/packages/datadog-plugin-supabase/src/url.js +17 -0
- package/packages/datadog-plugin-vitest/src/index.js +10 -0
- package/packages/datadog-plugin-ws/src/util.js +0 -4
- package/packages/datadog-turbopack/index.js +206 -0
- package/packages/datadog-turbopack/src/constants.js +5 -0
- package/packages/datadog-turbopack/src/loader.js +484 -0
- package/packages/datadog-webpack/src/loader.js +0 -1
- package/packages/dd-trace/src/aiguard/client.js +2 -3
- package/packages/dd-trace/src/aiguard/evaluation.js +6 -12
- package/packages/dd-trace/src/aiguard/index.js +3 -2
- package/packages/dd-trace/src/aiguard/integrations/anthropic.js +53 -25
- package/packages/dd-trace/src/aiguard/integrations/evaluate.js +49 -25
- package/packages/dd-trace/src/aiguard/integrations/index.js +4 -3
- package/packages/dd-trace/src/aiguard/integrations/openai.js +132 -29
- package/packages/dd-trace/src/aiguard/integrations/vercel-ai.js +116 -42
- package/packages/dd-trace/src/aiguard/messages/anthropic.js +0 -2
- package/packages/dd-trace/src/aiguard/messages/openai.js +64 -1
- package/packages/dd-trace/src/aiguard/messages/utils.js +29 -2
- package/packages/dd-trace/src/aiguard/messages/vercel-ai.js +25 -0
- package/packages/dd-trace/src/aiguard/redaction.js +0 -1
- package/packages/dd-trace/src/aiguard/sdk.js +1 -1
- package/packages/dd-trace/src/appsec/activation.js +1 -1
- package/packages/dd-trace/src/appsec/api_security/normalized-route.js +0 -5
- package/packages/dd-trace/src/appsec/api_security/sampler.js +0 -4
- package/packages/dd-trace/src/appsec/blocking/index.js +3 -3
- package/packages/dd-trace/src/appsec/downstream_requests.js +1 -4
- package/packages/dd-trace/src/appsec/iast/index.js +1 -1
- package/packages/dd-trace/src/appsec/iast/overhead-controller.js +5 -5
- package/packages/dd-trace/src/appsec/iast/taint-tracking/index.js +1 -1
- package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +1 -1
- package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +3 -3
- package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/sql-sensitive-analyzer.js +8 -10
- package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-analyzers/url-sensitive-analyzer.js +2 -2
- package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/evidence-redaction/sensitive-handler.js +2 -2
- package/packages/dd-trace/src/appsec/iast/vulnerabilities-formatter/utils.js +4 -1
- package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +7 -7
- package/packages/dd-trace/src/appsec/index.js +2 -2
- package/packages/dd-trace/src/appsec/lambda.js +71 -2
- package/packages/dd-trace/src/appsec/rasp/utils.js +5 -1
- package/packages/dd-trace/src/appsec/remote_config.js +8 -6
- package/packages/dd-trace/src/appsec/reporter.js +10 -6
- package/packages/dd-trace/src/appsec/rule_manager.js +3 -3
- package/packages/dd-trace/src/appsec/sdk/track_event.js +0 -2
- package/packages/dd-trace/src/appsec/telemetry/api_security.js +1 -3
- package/packages/dd-trace/src/appsec/telemetry/common.js +4 -0
- package/packages/dd-trace/src/appsec/telemetry/index.js +23 -5
- package/packages/dd-trace/src/appsec/telemetry/rasp.js +1 -20
- package/packages/dd-trace/src/appsec/telemetry/user.js +1 -3
- package/packages/dd-trace/src/appsec/telemetry/waf.js +1 -20
- package/packages/dd-trace/src/appsec/waf/index.js +2 -2
- package/packages/dd-trace/src/appsec/waf/waf_manager.js +8 -5
- package/packages/dd-trace/src/carrier.js +0 -5
- package/packages/dd-trace/src/ci-visibility/dynamic-atr-retries.js +104 -0
- package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +0 -2
- package/packages/dd-trace/src/ci-visibility/efd-retry-policy.js +34 -3
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js +0 -1
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/di-logs-writer.js +0 -1
- package/packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js +0 -1
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -4
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -1
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -2
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +37 -15
- package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +0 -3
- package/packages/dd-trace/src/ci-visibility/exporters/request.js +0 -11
- package/packages/dd-trace/src/ci-visibility/exporters/settings-cache-key.js +0 -1
- package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +0 -1
- package/packages/dd-trace/src/ci-visibility/requests/fs-cache.js +0 -6
- package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +2 -2
- package/packages/dd-trace/src/ci-visibility/requests/rate-limit.js +0 -1
- package/packages/dd-trace/src/ci-visibility/requests/upload-test-screenshot.js +0 -5
- package/packages/dd-trace/src/ci-visibility/requests/video-request.js +0 -1
- package/packages/dd-trace/src/ci-visibility/telemetry.js +13 -0
- package/packages/dd-trace/src/ci-visibility/test-optimization-cache.js +0 -1
- package/packages/dd-trace/src/ci-visibility/test-screenshot.js +0 -2
- package/packages/dd-trace/src/ci-visibility/test-video.js +0 -1
- package/packages/dd-trace/src/config/defaults.js +3 -2
- package/packages/dd-trace/src/config/generated-config-types.d.ts +74 -66
- package/packages/dd-trace/src/config/helper.js +9 -2
- package/packages/dd-trace/src/config/index.js +44 -29
- package/packages/dd-trace/src/config/parsers.js +34 -6
- package/packages/dd-trace/src/config/remote_config.js +25 -109
- package/packages/dd-trace/src/config/supported-configurations.json +146 -9
- package/packages/dd-trace/src/datastreams/encoding.js +0 -1
- package/packages/dd-trace/src/datastreams/pathway.js +0 -1
- package/packages/dd-trace/src/debugger/constants.js +10 -0
- package/packages/dd-trace/src/debugger/devtools_client/breakpoints.js +76 -17
- package/packages/dd-trace/src/debugger/devtools_client/config.js +2 -0
- package/packages/dd-trace/src/debugger/devtools_client/guardrail-metrics.js +15 -0
- package/packages/dd-trace/src/debugger/devtools_client/index.js +103 -27
- package/packages/dd-trace/src/debugger/devtools_client/json-buffer.js +50 -7
- package/packages/dd-trace/src/debugger/devtools_client/log.js +3 -1
- package/packages/dd-trace/src/debugger/devtools_client/probe_sampler.js +34 -8
- package/packages/dd-trace/src/debugger/devtools_client/send.js +40 -14
- package/packages/dd-trace/src/debugger/devtools_client/snapshot/index.js +53 -13
- package/packages/dd-trace/src/debugger/devtools_client/snapshot/processor.js +118 -71
- package/packages/dd-trace/src/debugger/devtools_client/snapshot-pruner.js +0 -3
- package/packages/dd-trace/src/debugger/devtools_client/status.js +20 -6
- package/packages/dd-trace/src/debugger/guardrail-metrics.js +167 -0
- package/packages/dd-trace/src/debugger/index.js +50 -2
- package/packages/dd-trace/src/debugger/inspect-segment.js +0 -3
- package/packages/dd-trace/src/debugger/probe_sampler.js +133 -9
- package/packages/dd-trace/src/debugger/probe_sampler_constants.js +31 -1
- package/packages/dd-trace/src/dogstatsd.js +0 -23
- package/packages/dd-trace/src/encode/0.4-cross-payload.js +0 -3
- package/packages/dd-trace/src/encode/0.4.js +0 -7
- package/packages/dd-trace/src/encode/0.5.js +0 -2
- package/packages/dd-trace/src/encode/tags-processors.js +0 -1
- package/packages/dd-trace/src/evp_proxy/discovery.js +3 -5
- package/packages/dd-trace/src/evp_proxy/path.js +11 -4
- package/packages/dd-trace/src/exporters/agent/writer.js +0 -1
- package/packages/dd-trace/src/exporters/agentless/index.js +0 -1
- package/packages/dd-trace/src/exporters/agentless/intake.js +0 -1
- package/packages/dd-trace/src/exporters/agentless/writer.js +0 -3
- package/packages/dd-trace/src/exporters/common/docker.js +4 -1
- package/packages/dd-trace/src/exporters/common/final-flush-request-tracker.js +0 -6
- package/packages/dd-trace/src/exporters/common/proxy.js +3 -0
- package/packages/dd-trace/src/exporters/common/request.js +1 -0
- package/packages/dd-trace/src/exporters/common/url.js +0 -2
- package/packages/dd-trace/src/exporters/common/writer.js +0 -2
- package/packages/dd-trace/src/id.js +0 -11
- package/packages/dd-trace/src/llmobs/audio-codec.js +192 -0
- package/packages/dd-trace/src/llmobs/audio-utils.js +121 -0
- package/packages/dd-trace/src/llmobs/constants/audio.js +35 -0
- package/packages/dd-trace/src/llmobs/constants/prompts.js +14 -0
- package/packages/dd-trace/src/llmobs/constants/tags.js +17 -0
- package/packages/dd-trace/src/llmobs/eval-metric.js +0 -6
- package/packages/dd-trace/src/llmobs/experiments/dataset.js +0 -4
- package/packages/dd-trace/src/llmobs/experiments/experiment.js +0 -3
- package/packages/dd-trace/src/llmobs/experiments/index.js +7 -6
- package/packages/dd-trace/src/llmobs/experiments/util.js +1 -11
- package/packages/dd-trace/src/llmobs/index.js +1 -3
- package/packages/dd-trace/src/llmobs/noop.js +10 -0
- package/packages/dd-trace/src/llmobs/plugins/ai/util.js +0 -4
- package/packages/dd-trace/src/llmobs/plugins/anthropic/util.js +0 -1
- package/packages/dd-trace/src/llmobs/plugins/genai/util.js +0 -4
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +0 -2
- package/packages/dd-trace/src/llmobs/plugins/openai/constants.js +0 -2
- package/packages/dd-trace/src/llmobs/plugins/openai/index.js +4 -6
- package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +285 -0
- package/packages/dd-trace/src/llmobs/plugins/openai/utils.js +16 -3
- package/packages/dd-trace/src/llmobs/prompts/cache.js +272 -0
- package/packages/dd-trace/src/llmobs/prompts/manager.js +639 -0
- package/packages/dd-trace/src/llmobs/prompts/noop.js +29 -0
- package/packages/dd-trace/src/llmobs/prompts/prompt.js +92 -0
- package/packages/dd-trace/src/llmobs/sdk.js +21 -6
- package/packages/dd-trace/src/llmobs/span_processor.js +81 -2
- package/packages/dd-trace/src/llmobs/tagger.js +30 -7
- package/packages/dd-trace/src/llmobs/telemetry.js +36 -4
- package/packages/dd-trace/src/llmobs/util.js +0 -34
- package/packages/dd-trace/src/llmobs/writers/base.js +0 -1
- package/packages/dd-trace/src/llmobs/writers/util.js +1 -2
- package/packages/dd-trace/src/log/channels.js +3 -0
- package/packages/dd-trace/src/log/index.js +23 -5
- package/packages/dd-trace/src/log-submission/log-submission-plugin.js +74 -6
- package/packages/dd-trace/src/msgpack/chunk.js +0 -1
- package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +0 -12
- package/packages/dd-trace/src/openfeature/encoding.js +0 -2
- package/packages/dd-trace/src/openfeature/eval-metrics-hook.js +0 -1
- package/packages/dd-trace/src/openfeature/index.js +0 -4
- package/packages/dd-trace/src/openfeature/span-enrichment-hook.js +0 -1
- package/packages/dd-trace/src/openfeature/span-enrichment.js +0 -4
- package/packages/dd-trace/src/openfeature/writers/base.js +0 -6
- package/packages/dd-trace/src/openfeature/writers/exposures.js +0 -5
- package/packages/dd-trace/src/openfeature/writers/util.js +0 -4
- package/packages/dd-trace/src/opentelemetry/logs/logger.js +0 -1
- package/packages/dd-trace/src/opentelemetry/logs/logger_provider.js +0 -1
- package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +0 -1
- package/packages/dd-trace/src/opentelemetry/logs/otlp_transformer.js +0 -2
- package/packages/dd-trace/src/opentelemetry/metrics/index.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/meter_provider.js +4 -4
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_transformer.js +0 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_transformer.js +0 -1
- package/packages/dd-trace/src/opentelemetry/metrics/periodic_metric_reader.js +103 -35
- package/packages/dd-trace/src/opentelemetry/metrics/time.js +0 -1
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +36 -13
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +0 -1
- package/packages/dd-trace/src/opentelemetry/span-helpers.js +0 -1
- package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +0 -1
- package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +0 -3
- package/packages/dd-trace/src/opentracing/propagation/text_map.js +0 -6
- package/packages/dd-trace/src/opentracing/span_context.js +0 -1
- package/packages/dd-trace/src/otel-thread-ctx.js +38 -11
- package/packages/dd-trace/src/payload-tagging/tagging.js +15 -3
- package/packages/dd-trace/src/plugin_manager.js +9 -3
- package/packages/dd-trace/src/plugins/ci_plugin.js +0 -1
- package/packages/dd-trace/src/plugins/database.js +2 -6
- package/packages/dd-trace/src/plugins/index.js +8 -0
- package/packages/dd-trace/src/plugins/plugin.js +0 -4
- package/packages/dd-trace/src/plugins/tracing.js +1 -1
- package/packages/dd-trace/src/plugins/util/git.js +1 -3
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +0 -1
- package/packages/dd-trace/src/plugins/util/llm.js +0 -2
- package/packages/dd-trace/src/plugins/util/status-validator.js +0 -1
- package/packages/dd-trace/src/plugins/util/test.js +25 -21
- package/packages/dd-trace/src/plugins/util/url.js +0 -5
- package/packages/dd-trace/src/priority_sampler.js +0 -6
- package/packages/dd-trace/src/process-tags/index.js +0 -1
- package/packages/dd-trace/src/profiler.js +132 -35
- package/packages/dd-trace/src/profiling/exporters/event_serializer.js +0 -1
- package/packages/dd-trace/src/profiling/profiler.js +101 -41
- package/packages/dd-trace/src/profiling/ssi-heuristics.js +29 -15
- package/packages/dd-trace/src/propagation-hash/index.js +0 -1
- package/packages/dd-trace/src/proxy.js +21 -45
- package/packages/dd-trace/src/random_sampler.js +0 -4
- package/packages/dd-trace/src/rate_limiter.js +0 -4
- package/packages/dd-trace/src/remote_config/capabilities.js +1 -9
- package/packages/dd-trace/src/remote_config/index.js +0 -1
- package/packages/dd-trace/src/runtime_metrics/otlp_runtime_metrics.js +0 -3
- package/packages/dd-trace/src/sampler.js +0 -4
- package/packages/dd-trace/src/sampling_rule.js +0 -7
- package/packages/dd-trace/src/serverless/vercel.js +0 -1
- package/packages/dd-trace/src/serverless.js +0 -1
- package/packages/dd-trace/src/service-naming/index.js +0 -1
- package/packages/dd-trace/src/service-naming/schemas/util.js +0 -1
- package/packages/dd-trace/src/service-naming/schemas/v0/storage.js +7 -0
- package/packages/dd-trace/src/service-naming/schemas/v1/storage.js +5 -0
- package/packages/dd-trace/src/span_processor.js +2 -2
- package/packages/dd-trace/src/span_sampler.js +0 -1
- package/packages/dd-trace/src/standalone/product.js +2 -2
- package/packages/dd-trace/src/standalone/tracesource.js +0 -1
- package/packages/dd-trace/src/startup-log.js +1 -1
- package/packages/dd-trace/src/telemetry/endpoints.js +0 -8
- package/packages/dd-trace/src/telemetry/logs/index.js +16 -5
- package/packages/dd-trace/src/telemetry/logs/log-collector.js +16 -6
- package/packages/dd-trace/src/telemetry/metrics.js +0 -2
- package/packages/dd-trace/src/telemetry/telemetry.js +4 -1
- package/packages/dd-trace/src/util.js +13 -1
- package/vendor/dist/@datadog/openfeature-node-server/index.js +1 -1
- package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/utils.js +0 -10
|
@@ -6,90 +6,30 @@ const { addHook } = require('./helpers/instrument')
|
|
|
6
6
|
|
|
7
7
|
const anthropicTracingChannel = tracingChannel('apm:anthropic:request')
|
|
8
8
|
const onStreamedChunkCh = channel('apm:anthropic:request:chunk')
|
|
9
|
-
const messagesBeforeChannel = channel('dd-trace:anthropic:messages:before')
|
|
10
|
-
const messagesAfterChannel = channel('dd-trace:anthropic:messages:after')
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* @param {object} payload
|
|
20
|
-
* @returns {Promise<void>}
|
|
21
|
-
*/
|
|
22
|
-
function publishLifecycle (channel, payload) {
|
|
23
|
-
const abortController = new AbortController()
|
|
24
|
-
const ctx = { ...payload, abortController, pending: [] }
|
|
25
|
-
|
|
26
|
-
channel.publish(ctx)
|
|
27
|
-
|
|
28
|
-
return Promise.all(ctx.pending).then(() => {
|
|
29
|
-
if (abortController.signal.aborted) {
|
|
30
|
-
throw abortController.signal.reason
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
}
|
|
10
|
+
// `prepare` is published before the SDK is invoked, so subscribers may replace `arguments[0]`.
|
|
11
|
+
// `intercept` follows with the native call data; a subscriber may set either callback and this
|
|
12
|
+
// instrumentation applies it, so the wrapping stays here and only the policy lives outside:
|
|
13
|
+
// beforeResult () => Promise<void>|undefined holds the result back until it settles
|
|
14
|
+
// onResult (body) => unknown|Promise<unknown> inspects or replaces the delivered body
|
|
15
|
+
const messagesPrepareChannel = channel('dd-trace:anthropic:messages:prepare')
|
|
16
|
+
const messagesInterceptChannel = channel('dd-trace:anthropic:messages:intercept')
|
|
34
17
|
|
|
35
18
|
/**
|
|
19
|
+
* Returns `promise`, but not before `settled` settles, so a rejection from an interceptor
|
|
20
|
+
* reaches the caller instead of the SDK's value.
|
|
21
|
+
*
|
|
36
22
|
* @template T
|
|
37
23
|
* @param {Promise<T>} promise
|
|
38
|
-
* @param {Promise<void>|undefined}
|
|
24
|
+
* @param {Promise<void>|undefined} settled
|
|
39
25
|
* @returns {Promise<T>}
|
|
40
26
|
*/
|
|
41
|
-
function
|
|
42
|
-
if (!
|
|
27
|
+
function heldUntil (promise, settled) {
|
|
28
|
+
if (!settled) return promise
|
|
43
29
|
|
|
44
|
-
// The
|
|
30
|
+
// The interceptor's rejection wins over an earlier SDK rejection, so keep that one handled.
|
|
45
31
|
promise.catch(() => {})
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @param {Array<unknown>} args
|
|
51
|
-
* @returns {Array<unknown>|undefined}
|
|
52
|
-
*/
|
|
53
|
-
function snapshotLifecycleArgs (args) {
|
|
54
|
-
const options = args[0]
|
|
55
|
-
if (!options || typeof options !== 'object') return
|
|
56
|
-
|
|
57
|
-
const input = { messages: options.messages }
|
|
58
|
-
if (options.system !== undefined) input.system = options.system
|
|
59
|
-
|
|
60
|
-
// Snapshot via JSON so AI Guard evaluates exactly what the SDK serializes and sends, immune to
|
|
61
|
-
// later caller mutation. If it can't serialize (e.g. circular), the SDK's own serialization would
|
|
62
|
-
// fail too, so skipping evaluation is safe — nothing reaches the model.
|
|
63
|
-
try {
|
|
64
|
-
const snapshot = [...args]
|
|
65
|
-
// eslint-disable-next-line unicorn/prefer-structured-clone
|
|
66
|
-
snapshot[0] = { ...options, ...JSON.parse(JSON.stringify(input)) }
|
|
67
|
-
return snapshot
|
|
68
|
-
} catch {
|
|
69
|
-
// Unserializable input — leave AI Guard inactive for this call (the SDK send would fail too).
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Finishes after output evaluation so a block propagates to the caller and span.
|
|
75
|
-
*
|
|
76
|
-
* @param {object} ctx
|
|
77
|
-
* @param {object} result
|
|
78
|
-
* @param {(body: object) => Promise<void>|undefined} getVerdict
|
|
79
|
-
* @param {object|string} [returnedResult]
|
|
80
|
-
* @returns {object|string|Promise<object|string>}
|
|
81
|
-
*/
|
|
82
|
-
function finishResult (ctx, result, getVerdict, returnedResult = result) {
|
|
83
|
-
const verdict = getVerdict(result)
|
|
84
|
-
if (!verdict) {
|
|
85
|
-
finish(ctx, result)
|
|
86
|
-
return returnedResult
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return verdict.then(() => {
|
|
90
|
-
finish(ctx, result)
|
|
91
|
-
return returnedResult
|
|
92
|
-
})
|
|
32
|
+
return settled.then(() => promise)
|
|
93
33
|
}
|
|
94
34
|
|
|
95
35
|
/**
|
|
@@ -106,22 +46,36 @@ function finishAndThrow (ctx, error) {
|
|
|
106
46
|
* @param {object} response
|
|
107
47
|
* @param {'json'|'text'} method
|
|
108
48
|
* @param {object} ctx
|
|
109
|
-
* @param {
|
|
49
|
+
* @param {object} [interceptCtx]
|
|
110
50
|
*/
|
|
111
|
-
function wrapResponseReader (response, method, ctx,
|
|
51
|
+
function wrapResponseReader (response, method, ctx, interceptCtx) {
|
|
112
52
|
if (typeof response[method] !== 'function') return
|
|
113
53
|
|
|
114
54
|
shimmer.wrap(response, method, original => function (...args) {
|
|
115
55
|
return original.apply(this, args)
|
|
116
56
|
.then(body => {
|
|
117
|
-
|
|
57
|
+
// `text()` callers keep their string; only the callback and the span see the parsed body.
|
|
58
|
+
let parsed = body
|
|
59
|
+
if (method === 'text') {
|
|
60
|
+
try {
|
|
61
|
+
parsed = JSON.parse(body)
|
|
62
|
+
} catch {
|
|
63
|
+
finish(ctx)
|
|
64
|
+
return body
|
|
65
|
+
}
|
|
66
|
+
}
|
|
118
67
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
} catch {
|
|
122
|
-
finish(ctx)
|
|
68
|
+
if (!interceptCtx?.onResult) {
|
|
69
|
+
finish(ctx, parsed)
|
|
123
70
|
return body
|
|
124
71
|
}
|
|
72
|
+
|
|
73
|
+
return Promise.resolve(interceptCtx.onResult(parsed)).then(deliveredBody => {
|
|
74
|
+
finish(ctx, parsed)
|
|
75
|
+
// `json()` callers get any replacement; `text()` callers keep their original string,
|
|
76
|
+
// because the callback was handed the parsed object rather than the text.
|
|
77
|
+
return method === 'json' ? deliveredBody : body
|
|
78
|
+
})
|
|
125
79
|
})
|
|
126
80
|
.catch(error => finishAndThrow(ctx, error))
|
|
127
81
|
})
|
|
@@ -130,17 +84,17 @@ function wrapResponseReader (response, method, ctx, getVerdict) {
|
|
|
130
84
|
/**
|
|
131
85
|
* @param {object} response
|
|
132
86
|
* @param {object} ctx
|
|
133
|
-
* @param {
|
|
87
|
+
* @param {object} [interceptCtx]
|
|
134
88
|
*/
|
|
135
|
-
function wrapRawResponse (response, ctx,
|
|
136
|
-
wrapResponseReader(response, 'json', ctx,
|
|
137
|
-
wrapResponseReader(response, 'text', ctx,
|
|
89
|
+
function wrapRawResponse (response, ctx, interceptCtx) {
|
|
90
|
+
wrapResponseReader(response, 'json', ctx, interceptCtx)
|
|
91
|
+
wrapResponseReader(response, 'text', ctx, interceptCtx)
|
|
138
92
|
|
|
139
93
|
if (typeof response.clone !== 'function') return
|
|
140
94
|
|
|
141
95
|
shimmer.wrap(response, 'clone', clone => function (...args) {
|
|
142
96
|
const clonedResponse = clone.apply(this, args)
|
|
143
|
-
wrapRawResponse(clonedResponse, ctx,
|
|
97
|
+
wrapRawResponse(clonedResponse, ctx, interceptCtx)
|
|
144
98
|
return clonedResponse
|
|
145
99
|
})
|
|
146
100
|
}
|
|
@@ -172,68 +126,60 @@ function wrapStreamIterator (iterator, ctx) {
|
|
|
172
126
|
|
|
173
127
|
function wrapCreate (create) {
|
|
174
128
|
return function (...args) {
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
// Streaming is out of scope for lifecycle evaluation.
|
|
179
|
-
const lifecycleArgs = !stream &&
|
|
180
|
-
(messagesBeforeChannel.hasSubscribers || messagesAfterChannel.hasSubscribers)
|
|
181
|
-
? snapshotLifecycleArgs(args)
|
|
182
|
-
: undefined
|
|
129
|
+
const stream = args[0]?.stream
|
|
130
|
+
const preparing = !stream && messagesPrepareChannel.hasSubscribers
|
|
131
|
+
const intercepting = !stream && messagesInterceptChannel.hasSubscribers
|
|
183
132
|
|
|
184
|
-
if (!anthropicTracingChannel.start.hasSubscribers && !
|
|
133
|
+
if (!anthropicTracingChannel.start.hasSubscribers && !preparing && !intercepting) {
|
|
185
134
|
return create.apply(this, args)
|
|
186
135
|
}
|
|
187
136
|
|
|
188
|
-
|
|
137
|
+
// `args` is this wrapper's own rest array, so replacing `arguments[0]` changes what reaches
|
|
138
|
+
// the SDK without touching anything the caller still holds.
|
|
139
|
+
if (preparing) {
|
|
140
|
+
messagesPrepareChannel.publish({ arguments: args })
|
|
141
|
+
}
|
|
189
142
|
|
|
190
|
-
|
|
191
|
-
const parentSpan = lifecycleArgs ? ctx.currentStore?.span : undefined
|
|
143
|
+
const ctx = { options: args[0], resource: 'create', baseUrl: this._client?.baseURL }
|
|
192
144
|
|
|
145
|
+
return anthropicTracingChannel.start.runStores(ctx, () => {
|
|
193
146
|
let apiPromise
|
|
194
147
|
try {
|
|
195
|
-
// Anthropic starts the request eagerly
|
|
196
|
-
apiPromise = create.apply(this,
|
|
148
|
+
// Anthropic starts the request eagerly, so subscribers can only hold back delivery.
|
|
149
|
+
apiPromise = create.apply(this, args)
|
|
197
150
|
} catch (error) {
|
|
198
151
|
finish(ctx, null, error)
|
|
199
152
|
throw error
|
|
200
153
|
}
|
|
201
154
|
|
|
202
|
-
let
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
function getBeforeVerdict () {
|
|
208
|
-
if (!lifecycleArgs || beforeVerdict) return beforeVerdict
|
|
209
|
-
if (!messagesBeforeChannel.hasSubscribers) return
|
|
210
|
-
|
|
211
|
-
beforeVerdict = publishLifecycle(messagesBeforeChannel, { args: lifecycleArgs, parentSpan })
|
|
212
|
-
return beforeVerdict
|
|
155
|
+
let interceptCtx
|
|
156
|
+
if (intercepting) {
|
|
157
|
+
interceptCtx = { arguments: args, tracingContext: ctx }
|
|
158
|
+
messagesInterceptChannel.publish(interceptCtx)
|
|
213
159
|
}
|
|
214
160
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
*/
|
|
218
|
-
function getAfterVerdict (body) {
|
|
219
|
-
if (!lifecycleArgs || afterVerdict) return afterVerdict
|
|
220
|
-
if (!messagesAfterChannel.hasSubscribers) return
|
|
221
|
-
|
|
222
|
-
afterVerdict = publishLifecycle(messagesAfterChannel, { args: lifecycleArgs, body, parentSpan })
|
|
223
|
-
return afterVerdict
|
|
224
|
-
}
|
|
161
|
+
let parseResult
|
|
162
|
+
let wrappedResponse
|
|
225
163
|
|
|
226
164
|
shimmer.wrap(apiPromise, 'parse', parse => function (...parseArgs) {
|
|
227
165
|
if (parseResult) return parseResult
|
|
228
166
|
|
|
229
|
-
|
|
230
|
-
parseResult = waitForVerdict(parsed, getBeforeVerdict())
|
|
167
|
+
parseResult = heldUntil(parse.apply(this, parseArgs), interceptCtx?.beforeResult?.())
|
|
231
168
|
.then(response => {
|
|
232
169
|
if (stream) {
|
|
233
170
|
shimmer.wrap(response, Symbol.asyncIterator, iterator => wrapStreamIterator(iterator, ctx))
|
|
234
171
|
return response
|
|
235
172
|
}
|
|
236
|
-
|
|
173
|
+
|
|
174
|
+
if (!interceptCtx?.onResult) {
|
|
175
|
+
finish(ctx, response)
|
|
176
|
+
return response
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return Promise.resolve(interceptCtx.onResult(response)).then(deliveredResponse => {
|
|
180
|
+
finish(ctx, response)
|
|
181
|
+
return deliveredResponse
|
|
182
|
+
})
|
|
237
183
|
})
|
|
238
184
|
.catch(error => finishAndThrow(ctx, error))
|
|
239
185
|
|
|
@@ -242,18 +188,14 @@ function wrapCreate (create) {
|
|
|
242
188
|
|
|
243
189
|
if (typeof apiPromise.asResponse === 'function') {
|
|
244
190
|
shimmer.wrap(apiPromise, 'asResponse', origAsResponse => function (...asResponseArgs) {
|
|
245
|
-
return
|
|
191
|
+
return heldUntil(origAsResponse.apply(this, asResponseArgs), interceptCtx?.beforeResult?.())
|
|
246
192
|
.then(response => {
|
|
247
|
-
// Wrap
|
|
248
|
-
//
|
|
249
|
-
|
|
250
|
-
afterVerdict || messagesAfterChannel.hasSubscribers
|
|
251
|
-
if (!stream && outputObserved && wrappedResponse !== response) {
|
|
193
|
+
// Wrap json()/text()/clone() so the span still closes on the raw-response path,
|
|
194
|
+
// and not twice for the same response.
|
|
195
|
+
if (!stream && wrappedResponse !== response) {
|
|
252
196
|
wrappedResponse = response
|
|
253
|
-
wrapRawResponse(response, ctx,
|
|
197
|
+
wrapRawResponse(response, ctx, interceptCtx)
|
|
254
198
|
}
|
|
255
|
-
|
|
256
|
-
if (afterVerdict) return afterVerdict.then(() => response)
|
|
257
199
|
return response
|
|
258
200
|
})
|
|
259
201
|
.catch(error => finishAndThrow(ctx, error))
|
|
@@ -70,7 +70,6 @@ const instrumentedProtos = new WeakSet()
|
|
|
70
70
|
* observer attaches at most once (a promise settles only once). Instances we don't observe
|
|
71
71
|
* never set `ON_SETTLE`, so for them the wrappers are a single property read and a passthrough.
|
|
72
72
|
* @param {object} proto - The DurablePromise prototype (`Object.getPrototypeOf(dp)`).
|
|
73
|
-
* @returns {void}
|
|
74
73
|
*/
|
|
75
74
|
function instrumentDurablePromiseProto (proto) {
|
|
76
75
|
if (instrumentedProtos.has(proto)) return
|
|
@@ -97,7 +96,6 @@ function instrumentDurablePromiseProto (proto) {
|
|
|
97
96
|
* @param {object} dp - The returned DurablePromise instance.
|
|
98
97
|
* @param {(err: unknown) => void} onSettle - Called once with `undefined` on success or the
|
|
99
98
|
* rejection reason on failure.
|
|
100
|
-
* @returns {void}
|
|
101
99
|
*/
|
|
102
100
|
function observeDurablePromise (dp, onSettle) {
|
|
103
101
|
if (!dp || typeof dp.then !== 'function') return
|
|
@@ -105,7 +103,7 @@ function observeDurablePromise (dp, onSettle) {
|
|
|
105
103
|
dp[ON_SETTLE] = onSettle
|
|
106
104
|
}
|
|
107
105
|
|
|
108
|
-
for (const hook of getHooks('@aws/durable-execution-sdk-js')) {
|
|
106
|
+
for (const hook of getHooks('@aws/durable-execution-sdk-js').values()) {
|
|
109
107
|
hook.file = null
|
|
110
108
|
addHook(hook, exports => exports)
|
|
111
109
|
}
|
|
@@ -77,7 +77,6 @@ const clientNameCache = new WeakMap()
|
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
79
|
* @param {Function} clientCtor
|
|
80
|
-
* @returns {string}
|
|
81
80
|
*/
|
|
82
81
|
function getClientName (clientCtor) {
|
|
83
82
|
let name = clientNameCache.get(clientCtor)
|
|
@@ -93,7 +92,6 @@ const operationCache = new WeakMap()
|
|
|
93
92
|
|
|
94
93
|
/**
|
|
95
94
|
* @param {Function} commandCtor
|
|
96
|
-
* @returns {string}
|
|
97
95
|
*/
|
|
98
96
|
function getOperationName (commandCtor) {
|
|
99
97
|
let operation = operationCache.get(commandCtor)
|
|
@@ -5,6 +5,7 @@ const shimmer = require('../../datadog-shimmer')
|
|
|
5
5
|
|
|
6
6
|
const {
|
|
7
7
|
addHook,
|
|
8
|
+
getHooks,
|
|
8
9
|
} = require('./helpers/instrument')
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -12,6 +13,10 @@ const {
|
|
|
12
13
|
*/
|
|
13
14
|
const azureDurableFunctionsChannel = dc.tracingChannel('datadog:azure:durable-functions:invoke')
|
|
14
15
|
|
|
16
|
+
for (const hook of getHooks('durable-functions').values()) {
|
|
17
|
+
addHook(hook, exports => exports)
|
|
18
|
+
}
|
|
19
|
+
|
|
15
20
|
addHook({ name: 'durable-functions', versions: ['>=3'], patchDefault: false }, (df) => {
|
|
16
21
|
const { app } = df
|
|
17
22
|
|
|
@@ -42,9 +47,16 @@ function entityHandler (handler, entityName) {
|
|
|
42
47
|
if (!azureDurableFunctionsChannel.hasSubscribers) return handler.apply(this, args)
|
|
43
48
|
|
|
44
49
|
const entityContext = args[0]
|
|
50
|
+
const traceContext = entityContext?.traceContext
|
|
45
51
|
return azureDurableFunctionsChannel.traceSync(
|
|
46
52
|
handler,
|
|
47
|
-
{
|
|
53
|
+
{
|
|
54
|
+
trigger: 'Entity',
|
|
55
|
+
functionName: entityName,
|
|
56
|
+
operationName: entityContext?.df?.operationName,
|
|
57
|
+
traceparent: traceContext?.traceParent,
|
|
58
|
+
tracestate: traceContext?.traceState,
|
|
59
|
+
},
|
|
48
60
|
this, ...args)
|
|
49
61
|
}
|
|
50
62
|
}
|
|
@@ -58,16 +70,18 @@ function activityHandler (method) {
|
|
|
58
70
|
return function (...args) {
|
|
59
71
|
if (!azureDurableFunctionsChannel.hasSubscribers) return handler.apply(this, args)
|
|
60
72
|
|
|
73
|
+
const traceContext = args[1]?.traceContext
|
|
74
|
+
const channelCtx = {
|
|
75
|
+
trigger: 'Activity',
|
|
76
|
+
functionName: activityName,
|
|
77
|
+
traceparent: traceContext?.traceParent,
|
|
78
|
+
tracestate: traceContext?.traceState,
|
|
79
|
+
}
|
|
80
|
+
|
|
61
81
|
// use tracePromise if this is an async handler. otherwise, use traceSync
|
|
62
82
|
return isAsync
|
|
63
|
-
? azureDurableFunctionsChannel.tracePromise(
|
|
64
|
-
|
|
65
|
-
{ trigger: 'Activity', functionName: activityName },
|
|
66
|
-
this, ...args)
|
|
67
|
-
: azureDurableFunctionsChannel.traceSync(
|
|
68
|
-
handler,
|
|
69
|
-
{ trigger: 'Activity', functionName: activityName },
|
|
70
|
-
this, ...args)
|
|
83
|
+
? azureDurableFunctionsChannel.tracePromise(handler, channelCtx, this, ...args)
|
|
84
|
+
: azureDurableFunctionsChannel.traceSync(handler, channelCtx, this, ...args)
|
|
71
85
|
}
|
|
72
86
|
})
|
|
73
87
|
return method.apply(this, arguments)
|
|
@@ -8,6 +8,12 @@ const {
|
|
|
8
8
|
|
|
9
9
|
const azureFunctionsChannel = dc.tracingChannel('datadog:azure:functions:invoke')
|
|
10
10
|
|
|
11
|
+
// Orchestrators register via app.generic; activities/entities use the durable-functions hook.
|
|
12
|
+
const azureDurableFunctionsChannel = dc.tracingChannel('datadog:azure:durable-functions:invoke')
|
|
13
|
+
|
|
14
|
+
const ORCHESTRATION_TRIGGER_TYPE = 'orchestrationTrigger'
|
|
15
|
+
const ORCHESTRATOR_COMPLETED_EVENT_TYPE = 13
|
|
16
|
+
|
|
11
17
|
addHook({ name: '@azure/functions', versions: ['>=4'], patchDefault: false }, (azureFunction) => {
|
|
12
18
|
const { app } = azureFunction
|
|
13
19
|
|
|
@@ -29,9 +35,51 @@ addHook({ name: '@azure/functions', versions: ['>=4'], patchDefault: false }, (a
|
|
|
29
35
|
// CosmosDB triggers
|
|
30
36
|
shimmer.wrap(app, 'cosmosDB', wrapHandler)
|
|
31
37
|
|
|
38
|
+
// Durable Functions orchestration triggers
|
|
39
|
+
shimmer.wrap(app, 'generic', wrapGeneric)
|
|
40
|
+
|
|
32
41
|
return azureFunction
|
|
33
42
|
})
|
|
34
43
|
|
|
44
|
+
function wrapGeneric (method) {
|
|
45
|
+
return function (name, options) {
|
|
46
|
+
if (options?.trigger?.type === ORCHESTRATION_TRIGGER_TYPE && typeof options.handler === 'function') {
|
|
47
|
+
options.handler = traceOrchestrationHandler(options.handler, name)
|
|
48
|
+
}
|
|
49
|
+
return method.apply(this, arguments)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function traceOrchestrationHandler (handler, functionName) {
|
|
54
|
+
return function (...args) {
|
|
55
|
+
if (!azureDurableFunctionsChannel.hasSubscribers) return handler.apply(this, args)
|
|
56
|
+
|
|
57
|
+
const orchestrationBinding = args[0]
|
|
58
|
+
// we do not want to trace if the orchestrator has already completed and is being reactivated
|
|
59
|
+
const history = orchestrationBinding?.history
|
|
60
|
+
const hasPreviousActivation = history?.some(
|
|
61
|
+
event => event.EventType === ORCHESTRATOR_COMPLETED_EVENT_TYPE
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
if (hasPreviousActivation) {
|
|
65
|
+
return handler.apply(this, args)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const traceContext = args[1]?.traceContext
|
|
69
|
+
const channelCtx = {
|
|
70
|
+
trigger: 'Orchestration',
|
|
71
|
+
functionName,
|
|
72
|
+
traceparent: traceContext?.traceParent,
|
|
73
|
+
tracestate: traceContext?.traceState,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return azureDurableFunctionsChannel.tracePromise(
|
|
77
|
+
handler,
|
|
78
|
+
channelCtx,
|
|
79
|
+
this, ...args)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
35
83
|
// The http methods are overloaded so we need to check which type of argument was passed in order to wrap the handler
|
|
36
84
|
// The arguments are either an object with a handler property or the handler function itself
|
|
37
85
|
function wrapHandler (method) {
|
|
@@ -353,7 +353,6 @@ function getToolResultContent (chunk, toolUseId) {
|
|
|
353
353
|
* @param {SessionContext | null | undefined} sessionCtx
|
|
354
354
|
* @param {GetLifecycle} getLifecycle
|
|
355
355
|
* @param {ToolLifecycle} lifecycle
|
|
356
|
-
* @returns {number} index in chunks where the next step should start iteration
|
|
357
356
|
*/
|
|
358
357
|
function processTool (chunks, startIndex, toolUseId, sessionCtx, getLifecycle, lifecycle) {
|
|
359
358
|
let chunkIndex = startIndex
|
|
@@ -412,7 +411,6 @@ function processTool (chunks, startIndex, toolUseId, sessionCtx, getLifecycle, l
|
|
|
412
411
|
* @param {StepContext | null | undefined} stepCtx
|
|
413
412
|
* @param {SessionContext | null | undefined} sessionCtx
|
|
414
413
|
* @param {GetLifecycle} getLifecycle
|
|
415
|
-
* @returns {number} index in chunks where the next step should start iteration
|
|
416
414
|
*/
|
|
417
415
|
function processStep (
|
|
418
416
|
chunks,
|
|
@@ -638,7 +636,7 @@ function wrapQueryAsyncIterator (asyncIterator, ctx) {
|
|
|
638
636
|
|
|
639
637
|
let querySubscribed = false
|
|
640
638
|
|
|
641
|
-
for (const hook of getHooks('@anthropic-ai/claude-agent-sdk')) {
|
|
639
|
+
for (const hook of getHooks('@anthropic-ai/claude-agent-sdk').values()) {
|
|
642
640
|
hook.file = null
|
|
643
641
|
|
|
644
642
|
addHook(hook, exports => {
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const shimmer = require('../../datadog-shimmer')
|
|
4
|
+
const { channel } = require('./helpers/instrument')
|
|
5
|
+
|
|
6
|
+
const configureCh = channel('ci:log-submission:console:configure')
|
|
7
|
+
const logSubmissionCh = channel('ci:log-submission:console')
|
|
8
|
+
const vitestSuiteStartCh = channel('ci:vitest:test-suite:start')
|
|
9
|
+
const methods = ['error', 'warn']
|
|
10
|
+
const methodSet = new Set(methods)
|
|
11
|
+
const wrappedTargets = new WeakSet()
|
|
12
|
+
|
|
13
|
+
let callDepth = 0
|
|
14
|
+
let configuredGetLogHolder
|
|
15
|
+
let isVitestConsoleSubscribed = false
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {string} method
|
|
19
|
+
* @param {unknown[]} args
|
|
20
|
+
* @param {(() => { dd: object } | undefined) | undefined} getLogHolder
|
|
21
|
+
*/
|
|
22
|
+
function publishLog (method, args, getLogHolder) {
|
|
23
|
+
if (!logSubmissionCh.hasSubscribers) return
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const logHolder = (getLogHolder || configuredGetLogHolder)?.()
|
|
27
|
+
if (logHolder) logSubmissionCh.publish({ args, logHolder, method })
|
|
28
|
+
} catch {}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {object} target
|
|
33
|
+
* @param {(() => { dd: object } | undefined) | undefined} [getLogHolder]
|
|
34
|
+
*/
|
|
35
|
+
function wrapConsole (target, getLogHolder) {
|
|
36
|
+
if (!target || wrappedTargets.has(target)) return
|
|
37
|
+
|
|
38
|
+
wrappedTargets.add(target)
|
|
39
|
+
for (const method of methods) {
|
|
40
|
+
if (typeof target[method] !== 'function') continue
|
|
41
|
+
|
|
42
|
+
// Global console methods are bound at runtime, so source rewriting cannot intercept them.
|
|
43
|
+
try {
|
|
44
|
+
shimmer.wrap(target, method, original => function () {
|
|
45
|
+
const shouldPublish = callDepth++ === 0
|
|
46
|
+
try {
|
|
47
|
+
const result = original.apply(this, arguments)
|
|
48
|
+
if (shouldPublish) publishLog(method, [...arguments], getLogHolder)
|
|
49
|
+
return result
|
|
50
|
+
} finally {
|
|
51
|
+
callDepth--
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
} catch {}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param {{ BufferedConsole?: Function, CustomConsole?: Function }} jestConsole
|
|
60
|
+
* @param {(() => { dd: object } | undefined) | undefined} [getLogHolder]
|
|
61
|
+
*/
|
|
62
|
+
function wrapJestConsole (jestConsole, getLogHolder) {
|
|
63
|
+
if (!getLogHolder && !configuredGetLogHolder) return
|
|
64
|
+
|
|
65
|
+
const { BufferedConsole, CustomConsole } = jestConsole
|
|
66
|
+
|
|
67
|
+
if (BufferedConsole && !wrappedTargets.has(BufferedConsole)) {
|
|
68
|
+
wrappedTargets.add(BufferedConsole)
|
|
69
|
+
// Jest bundles and exports these adapter classes differently across versions, so wrap their runtime exports.
|
|
70
|
+
shimmer.wrap(BufferedConsole, 'write', original => function (buffer, method, message) {
|
|
71
|
+
const result = original.apply(this, arguments)
|
|
72
|
+
if (methodSet.has(method)) publishLog(method, [message], getLogHolder)
|
|
73
|
+
return result
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (CustomConsole && !wrappedTargets.has(CustomConsole)) {
|
|
78
|
+
wrappedTargets.add(CustomConsole)
|
|
79
|
+
shimmer.wrap(CustomConsole.prototype, '_logError', original => function (method, message) {
|
|
80
|
+
const result = original.apply(this, arguments)
|
|
81
|
+
if (methodSet.has(method)) publishLog(method, [message], getLogHolder)
|
|
82
|
+
return result
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
configureCh.subscribe(({ getLogHolder } = {}) => {
|
|
88
|
+
configuredGetLogHolder = getLogHolder
|
|
89
|
+
wrapConsole(globalThis.console)
|
|
90
|
+
if (!isVitestConsoleSubscribed) {
|
|
91
|
+
isVitestConsoleSubscribed = true
|
|
92
|
+
// Vitest replaces the global console after tracer startup and before the first suite starts.
|
|
93
|
+
vitestSuiteStartCh.subscribe(() => wrapConsole(globalThis.console))
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
module.exports = { wrapConsole, wrapJestConsole }
|