dd-trace 5.135.0 → 5.137.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/ci/cypress/support.js +2 -1
- package/ci/init.js +2 -22
- package/ci/vitest-no-worker-init-node-setup.mjs +2 -1
- package/ci/vitest-no-worker-init-runner-setup.mjs +2 -1
- package/ci/vitest-no-worker-init-setup.mjs +729 -724
- package/ci/vitest-no-worker-init-v5-setup.mjs +2 -1
- package/ext/exporters.js +0 -1
- package/index.d.ts +105 -5
- package/initialize.mjs +5 -2
- package/package.json +41 -36
- package/packages/datadog-esbuild/index.js +16 -70
- package/packages/datadog-esbuild/src/log.js +2 -29
- package/packages/datadog-instrumentations/src/ai.js +6 -1
- package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
- package/packages/datadog-instrumentations/src/cucumber.js +5 -2
- package/packages/datadog-instrumentations/src/cypress-config.js +20 -9
- package/packages/datadog-instrumentations/src/elevenlabs/activity.js +114 -0
- package/packages/datadog-instrumentations/src/elevenlabs/audio.js +104 -0
- package/packages/datadog-instrumentations/src/elevenlabs/index.js +288 -0
- package/packages/datadog-instrumentations/src/elevenlabs/session.js +444 -0
- package/packages/datadog-instrumentations/src/graphql.js +20 -17
- package/packages/datadog-instrumentations/src/helpers/bundler-esm-exports.js +582 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-log.js +38 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +576 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
- package/packages/datadog-instrumentations/src/helpers/fetch.js +51 -6
- package/packages/datadog-instrumentations/src/helpers/hook.js +29 -1
- package/packages/datadog-instrumentations/src/helpers/hooks.js +3 -7
- package/packages/datadog-instrumentations/src/helpers/lambda-handler.js +189 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +8 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +26 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/async-mutex.js +41 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/elevenlabs.js +25 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql.js +0 -36
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-client.js +30 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/modelcontextprotocol-server.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/next.js +61 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/postgres.js +33 -4
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +80 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +23 -3
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms/postgres.js +122 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
- package/packages/datadog-instrumentations/src/ioredis.js +101 -3
- package/packages/datadog-instrumentations/src/microgateway-core.js +1 -2
- package/packages/datadog-instrumentations/src/modelcontextprotocol-client.js +21 -0
- package/packages/datadog-instrumentations/src/modelcontextprotocol-sdk.js +7 -1
- package/packages/datadog-instrumentations/src/modelcontextprotocol-server.js +41 -0
- package/packages/datadog-instrumentations/src/next.js +203 -26
- package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
- package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
- package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
- package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
- package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
- package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
- package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
- package/packages/datadog-instrumentations/src/router.js +35 -12
- package/packages/datadog-instrumentations/src/vitest-main.js +10 -2
- package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
- package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
- package/packages/datadog-plugin-aws-lambda/src/arn.js +41 -0
- package/packages/datadog-plugin-aws-lambda/src/event-type-guards.js +170 -0
- package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
- package/packages/datadog-plugin-aws-lambda/src/trigger.js +339 -0
- package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +7 -0
- package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +32 -10
- package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +10 -1
- package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +4 -0
- package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +3 -0
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +50 -13
- package/packages/datadog-plugin-cypress/src/support.mjs +1353 -0
- package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
- package/packages/datadog-plugin-express/src/code_origin.js +2 -2
- package/packages/datadog-plugin-fastify/src/code_origin.js +2 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +20 -7
- package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +21 -52
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +11 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
- package/packages/datadog-plugin-google-cloud-pubsub/src/resource-names.js +24 -0
- package/packages/datadog-plugin-graphql/src/tools/transforms.js +1 -0
- package/packages/datadog-plugin-http/src/client.js +34 -10
- package/packages/datadog-plugin-http2/src/client.js +40 -14
- package/packages/datadog-plugin-modelcontextprotocol-sdk/src/tracing.js +28 -2
- package/packages/datadog-plugin-modelcontextprotocol-sdk/src/utils.js +1 -0
- package/packages/datadog-plugin-mongodb-core/src/query.js +17 -1
- package/packages/datadog-plugin-next/src/index.js +112 -14
- package/packages/datadog-plugin-postgres/src/index.js +118 -41
- package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
- package/packages/datadog-plugin-supabase/src/supabase-auth-js-gotrueclient-getuser.js +18 -8
- package/packages/datadog-plugin-supabase/src/supabase-functions-js-functionsclient-invoke.js +49 -13
- package/packages/datadog-plugin-supabase/src/supabase-storage-js-handle-request.js +34 -9
- package/packages/datadog-plugin-trpc/src/index.js +15 -0
- package/packages/datadog-plugin-trpc/src/procedure.js +48 -0
- package/packages/datadog-plugin-trpc/src/request.js +81 -0
- package/packages/datadog-plugin-undici/src/index.js +22 -7
- package/packages/datadog-plugin-vitest/src/index.js +3 -2
- package/packages/datadog-plugin-ws/src/close.js +3 -5
- package/packages/datadog-plugin-ws/src/producer.js +1 -4
- package/packages/datadog-plugin-ws/src/receiver.js +3 -5
- package/packages/datadog-plugin-ws/src/server.js +44 -13
- package/packages/datadog-turbopack/index.js +4 -28
- package/packages/datadog-turbopack/src/loader.js +14 -452
- package/packages/datadog-vite/index.js +537 -0
- package/packages/datadog-vite/src/log.js +5 -0
- package/packages/datadog-webpack/index.js +3 -55
- package/packages/datadog-webpack/src/log.js +2 -29
- package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
- package/packages/dd-trace/src/aiguard/index.js +1 -1
- package/packages/dd-trace/src/aiguard/integrations/index.js +6 -5
- package/packages/dd-trace/src/aiguard/sdk.js +8 -2
- package/packages/dd-trace/src/aiguard/tags.js +2 -0
- package/packages/dd-trace/src/appsec/blocking/index.js +21 -1
- package/packages/dd-trace/src/appsec/channels.js +7 -0
- package/packages/dd-trace/src/appsec/downstream_requests.js +105 -0
- package/packages/dd-trace/src/appsec/graphql.js +89 -7
- package/packages/dd-trace/src/appsec/handlers/auth.js +1 -3
- package/packages/dd-trace/src/appsec/handlers/http-request.js +60 -65
- package/packages/dd-trace/src/appsec/handlers/http-response.js +61 -7
- package/packages/dd-trace/src/appsec/handlers/payments.js +23 -27
- package/packages/dd-trace/src/appsec/index.js +6 -0
- package/packages/dd-trace/src/appsec/lambda.js +17 -17
- package/packages/dd-trace/src/appsec/rasp/command_injection.js +4 -4
- package/packages/dd-trace/src/appsec/rasp/index.js +8 -1
- package/packages/dd-trace/src/appsec/rasp/lfi.js +2 -2
- package/packages/dd-trace/src/appsec/rasp/sql_injection.js +7 -17
- package/packages/dd-trace/src/appsec/rasp/ssrf.js +80 -16
- package/packages/dd-trace/src/appsec/rasp/utils.js +33 -3
- package/packages/dd-trace/src/appsec/recommended.json +1358 -94
- package/packages/dd-trace/src/appsec/reporter.js +9 -0
- package/packages/dd-trace/src/appsec/sdk/set_user.js +3 -3
- package/packages/dd-trace/src/appsec/sdk/track_event.js +4 -4
- package/packages/dd-trace/src/appsec/sdk/user_blocking.js +1 -1
- package/packages/dd-trace/src/appsec/user_tracking.js +6 -8
- package/packages/dd-trace/src/appsec/waf/index.js +65 -6
- package/packages/dd-trace/src/appsec/waf/waf_context_wrapper.js +33 -38
- package/packages/dd-trace/src/appsec/waf/waf_manager.js +18 -2
- package/packages/dd-trace/src/before-exit.js +32 -0
- package/packages/dd-trace/src/bootstrap.js +5 -3
- package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +15 -2
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +12 -34
- package/packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js +41 -13
- package/packages/dd-trace/src/ci-visibility/exporters/request.js +2 -3
- package/packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js +1 -2
- package/packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js +1 -1
- package/packages/dd-trace/src/ci-visibility/telemetry.js +6 -0
- package/packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js +1 -1
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache-schema.js +9 -134
- package/packages/dd-trace/src/ci-visibility/test-optimization-http-cache.js +11 -156
- package/packages/dd-trace/src/config/config-types.d.ts +3 -0
- package/packages/dd-trace/src/config/defaults.js +5 -0
- package/packages/dd-trace/src/config/generated-config-types.d.ts +46 -4
- package/packages/dd-trace/src/config/index.js +63 -31
- package/packages/dd-trace/src/config/parsers.js +44 -0
- package/packages/dd-trace/src/config/remote-config-layers.js +38 -0
- package/packages/dd-trace/src/config/remote_config.js +2 -1
- package/packages/dd-trace/src/config/supported-configurations.json +172 -10
- package/packages/dd-trace/src/constants.js +1 -0
- package/packages/dd-trace/src/datastreams/fnv.js +27 -0
- package/packages/dd-trace/src/datastreams/pathway.js +113 -28
- package/packages/dd-trace/src/datastreams/processor.js +5 -4
- package/packages/dd-trace/src/debugger/config.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/request-options.js +7 -9
- package/packages/dd-trace/src/debugger/devtools_client/send.js +1 -1
- package/packages/dd-trace/src/debugger/devtools_client/state.js +3 -1
- package/packages/dd-trace/src/debugger/devtools_client/tags.js +1 -1
- package/packages/dd-trace/src/debugger/index.js +2 -2
- package/packages/dd-trace/src/debugger/inspect-segment.js +3 -2
- package/packages/dd-trace/src/debugger/pause-duration-histogram.js +6 -2
- package/packages/dd-trace/src/debugger/probe_sampler.js +39 -17
- package/packages/dd-trace/src/debugger/unsupported-runtime.js +2 -0
- package/packages/dd-trace/src/exporter.js +0 -11
- package/packages/dd-trace/src/exporters/common/request.js +81 -48
- package/packages/dd-trace/src/exporters/common/retry.js +12 -7
- package/packages/dd-trace/src/exporters/common/url.js +1 -1
- package/packages/dd-trace/src/git_metadata.js +2 -1
- package/packages/dd-trace/src/id.js +1 -1
- package/packages/dd-trace/src/index.js +6 -3
- package/packages/dd-trace/src/lambda/facade.js +75 -0
- package/packages/dd-trace/src/lambda/handler.js +3 -41
- package/packages/dd-trace/src/lambda/index.js +38 -15
- package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
- package/packages/dd-trace/src/lambda/wrap.js +44 -0
- package/packages/dd-trace/src/llmobs/constants/tags.js +2 -0
- package/packages/dd-trace/src/llmobs/experiments/experiment.js +10 -5
- package/packages/dd-trace/src/llmobs/plugins/elevenlabs.js +96 -0
- package/packages/dd-trace/src/llmobs/plugins/genai/util.js +19 -6
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +54 -3
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +81 -1
- package/packages/dd-trace/src/llmobs/plugins/openai/realtime.js +38 -11
- package/packages/dd-trace/src/llmobs/plugins/vertexai.js +10 -2
- package/packages/dd-trace/src/llmobs/sdk.js +19 -0
- package/packages/dd-trace/src/llmobs/span_processor.js +9 -0
- package/packages/dd-trace/src/llmobs/tagger.js +22 -0
- package/packages/dd-trace/src/log/channels.js +4 -0
- package/packages/dd-trace/src/log/writer.js +6 -1
- package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +7 -0
- package/packages/dd-trace/src/openfeature/configuration_source.js +55 -27
- package/packages/dd-trace/src/openfeature/flag-selection.js +152 -0
- package/packages/dd-trace/src/openfeature/flagging_provider.js +19 -1
- package/packages/dd-trace/src/openfeature/writers/base.js +1 -3
- package/packages/dd-trace/src/opentelemetry/logs/index.js +11 -0
- package/packages/dd-trace/src/opentelemetry/logs/otlp_http_log_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/index.js +7 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_http_metric_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_span_stats_exporter.js +4 -1
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_http_exporter_base.js +19 -1
- package/packages/dd-trace/src/opentelemetry/span-ending-hook.js +5 -1
- package/packages/dd-trace/src/opentelemetry/span-helpers.js +6 -1
- package/packages/dd-trace/src/opentelemetry/span.js +2 -2
- package/packages/dd-trace/src/opentelemetry/startup-config.js +174 -0
- package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +1 -1
- package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +7 -1
- package/packages/dd-trace/src/opentracing/propagation/tracestate.js +77 -23
- package/packages/dd-trace/src/opentracing/tracer.js +24 -0
- package/packages/dd-trace/src/otel-thread-ctx.js +28 -31
- package/packages/dd-trace/src/plugin_manager.js +34 -7
- package/packages/dd-trace/src/plugins/ci_plugin.js +143 -17
- package/packages/dd-trace/src/plugins/index.js +8 -0
- package/packages/dd-trace/src/plugins/plugin.js +4 -2
- package/packages/dd-trace/src/plugins/tracing.js +1 -1
- package/packages/dd-trace/src/plugins/util/ci.js +52 -1
- package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
- package/packages/dd-trace/src/plugins/util/git.js +263 -82
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +80 -56
- package/packages/dd-trace/src/plugins/util/inferred_proxy.js +12 -4
- package/packages/dd-trace/src/plugins/util/status-validator.js +23 -10
- package/packages/dd-trace/src/plugins/util/tags.js +6 -0
- package/packages/dd-trace/src/plugins/util/test.js +92 -40
- package/packages/dd-trace/src/plugins/util/url.js +18 -7
- package/packages/dd-trace/src/plugins/util/user-provided-git.js +6 -6
- package/packages/dd-trace/src/plugins/util/web.js +65 -10
- package/packages/dd-trace/src/process-tags/index.js +1 -1
- package/packages/dd-trace/src/profiler.js +74 -12
- package/packages/dd-trace/src/profiling/profiler.js +30 -2
- package/packages/dd-trace/src/profiling/profilers/space.js +3 -1
- package/packages/dd-trace/src/profiling/profilers/wall.js +4 -4
- package/packages/dd-trace/src/profiling/remote-config.js +354 -0
- package/packages/dd-trace/src/profiling/runtime-capabilities.js +11 -0
- package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
- package/packages/dd-trace/src/propagation-hash/index.js +7 -0
- package/packages/dd-trace/src/proxy.js +46 -54
- package/packages/dd-trace/src/span_processor.js +20 -0
- package/packages/dd-trace/src/startup-log.js +8 -6
- package/packages/dd-trace/src/telemetry/metrics.js +2 -1
- package/packages/dd-trace/src/tracer.js +0 -2
- package/packages/dd-trace/src/web-tags-cache.js +8 -9
- package/register.js +2 -1
- package/vendor/dist/@apm-js-collab/code-transformer/LICENSE +489 -0
- package/vendor/dist/@datadog/flagging-core/LICENSE +221 -0
- package/vendor/dist/@datadog/flagging-core/index.js +1 -0
- package/vendor/dist/@datadog/openfeature-node-server/LICENSE +21 -1
- package/vendor/dist/@datadog/openfeature-node-server/rules-based/LICENSE +3 -1
- package/vendor/dist/@datadog/sketches-js/LICENSE +263 -0
- package/vendor/dist/@datadog/source-map/LICENSE +1 -0
- package/vendor/dist/@isaacs/ttlcache/LICENSE +13 -0
- package/vendor/dist/@opentelemetry/core/LICENSE +220 -1
- package/vendor/dist/@opentelemetry/core/index.js +1 -1
- package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
- package/vendor/dist/escape-string-regexp/LICENSE +13 -0
- package/vendor/dist/esquery/LICENSE +2 -0
- package/vendor/dist/https-proxy-agent/LICENSE +80 -1
- package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
- package/vendor/dist/jest-docblock/LICENSE +16 -0
- package/vendor/dist/jsonpath-plus/LICENSE +13 -0
- package/vendor/dist/limiter/LICENSE +2 -0
- package/vendor/dist/lodash.sortby/LICENSE +2 -0
- package/vendor/dist/lru-cache/LICENSE +13 -0
- package/vendor/dist/meriyah/LICENSE +13 -0
- package/vendor/dist/module-details-from-path/LICENSE +2 -0
- package/vendor/dist/mutexify/promise/LICENSE +28 -0
- package/vendor/dist/pprof-format/LICENSE +13 -0
- package/vendor/dist/pprof-format/index.js +1 -1
- package/vendor/dist/protobufjs/LICENSE +219 -0
- package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
- package/vendor/dist/proxy-from-env/LICENSE +13 -0
- package/vendor/dist/retry/LICENSE +2 -0
- package/vendor/dist/rfdc/LICENSE +2 -0
- package/vendor/dist/semifies/LICENSE +3 -1
- package/vendor/dist/shell-quote/LICENSE +3 -1
- package/vendor/dist/source-map/LICENSE +1 -0
- package/vendor/dist/source-map/lib/util/LICENSE +1 -0
- package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
- package/vendor/dist/ttl-set/LICENSE +28 -0
- package/vite.d.ts +7 -0
- package/vite.js +3 -0
- package/ci/diagnose.js +0 -2215
- package/ci/runbook.md +0 -299
- package/ci/test-optimization-validation/approval-artifacts.js +0 -175
- package/ci/test-optimization-validation/approval.js +0 -386
- package/ci/test-optimization-validation/artifact-id.js +0 -18
- package/ci/test-optimization-validation/blocker-category.js +0 -24
- package/ci/test-optimization-validation/bounded-json.js +0 -120
- package/ci/test-optimization-validation/ci-command-candidate.js +0 -77
- package/ci/test-optimization-validation/ci-discovery.js +0 -192
- package/ci/test-optimization-validation/ci-package-scripts.js +0 -169
- package/ci/test-optimization-validation/ci-remediation.js +0 -283
- package/ci/test-optimization-validation/cli.js +0 -954
- package/ci/test-optimization-validation/command-blocker.js +0 -377
- package/ci/test-optimization-validation/command-output-policy.js +0 -188
- package/ci/test-optimization-validation/command-runner.js +0 -649
- package/ci/test-optimization-validation/environment.js +0 -88
- package/ci/test-optimization-validation/executable-approval.js +0 -47
- package/ci/test-optimization-validation/executable.js +0 -244
- package/ci/test-optimization-validation/execution-lock.js +0 -70
- package/ci/test-optimization-validation/framework-adapters/cucumber-validation.json +0 -3
- package/ci/test-optimization-validation/framework-adapters/cucumber.js +0 -767
- package/ci/test-optimization-validation/framework-adapters/cypress.js +0 -99
- package/ci/test-optimization-validation/framework-adapters/playwright.js +0 -175
- package/ci/test-optimization-validation/framework-adapters/vitest.js +0 -513
- package/ci/test-optimization-validation/generated-file-policy.js +0 -63
- package/ci/test-optimization-validation/generated-files.js +0 -425
- package/ci/test-optimization-validation/generated-test-contract.js +0 -284
- package/ci/test-optimization-validation/generated-verifier.js +0 -235
- package/ci/test-optimization-validation/literal-environment.js +0 -56
- package/ci/test-optimization-validation/literal-glob.js +0 -52
- package/ci/test-optimization-validation/manifest-loader.js +0 -116
- package/ci/test-optimization-validation/manifest-scaffold.js +0 -1276
- package/ci/test-optimization-validation/manifest-schema.js +0 -695
- package/ci/test-optimization-validation/offline-fixtures.js +0 -335
- package/ci/test-optimization-validation/offline-output.js +0 -406
- package/ci/test-optimization-validation/package-check.js +0 -97
- package/ci/test-optimization-validation/payload-normalizer.js +0 -72
- package/ci/test-optimization-validation/plan-writer.js +0 -541
- package/ci/test-optimization-validation/preflight-runner.js +0 -186
- package/ci/test-optimization-validation/project-build-artifact.js +0 -31
- package/ci/test-optimization-validation/redaction.js +0 -319
- package/ci/test-optimization-validation/report-writer.js +0 -666
- package/ci/test-optimization-validation/result-semantics.js +0 -103
- package/ci/test-optimization-validation/runner-command.js +0 -264
- package/ci/test-optimization-validation/runner-contract.js +0 -695
- package/ci/test-optimization-validation/safe-files.js +0 -202
- package/ci/test-optimization-validation/scenarios/auto-test-retries.js +0 -171
- package/ci/test-optimization-validation/scenarios/basic-reporting.js +0 -407
- package/ci/test-optimization-validation/scenarios/ci-wiring.js +0 -666
- package/ci/test-optimization-validation/scenarios/early-flake-detection.js +0 -142
- package/ci/test-optimization-validation/scenarios/helpers.js +0 -621
- package/ci/test-optimization-validation/scenarios/test-management.js +0 -219
- package/ci/test-optimization-validation/source-text.js +0 -84
- package/ci/test-optimization-validation/static-diagnosis.js +0 -166
- package/ci/test-optimization-validation/test-output.js +0 -120
- package/ci/test-optimization-validation/validation-blocker.js +0 -21
- package/ci/validate-test-optimization.js +0 -3
- package/packages/datadog-esbuild/src/resolver.js +0 -284
- package/packages/datadog-esbuild/src/utils.js +0 -318
- package/packages/datadog-plugin-cypress/src/support.js +0 -1348
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/index.js +0 -156
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/msgpack-to-json.js +0 -287
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/payload-projection.js +0 -84
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/sink.js +0 -368
- package/packages/dd-trace/src/ci-visibility/exporters/ci-validation/writer.js +0 -59
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// Ported from datadog-lambda-js at da9fc3c0c9dca00893f70c9a1bd5ac1254af3b01.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {string} arn
|
|
7
|
+
* @param {string} [version]
|
|
8
|
+
*/
|
|
9
|
+
function parseLambdaARN (arn, version) {
|
|
10
|
+
let [, , , region, accountId, , functionname, alias] = arn.split(':')
|
|
11
|
+
const tags = { region, account_id: accountId, functionname }
|
|
12
|
+
// If we have an alias...
|
|
13
|
+
if (alias === undefined) {
|
|
14
|
+
tags.resource = functionname
|
|
15
|
+
} else {
|
|
16
|
+
// Check if $Latest and remove $ for datadog tag convention.
|
|
17
|
+
if (alias.startsWith('$')) {
|
|
18
|
+
alias = alias.slice(1)
|
|
19
|
+
// Check if this is an alias and not a version.
|
|
20
|
+
} else if (!Number(alias)) {
|
|
21
|
+
tags.executedversion = version
|
|
22
|
+
}
|
|
23
|
+
tags.resource = functionname + ':' + alias
|
|
24
|
+
}
|
|
25
|
+
return tags
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @param {Record<string, string | undefined>} tags */
|
|
29
|
+
function makeTagStringsFromObject (tags) {
|
|
30
|
+
return Object.entries(tags).map(([tagKey, tagValue]) => `${tagKey}:${tagValue}`)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {string} arn
|
|
35
|
+
* @param {string} [version]
|
|
36
|
+
*/
|
|
37
|
+
function parseTagsFromARN (arn, version) {
|
|
38
|
+
return makeTagStringsFromObject(parseLambdaARN(arn, version))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = { parseLambdaARN, parseTagsFromARN }
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// Ported from datadog-lambda-js at da9fc3c0c9dca00893f70c9a1bd5ac1254af3b01.
|
|
4
|
+
|
|
5
|
+
const API_GATEWAY_EVENT_V2 = '2.0'
|
|
6
|
+
|
|
7
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
8
|
+
function isAPIGatewayEvent (event) {
|
|
9
|
+
return event.requestContext?.stage !== undefined && event.httpMethod !== undefined && event.resource !== undefined
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
13
|
+
function isAPIGatewayEventV2 (event) {
|
|
14
|
+
return (
|
|
15
|
+
event.requestContext !== undefined &&
|
|
16
|
+
event.version === API_GATEWAY_EVENT_V2 &&
|
|
17
|
+
event.rawQueryString !== undefined &&
|
|
18
|
+
!event.requestContext.domainName.includes('lambda-url')
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
23
|
+
function isAPIGatewayWebsocketEvent (event) {
|
|
24
|
+
return event.requestContext !== undefined && event.requestContext.messageDirection !== undefined
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
28
|
+
function isALBEvent (event) {
|
|
29
|
+
return event.requestContext !== undefined && event.requestContext.elb !== undefined
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
33
|
+
function isCloudWatchLogsEvent (event) {
|
|
34
|
+
return event.awslogs !== undefined
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
38
|
+
function isCloudWatchEvent (event) {
|
|
39
|
+
return event.source !== undefined && event.source === 'aws.events'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
43
|
+
function isCloudFrontRequestEvent (event) {
|
|
44
|
+
return Array.isArray(event.Records) && event.Records.length > 0 && event.Records[0].cf !== undefined
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
48
|
+
function isDynamoDBStreamEvent (event) {
|
|
49
|
+
return Array.isArray(event.Records) && event.Records.length > 0 && event.Records[0].dynamodb !== undefined
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
53
|
+
function isKinesisStreamEvent (event) {
|
|
54
|
+
return Array.isArray(event.Records) && event.Records.length > 0 && event.Records[0].kinesis !== undefined
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
58
|
+
function isS3Event (event) {
|
|
59
|
+
return Array.isArray(event.Records) && event.Records.length > 0 && event.Records[0].s3 !== undefined
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
63
|
+
function isSNSEvent (event) {
|
|
64
|
+
return Array.isArray(event.Records) && event.Records.length > 0 && event.Records[0].Sns !== undefined
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
68
|
+
function isSQSEvent (event) {
|
|
69
|
+
return Array.isArray(event.Records) && event.Records.length > 0 && event.Records[0].eventSource === 'aws:sqs'
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
73
|
+
function isSNSSQSEvent (event) {
|
|
74
|
+
if (isSQSEvent(event)) {
|
|
75
|
+
try {
|
|
76
|
+
const body = JSON.parse(event.Records[0].body)
|
|
77
|
+
if (body.Type === 'Notification' && body.TopicArn) {
|
|
78
|
+
return true
|
|
79
|
+
}
|
|
80
|
+
} catch {
|
|
81
|
+
return false
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return false
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
88
|
+
function isEventBridgeSQSEvent (event) {
|
|
89
|
+
if (isSQSEvent(event)) {
|
|
90
|
+
try {
|
|
91
|
+
const body = JSON.parse(event.Records[0].body)
|
|
92
|
+
return body['detail-type'] !== undefined
|
|
93
|
+
} catch {
|
|
94
|
+
return false
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return false
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
101
|
+
function isAppSyncResolverEvent (event) {
|
|
102
|
+
return event.info !== undefined && event.info.selectionSetGraphQL !== undefined
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
106
|
+
function isEventBridgeEvent (event) {
|
|
107
|
+
return event['detail-type'] !== undefined
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
111
|
+
function isLambdaUrlEvent (event) {
|
|
112
|
+
return event?.requestContext?.domainName?.includes('lambda-url')
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Preserve the pinned shim's null/object semantics, including malformed-envelope throws.
|
|
116
|
+
/* eslint-disable eslint-rules/eslint-safe-typeof-object */
|
|
117
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
118
|
+
function isStepFunctionsEvent (event) {
|
|
119
|
+
// Extract Payload if available (Legacy lambda parsing)
|
|
120
|
+
if (typeof event.Payload === 'object') {
|
|
121
|
+
event = event.Payload
|
|
122
|
+
}
|
|
123
|
+
// Extract _datadog if available (JSONata v1 parsing)
|
|
124
|
+
if (typeof event._datadog === 'object') {
|
|
125
|
+
event = event._datadog
|
|
126
|
+
}
|
|
127
|
+
return (
|
|
128
|
+
typeof event.Execution === 'object' && typeof event.State === 'object' && typeof event.StateMachine === 'object'
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/* eslint-enable eslint-rules/eslint-safe-typeof-object */
|
|
133
|
+
|
|
134
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
135
|
+
function isMSKEvent (event) {
|
|
136
|
+
return (
|
|
137
|
+
event?.eventSource === 'aws:kafka' &&
|
|
138
|
+
event.records !== null &&
|
|
139
|
+
typeof event.records === 'object' &&
|
|
140
|
+
!Array.isArray(event.records)
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** @param {Record<string, unknown>} event Lambda trigger payload. */
|
|
145
|
+
function isDurableExecutionEvent (event) {
|
|
146
|
+
return typeof event.DurableExecutionArn === 'string'
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
module.exports = {
|
|
150
|
+
isAPIGatewayEvent,
|
|
151
|
+
isAPIGatewayEventV2,
|
|
152
|
+
isAPIGatewayWebsocketEvent,
|
|
153
|
+
isALBEvent,
|
|
154
|
+
isCloudWatchLogsEvent,
|
|
155
|
+
isCloudWatchEvent,
|
|
156
|
+
isCloudFrontRequestEvent,
|
|
157
|
+
isDynamoDBStreamEvent,
|
|
158
|
+
isKinesisStreamEvent,
|
|
159
|
+
isS3Event,
|
|
160
|
+
isSNSEvent,
|
|
161
|
+
isSQSEvent,
|
|
162
|
+
isSNSSQSEvent,
|
|
163
|
+
isEventBridgeSQSEvent,
|
|
164
|
+
isAppSyncResolverEvent,
|
|
165
|
+
isEventBridgeEvent,
|
|
166
|
+
isLambdaUrlEvent,
|
|
167
|
+
isStepFunctionsEvent,
|
|
168
|
+
isMSKEvent,
|
|
169
|
+
isDurableExecutionEvent,
|
|
170
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const dc = require('dc-polyfill')
|
|
4
|
+
|
|
5
|
+
const { getEnvironmentVariable } = require('../../dd-trace/src/config/helper')
|
|
6
|
+
const TracingPlugin = require('../../dd-trace/src/plugins/tracing')
|
|
7
|
+
|
|
8
|
+
const invocationStartChannel = dc.channel('datadog:aws-lambda:invocation:start')
|
|
9
|
+
const invocationEndChannel = dc.channel('datadog:aws-lambda:invocation:end')
|
|
10
|
+
|
|
11
|
+
class AwsLambdaPlugin extends TracingPlugin {
|
|
12
|
+
/**
|
|
13
|
+
* Starts the invocation span and publishes the invocation start boundary.
|
|
14
|
+
*
|
|
15
|
+
* Impending-timeout monitoring is deliberately not here: it belongs to
|
|
16
|
+
* `packages/dd-trace/src/lambda/handler.js`, which decorates whatever span is active rather than
|
|
17
|
+
* one it owns. That is what lets it work while the pre-migration shim still owns the span.
|
|
18
|
+
*
|
|
19
|
+
* @param {object} context Invocation channel context.
|
|
20
|
+
* @returns {object} Trace store bound to the customer handler.
|
|
21
|
+
*/
|
|
22
|
+
bindStart (context) {
|
|
23
|
+
const functionName = context.context?.functionName ||
|
|
24
|
+
getEnvironmentVariable('AWS_LAMBDA_FUNCTION_NAME')
|
|
25
|
+
// TODO(migration PR 8): the extracted upstream context becomes the parent. Until the context
|
|
26
|
+
// extractors land, pinning `childOf` keeps the span from adopting a stale active span left
|
|
27
|
+
// behind by a previous invocation in the same warm container.
|
|
28
|
+
const span = this.startSpan('aws.lambda', {
|
|
29
|
+
childOf: null,
|
|
30
|
+
kind: 'server',
|
|
31
|
+
resource: functionName,
|
|
32
|
+
service: resolveServiceName(functionName, this.config, context.config),
|
|
33
|
+
type: 'serverless',
|
|
34
|
+
}, context)
|
|
35
|
+
|
|
36
|
+
context.lambdaSpan = span
|
|
37
|
+
invocationStartChannel.publish(context)
|
|
38
|
+
|
|
39
|
+
return context.currentStore
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Tags handler failures on the invocation span.
|
|
44
|
+
*
|
|
45
|
+
* @param {{ error?: unknown, lambdaSpan?: object }} context Invocation channel context.
|
|
46
|
+
*/
|
|
47
|
+
error (context) {
|
|
48
|
+
this.addError(context.error, context.lambdaSpan)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Restores invocation scope when completion arrives through an externally invoked callback.
|
|
53
|
+
*
|
|
54
|
+
* @param {object} context Invocation channel context.
|
|
55
|
+
* @returns {object} Invocation trace store.
|
|
56
|
+
*/
|
|
57
|
+
bindAsyncStart (context) {
|
|
58
|
+
return context.currentStore
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Publishes the completed invocation and finishes its span.
|
|
63
|
+
*
|
|
64
|
+
* @param {object} context Invocation channel context.
|
|
65
|
+
*/
|
|
66
|
+
asyncStart (context) {
|
|
67
|
+
invocationEndChannel.publish(context)
|
|
68
|
+
// Span.finish() is idempotent, so a span the impending-timeout monitor already finished when
|
|
69
|
+
// it fired is left untouched here.
|
|
70
|
+
context.lambdaSpan?.finish()
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Honors per-handler and plugin service overrides before applying datadog-lambda-js service defaults.
|
|
76
|
+
*
|
|
77
|
+
* Fallbacks ported from `datadog-lambda-js/src/trace/listener.ts:386-397`. The service-naming schema's
|
|
78
|
+
* `identityService` would hand back dd-trace's `Config.service`, which inside a Lambda is
|
|
79
|
+
* `normalizeService(AWS_LAMBDA_FUNCTION_NAME)` — lowercased. `DD_SERVICE` is read raw and trimmed
|
|
80
|
+
* for the same reason. Customers key dashboards and monitors off this value.
|
|
81
|
+
*
|
|
82
|
+
* @param {string} functionName Lambda function name.
|
|
83
|
+
* @param {{ service?: string, serviceRepresentationEnabled?: boolean }} pluginConfig Plugin-specific configuration.
|
|
84
|
+
* @param {{ service?: string, serviceRepresentationEnabled?: boolean }} [handlerConfig] Per-handler overrides.
|
|
85
|
+
*/
|
|
86
|
+
function resolveServiceName (functionName, pluginConfig, handlerConfig) {
|
|
87
|
+
const service = handlerConfig?.service ?? pluginConfig.service
|
|
88
|
+
if (service) return service
|
|
89
|
+
|
|
90
|
+
const envService = getEnvironmentVariable('DD_SERVICE')
|
|
91
|
+
if (envService && envService.trim().length > 0) return envService.trim()
|
|
92
|
+
|
|
93
|
+
const serviceRepresentationEnabled = handlerConfig?.serviceRepresentationEnabled ??
|
|
94
|
+
pluginConfig.serviceRepresentationEnabled
|
|
95
|
+
if (serviceRepresentationEnabled === false) return 'aws.lambda'
|
|
96
|
+
|
|
97
|
+
return functionName || 'aws.lambda'
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
AwsLambdaPlugin.id = 'aws-lambda'
|
|
101
|
+
AwsLambdaPlugin.kind = 'server'
|
|
102
|
+
AwsLambdaPlugin.operation = 'invoke'
|
|
103
|
+
AwsLambdaPlugin.prefix = 'tracing:datadog:aws-lambda:invoke'
|
|
104
|
+
AwsLambdaPlugin.type = 'serverless'
|
|
105
|
+
|
|
106
|
+
module.exports = AwsLambdaPlugin
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// Ported from datadog-lambda-js at da9fc3c0c9dca00893f70c9a1bd5ac1254af3b01.
|
|
4
|
+
|
|
5
|
+
const { gunzipSync } = require('node:zlib')
|
|
6
|
+
|
|
7
|
+
const log = require('../../dd-trace/src/log')
|
|
8
|
+
const eventType = require('./event-type-guards')
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {string | undefined} eventSource
|
|
12
|
+
*/
|
|
13
|
+
function isHTTPTriggerEvent (eventSource) {
|
|
14
|
+
return (
|
|
15
|
+
eventSource === 'api-gateway' ||
|
|
16
|
+
eventSource === 'application-load-balancer' ||
|
|
17
|
+
eventSource === 'lambda-function-url'
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {string} region
|
|
23
|
+
*/
|
|
24
|
+
function getAWSPartitionByRegion (region) {
|
|
25
|
+
if (region.startsWith('us-gov-')) {
|
|
26
|
+
return 'aws-us-gov'
|
|
27
|
+
} else if (region.startsWith('cn-')) {
|
|
28
|
+
return 'aws-cn'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return 'aws'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param {Record<string, unknown>} event
|
|
36
|
+
*/
|
|
37
|
+
function extractCloudWatchLogsEventDecodedLogs (event) {
|
|
38
|
+
const buffer = Buffer.from(event.awslogs.data, 'base64')
|
|
39
|
+
const decompressed = gunzipSync(buffer).toString()
|
|
40
|
+
return JSON.parse(decompressed)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Preserve the pinned shim's envelope order and null behavior.
|
|
44
|
+
/* eslint-disable eslint-rules/eslint-safe-typeof-object */
|
|
45
|
+
/**
|
|
46
|
+
* @param {Record<string, unknown>} event
|
|
47
|
+
*/
|
|
48
|
+
function extractStateMachineARN (event) {
|
|
49
|
+
// Extract Payload if available (Legacy lambda parsing)
|
|
50
|
+
if (typeof event.Payload === 'object') {
|
|
51
|
+
event = event.Payload
|
|
52
|
+
}
|
|
53
|
+
// Extract _datadog if available (JSONata v1 parsing)
|
|
54
|
+
if (typeof event._datadog === 'object') {
|
|
55
|
+
event = event._datadog
|
|
56
|
+
}
|
|
57
|
+
return event.StateMachine.Id
|
|
58
|
+
}
|
|
59
|
+
/* eslint-enable eslint-rules/eslint-safe-typeof-object */
|
|
60
|
+
|
|
61
|
+
const eventTypes = {
|
|
62
|
+
apiGateway: 'api-gateway',
|
|
63
|
+
applicationLoadBalancer: 'application-load-balancer',
|
|
64
|
+
cloudFront: 'cloudfront',
|
|
65
|
+
cloudWatchEvents: 'cloudwatch-events',
|
|
66
|
+
cloudWatchLogs: 'cloudwatch-logs',
|
|
67
|
+
cloudWatch: 'cloudwatch',
|
|
68
|
+
dynamoDB: 'dynamodb',
|
|
69
|
+
eventBridge: 'eventbridge',
|
|
70
|
+
kinesis: 'kinesis',
|
|
71
|
+
lambdaUrl: 'lambda-function-url',
|
|
72
|
+
s3: 's3',
|
|
73
|
+
sns: 'sns',
|
|
74
|
+
sqs: 'sqs',
|
|
75
|
+
stepFunctions: 'states',
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const eventSubTypes = {
|
|
79
|
+
apiGatewayV1: 'api-gateway-rest-api',
|
|
80
|
+
apiGatewayV2: 'api-gateway-http-api',
|
|
81
|
+
apiGatewayWebsocket: 'api-gateway-websocket',
|
|
82
|
+
unknown: 'unknown-sub-type',
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @param {Record<string, unknown>} event
|
|
87
|
+
*/
|
|
88
|
+
function parseEventSourceSubtype (event) {
|
|
89
|
+
if (eventType.isAPIGatewayEvent(event)) {
|
|
90
|
+
return eventSubTypes.apiGatewayV1
|
|
91
|
+
}
|
|
92
|
+
if (eventType.isAPIGatewayEventV2(event)) {
|
|
93
|
+
return eventSubTypes.apiGatewayV2
|
|
94
|
+
}
|
|
95
|
+
if (eventType.isAPIGatewayWebsocketEvent(event)) {
|
|
96
|
+
return eventSubTypes.apiGatewayWebsocket
|
|
97
|
+
}
|
|
98
|
+
return eventSubTypes.unknown
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* parseEventSource parses the triggering event to determine the source
|
|
103
|
+
* Possible Returns:
|
|
104
|
+
* api-gateway | application-load-balancer | cloudwatch-logs |
|
|
105
|
+
* cloudwatch-events | cloudfront | dynamodb | kinesis | s3 | sns | sqs | states
|
|
106
|
+
*
|
|
107
|
+
* @param {Record<string, unknown>} event
|
|
108
|
+
*/
|
|
109
|
+
function parseEventSource (event) {
|
|
110
|
+
if (eventType.isLambdaUrlEvent(event)) {
|
|
111
|
+
return eventTypes.lambdaUrl
|
|
112
|
+
}
|
|
113
|
+
if (
|
|
114
|
+
eventType.isAPIGatewayEvent(event) ||
|
|
115
|
+
eventType.isAPIGatewayEventV2(event) ||
|
|
116
|
+
eventType.isAPIGatewayWebsocketEvent(event)
|
|
117
|
+
) {
|
|
118
|
+
return eventTypes.apiGateway
|
|
119
|
+
}
|
|
120
|
+
if (eventType.isALBEvent(event)) {
|
|
121
|
+
return eventTypes.applicationLoadBalancer
|
|
122
|
+
}
|
|
123
|
+
if (eventType.isCloudWatchLogsEvent(event)) {
|
|
124
|
+
return eventTypes.cloudWatchLogs
|
|
125
|
+
}
|
|
126
|
+
if (eventType.isCloudWatchEvent(event)) {
|
|
127
|
+
return eventTypes.cloudWatchEvents
|
|
128
|
+
}
|
|
129
|
+
if (eventType.isCloudFrontRequestEvent(event)) {
|
|
130
|
+
return eventTypes.cloudFront
|
|
131
|
+
}
|
|
132
|
+
if (eventType.isDynamoDBStreamEvent(event)) {
|
|
133
|
+
return eventTypes.dynamoDB
|
|
134
|
+
}
|
|
135
|
+
if (eventType.isKinesisStreamEvent(event)) {
|
|
136
|
+
return eventTypes.kinesis
|
|
137
|
+
}
|
|
138
|
+
if (eventType.isS3Event(event)) {
|
|
139
|
+
return eventTypes.s3
|
|
140
|
+
}
|
|
141
|
+
if (eventType.isSNSEvent(event)) {
|
|
142
|
+
return eventTypes.sns
|
|
143
|
+
}
|
|
144
|
+
if (eventType.isSQSEvent(event)) {
|
|
145
|
+
return eventTypes.sqs
|
|
146
|
+
}
|
|
147
|
+
if (eventType.isEventBridgeEvent(event)) {
|
|
148
|
+
return eventTypes.eventBridge
|
|
149
|
+
}
|
|
150
|
+
if (eventType.isStepFunctionsEvent(event)) {
|
|
151
|
+
return eventTypes.stepFunctions
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* parseEventSourceARN parses the triggering event to determine the event source's
|
|
157
|
+
* ARN if available. Otherwise we stitch together the ARN
|
|
158
|
+
*
|
|
159
|
+
* @param {string | undefined} source
|
|
160
|
+
* @param {Record<string, unknown>} event
|
|
161
|
+
* @param {{ invokedFunctionArn: string }} context
|
|
162
|
+
*/
|
|
163
|
+
function parseEventSourceARN (source, event, context) {
|
|
164
|
+
const splitFunctionArn = context.invokedFunctionArn.split(':')
|
|
165
|
+
const region = splitFunctionArn[3]
|
|
166
|
+
const accountId = splitFunctionArn[4]
|
|
167
|
+
const awsARN = getAWSPartitionByRegion(region)
|
|
168
|
+
switch (source) {
|
|
169
|
+
case 's3': {
|
|
170
|
+
return event.Records[0].s3.bucket.arn
|
|
171
|
+
}
|
|
172
|
+
case 'sns': {
|
|
173
|
+
return event.Records[0].Sns.TopicArn
|
|
174
|
+
}
|
|
175
|
+
case 'sqs': {
|
|
176
|
+
return event.Records[0].eventSourceARN
|
|
177
|
+
}
|
|
178
|
+
case 'cloudfront': {
|
|
179
|
+
const distributionId = event.Records[0].cf.config.distributionId
|
|
180
|
+
return `arn:${awsARN}:cloudfront::${accountId}:distribution/${distributionId}`
|
|
181
|
+
}
|
|
182
|
+
case 'api-gateway': {
|
|
183
|
+
const requestContext = event.requestContext
|
|
184
|
+
return `arn:${awsARN}:apigateway:${region}::/restapis/${requestContext.apiId}` +
|
|
185
|
+
`/stages/${requestContext.stage}`
|
|
186
|
+
}
|
|
187
|
+
case 'application-load-balancer': {
|
|
188
|
+
return event.requestContext.elb.targetGroupArn
|
|
189
|
+
}
|
|
190
|
+
case 'cloudwatch-logs': {
|
|
191
|
+
const logs = extractCloudWatchLogsEventDecodedLogs(event)
|
|
192
|
+
return `arn:${awsARN}:logs:${region}:${accountId}:log-group:${logs.logGroup}`
|
|
193
|
+
}
|
|
194
|
+
case 'cloudwatch-events': {
|
|
195
|
+
return event.resources[0]
|
|
196
|
+
}
|
|
197
|
+
case 'dynamodb': {
|
|
198
|
+
return event.Records[0].eventSourceARN
|
|
199
|
+
}
|
|
200
|
+
case 'kinesis': {
|
|
201
|
+
return event.Records[0].eventSourceARN
|
|
202
|
+
}
|
|
203
|
+
case 'eventbridge': {
|
|
204
|
+
return event.source
|
|
205
|
+
}
|
|
206
|
+
case 'states': {
|
|
207
|
+
return extractStateMachineARN(event)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* extractHTTPTags extracts HTTP facet tags from the triggering event
|
|
214
|
+
*
|
|
215
|
+
* @param {Record<string, unknown>} event
|
|
216
|
+
*/
|
|
217
|
+
function extractHTTPTags (event) {
|
|
218
|
+
const httpTags = {}
|
|
219
|
+
if (eventType.isAPIGatewayEvent(event)) {
|
|
220
|
+
const requestContext = event.requestContext
|
|
221
|
+
const path = requestContext.path
|
|
222
|
+
if (requestContext.domainName) {
|
|
223
|
+
httpTags['http.url'] = `https://${requestContext.domainName}${path ?? ''}`
|
|
224
|
+
}
|
|
225
|
+
httpTags['http.url_details.path'] = path
|
|
226
|
+
httpTags['http.method'] = requestContext.httpMethod
|
|
227
|
+
if (event.headers?.Referer) {
|
|
228
|
+
httpTags['http.referer'] = event.headers.Referer
|
|
229
|
+
}
|
|
230
|
+
if (event.resource) {
|
|
231
|
+
httpTags['http.route'] = event.resource
|
|
232
|
+
}
|
|
233
|
+
return httpTags
|
|
234
|
+
}
|
|
235
|
+
if (eventType.isAPIGatewayEventV2(event)) {
|
|
236
|
+
const requestContext = event.requestContext
|
|
237
|
+
const path = requestContext.http.path
|
|
238
|
+
httpTags['http.url'] = `https://${requestContext.domainName}${path ?? ''}`
|
|
239
|
+
httpTags['http.url_details.path'] = path
|
|
240
|
+
httpTags['http.method'] = requestContext.http.method
|
|
241
|
+
if (event.headers?.Referer) {
|
|
242
|
+
httpTags['http.referer'] = event.headers.Referer
|
|
243
|
+
}
|
|
244
|
+
if (event.routeKey) {
|
|
245
|
+
// "GET /my/endpoint" => "/my/endpoint"
|
|
246
|
+
const array = event.routeKey.split(' ')
|
|
247
|
+
httpTags['http.route'] = array.at(-1)
|
|
248
|
+
}
|
|
249
|
+
return httpTags
|
|
250
|
+
}
|
|
251
|
+
if (eventType.isALBEvent(event)) {
|
|
252
|
+
httpTags['http.url_details.path'] = event.path
|
|
253
|
+
httpTags['http.method'] = event.httpMethod
|
|
254
|
+
if (event.headers && event.headers.Referer) {
|
|
255
|
+
httpTags['http.referer'] = event.headers.Referer
|
|
256
|
+
}
|
|
257
|
+
return httpTags
|
|
258
|
+
}
|
|
259
|
+
if (eventType.isLambdaUrlEvent(event)) {
|
|
260
|
+
const requestContext = event.requestContext
|
|
261
|
+
const path = requestContext.http.path
|
|
262
|
+
if (requestContext.domainName) {
|
|
263
|
+
httpTags['http.url'] = `https://${requestContext.domainName}${path ?? ''}`
|
|
264
|
+
}
|
|
265
|
+
httpTags['http.url_details.path'] = path
|
|
266
|
+
httpTags['http.method'] = requestContext.http.method
|
|
267
|
+
if (event.headers?.Referer) {
|
|
268
|
+
httpTags['http.referer'] = event.headers.Referer
|
|
269
|
+
}
|
|
270
|
+
return httpTags
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* extractTriggerTags parses the trigger event object for tags to be added to the span metadata
|
|
276
|
+
*
|
|
277
|
+
* @param {Record<string, unknown>} event
|
|
278
|
+
* @param {{ invokedFunctionArn: string }} context
|
|
279
|
+
* @param {string | undefined} eventSource
|
|
280
|
+
*/
|
|
281
|
+
function extractTriggerTags (event, context, eventSource) {
|
|
282
|
+
let triggerTags = {}
|
|
283
|
+
if (eventSource) {
|
|
284
|
+
triggerTags['function_trigger.event_source'] = eventSource
|
|
285
|
+
let eventSourceARN
|
|
286
|
+
try {
|
|
287
|
+
eventSourceARN = parseEventSourceARN(eventSource, event, context)
|
|
288
|
+
} catch (error) {
|
|
289
|
+
log.debug('failed to extract %s arn from the event: %s', eventSource, error)
|
|
290
|
+
}
|
|
291
|
+
if (eventSourceARN) {
|
|
292
|
+
triggerTags['function_trigger.event_source_arn'] = eventSourceARN
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (isHTTPTriggerEvent(eventSource)) {
|
|
296
|
+
try {
|
|
297
|
+
triggerTags = { ...triggerTags, ...extractHTTPTags(event) }
|
|
298
|
+
} catch {
|
|
299
|
+
log.debug('failed to extract http tags from %s event', eventSource)
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return triggerTags
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* extractHTTPStatusCode extracts a status code from the response if the Lambda was triggered
|
|
307
|
+
* by API Gateway, ALB, or Lambda Function URL
|
|
308
|
+
*
|
|
309
|
+
* @param {Record<string, string> | undefined} triggerTags
|
|
310
|
+
* @param {{ statusCode?: string | number } | null | undefined} result
|
|
311
|
+
* @param {boolean} isResponseStreamFunction
|
|
312
|
+
*/
|
|
313
|
+
function extractHTTPStatusCodeTag (triggerTags, result, isResponseStreamFunction) {
|
|
314
|
+
const eventSource = triggerTags?.['function_trigger.event_source']
|
|
315
|
+
if (!isHTTPTriggerEvent(eventSource)) {
|
|
316
|
+
return
|
|
317
|
+
}
|
|
318
|
+
const resultStatusCode = result?.statusCode
|
|
319
|
+
// Return a 502 status if no response is found in
|
|
320
|
+
// any buffered function. Streaming functions returning
|
|
321
|
+
// undefined results will be marked as 200.
|
|
322
|
+
if (result === undefined && !isResponseStreamFunction) {
|
|
323
|
+
return '502'
|
|
324
|
+
} else if (resultStatusCode) {
|
|
325
|
+
return resultStatusCode.toString()
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return '200'
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
module.exports = {
|
|
332
|
+
eventTypes,
|
|
333
|
+
eventSubTypes,
|
|
334
|
+
parseEventSourceSubtype,
|
|
335
|
+
parseEventSource,
|
|
336
|
+
parseEventSourceARN,
|
|
337
|
+
extractTriggerTags,
|
|
338
|
+
extractHTTPStatusCodeTag,
|
|
339
|
+
}
|
|
@@ -5,6 +5,10 @@ const log = require('../../../dd-trace/src/log')
|
|
|
5
5
|
const { DYNAMODB_PTR_KIND, SPAN_POINTER_DIRECTION } = require('../../../dd-trace/src/constants')
|
|
6
6
|
const { extractPrimaryKeys, generatePointerHash } = require('../util')
|
|
7
7
|
|
|
8
|
+
// Requests may name the table by ARN, which cross-account access requires:
|
|
9
|
+
// arn:<partition>:dynamodb:<region>:<account>:table/<name>
|
|
10
|
+
const TABLE_ARN = /^arn:[^:]+:dynamodb:[^:]+:[^:]+:table\/[^/]+$/
|
|
11
|
+
|
|
8
12
|
class DynamoDb extends BaseAwsSdkPlugin {
|
|
9
13
|
static id = 'dynamodb'
|
|
10
14
|
static peerServicePrecursors = ['tablename']
|
|
@@ -31,6 +35,9 @@ class DynamoDb extends BaseAwsSdkPlugin {
|
|
|
31
35
|
tags['resource.name'] = `${operation} ${tableName}`
|
|
32
36
|
tags['aws.dynamodb.table_name'] = tableName
|
|
33
37
|
tags.tablename = tableName
|
|
38
|
+
if (TABLE_ARN.test(tableName)) {
|
|
39
|
+
tags['aws.table.arn'] = tableName
|
|
40
|
+
}
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
// TODO: DynamoDB.DocumentClient does batches on multiple tables
|