dd-trace 5.135.0 → 5.136.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ci/init.js +2 -22
- package/ext/exporters.js +0 -1
- package/index.d.ts +105 -5
- package/initialize.mjs +5 -2
- package/lambda.d.ts +39 -0
- package/lambda.js +3 -0
- package/package.json +11 -9
- package/packages/datadog-esbuild/index.js +8 -55
- package/packages/datadog-instrumentations/src/aws-lambda.js +88 -0
- package/packages/datadog-instrumentations/src/cucumber.js +5 -2
- 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-esbuild/src/utils.js → datadog-instrumentations/src/helpers/bundler-esm-exports.js} +282 -40
- package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +573 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-utils.js +104 -0
- package/packages/datadog-instrumentations/src/helpers/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 +2 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +18 -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/next.js +40 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/openai-agents-realtime.js +23 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/trpc.js +148 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +50 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +17 -3
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms.js +59 -2
- package/packages/datadog-instrumentations/src/ioredis.js +101 -3
- package/packages/datadog-instrumentations/src/next.js +19 -6
- package/packages/datadog-instrumentations/src/openai-agents-realtime.js +149 -0
- package/packages/datadog-instrumentations/src/openai-realtime/audio-accumulator.js +27 -0
- package/packages/datadog-instrumentations/src/openai-realtime/index.js +17 -6
- package/packages/datadog-instrumentations/src/openai-realtime/server-playback.js +887 -0
- package/packages/datadog-instrumentations/src/openai-realtime/session.js +150 -25
- package/packages/datadog-instrumentations/src/openai-realtime/turns.js +29 -2
- package/packages/datadog-instrumentations/src/otel-sdk-trace.js +11 -9
- package/packages/datadog-instrumentations/src/webdriverio.js +12 -12
- package/packages/datadog-plugin-async-mutex/src/index.js +50 -0
- package/packages/datadog-plugin-aws-lambda/src/index.js +106 -0
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +22 -11
- package/packages/datadog-plugin-elevenlabs/src/index.js +69 -0
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -7
- package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +19 -52
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +4 -2
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-request-context.js +25 -4
- package/packages/datadog-plugin-http/src/client.js +32 -9
- package/packages/datadog-plugin-http2/src/client.js +38 -13
- package/packages/datadog-plugin-next/src/index.js +112 -14
- package/packages/datadog-plugin-prisma/src/datadog-tracing-helper.js +5 -3
- 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-turbopack/index.js +4 -28
- package/packages/datadog-turbopack/src/loader.js +14 -452
- package/packages/datadog-webpack/index.js +3 -55
- package/packages/dd-trace/src/aiguard/evaluation.js +62 -1
- 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 +4 -0
- package/packages/dd-trace/src/appsec/graphql.js +91 -6
- package/packages/dd-trace/src/appsec/recommended.json +1287 -90
- package/packages/dd-trace/src/before-exit.js +32 -0
- package/packages/dd-trace/src/bootstrap.js +5 -3
- package/packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js +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 +42 -2
- package/packages/dd-trace/src/config/index.js +17 -5
- package/packages/dd-trace/src/config/parsers.js +9 -0
- package/packages/dd-trace/src/config/supported-configurations.json +158 -4
- package/packages/dd-trace/src/constants.js +1 -0
- package/packages/dd-trace/src/debugger/pause-duration-histogram.js +2 -1
- package/packages/dd-trace/src/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/id.js +1 -1
- package/packages/dd-trace/src/lambda/facade.js +74 -0
- package/packages/dd-trace/src/lambda/handler.js +3 -41
- package/packages/dd-trace/src/lambda/index.js +38 -15
- package/packages/dd-trace/src/lambda/runtime/patch.js +19 -3
- package/packages/dd-trace/src/lambda/wrap.js +44 -0
- package/packages/dd-trace/src/llmobs/constants/tags.js +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/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 +4 -0
- package/packages/dd-trace/src/openfeature/configuration_source.js +35 -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 +41 -10
- package/packages/dd-trace/src/plugins/index.js +6 -0
- package/packages/dd-trace/src/plugins/plugin.js +4 -2
- package/packages/dd-trace/src/plugins/tracing.js +1 -1
- package/packages/dd-trace/src/plugins/util/ci.js +18 -1
- package/packages/dd-trace/src/plugins/util/git-cache.js +4 -4
- package/packages/dd-trace/src/plugins/util/git.js +263 -82
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +75 -46
- 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 +64 -39
- package/packages/dd-trace/src/plugins/util/url.js +10 -2
- package/packages/dd-trace/src/plugins/util/user-provided-git.js +2 -2
- package/packages/dd-trace/src/plugins/util/web.js +65 -10
- package/packages/dd-trace/src/profiling/webspan-utils.js +6 -5
- package/packages/dd-trace/src/proxy.js +33 -53
- 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 +209 -1
- package/vendor/dist/crypto-randomuuid/LICENSE +3 -0
- package/vendor/dist/escape-string-regexp/LICENSE +13 -0
- package/vendor/dist/esquery/LICENSE +2 -0
- package/vendor/dist/https-proxy-agent/LICENSE +80 -1
- package/vendor/dist/istanbul-lib-coverage/LICENSE +2 -0
- package/vendor/dist/jest-docblock/LICENSE +16 -0
- package/vendor/dist/jsonpath-plus/LICENSE +13 -0
- package/vendor/dist/limiter/LICENSE +2 -0
- package/vendor/dist/lodash.sortby/LICENSE +2 -0
- package/vendor/dist/lru-cache/LICENSE +13 -0
- package/vendor/dist/meriyah/LICENSE +13 -0
- package/vendor/dist/module-details-from-path/LICENSE +2 -0
- package/vendor/dist/mutexify/promise/LICENSE +28 -0
- package/vendor/dist/pprof-format/LICENSE +13 -0
- package/vendor/dist/pprof-format/index.js +1 -1
- package/vendor/dist/protobufjs/LICENSE +219 -0
- package/vendor/dist/protobufjs/minimal/LICENSE +219 -0
- package/vendor/dist/proxy-from-env/LICENSE +13 -0
- package/vendor/dist/retry/LICENSE +2 -0
- package/vendor/dist/rfdc/LICENSE +2 -0
- package/vendor/dist/semifies/LICENSE +3 -1
- package/vendor/dist/shell-quote/LICENSE +3 -1
- package/vendor/dist/source-map/LICENSE +1 -0
- package/vendor/dist/source-map/lib/util/LICENSE +1 -0
- package/vendor/dist/tlhunter-sorted-set/LICENSE +2 -0
- package/vendor/dist/ttl-set/LICENSE +28 -0
- package/ci/diagnose.js +0 -2215
- package/ci/runbook.md +0 -299
- package/ci/test-optimization-validation/approval-artifacts.js +0 -175
- package/ci/test-optimization-validation/approval.js +0 -386
- package/ci/test-optimization-validation/artifact-id.js +0 -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/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
|
@@ -29,42 +29,84 @@ const maxActiveBufferSize = 1024 * 1024 * 64
|
|
|
29
29
|
let activeBufferSize = 0
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* @
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
32
|
+
* @typedef {Omit<import('node:http').RequestOptions, 'agent'> & {
|
|
33
|
+
* agent?: import('node:http').Agent|false,
|
|
34
|
+
* url?: string|URL|object,
|
|
35
|
+
* retry?: boolean,
|
|
36
|
+
* deferTimeoutAbort?: boolean,
|
|
37
|
+
* keepProcessAlive?: boolean,
|
|
38
|
+
* includeErrorResponseBody?: boolean
|
|
39
|
+
* }} RequestOptions
|
|
36
40
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param {RequestOptions} options
|
|
44
|
+
* @param {number} contentLength
|
|
45
|
+
* @returns {RequestOptions}
|
|
46
|
+
*/
|
|
47
|
+
function prepareRequestOptions (options, contentLength) {
|
|
48
|
+
const connectionOptions = { ...options }
|
|
41
49
|
|
|
42
50
|
if (options.url) {
|
|
43
51
|
const url = parseUrl(options.url)
|
|
44
52
|
if (url.protocol === 'unix:') {
|
|
45
|
-
options.
|
|
53
|
+
if (options.protocol !== undefined) connectionOptions.protocol = undefined
|
|
54
|
+
if (options.hostname !== undefined) connectionOptions.hostname = undefined
|
|
55
|
+
if (options.host !== undefined) connectionOptions.host = undefined
|
|
56
|
+
if (options.port !== undefined) connectionOptions.port = undefined
|
|
57
|
+
connectionOptions.socketPath = url.pathname
|
|
46
58
|
} else {
|
|
47
|
-
if (
|
|
48
|
-
options.
|
|
49
|
-
|
|
50
|
-
|
|
59
|
+
if (options.socketPath !== undefined) connectionOptions.socketPath = undefined
|
|
60
|
+
if (options.host !== undefined) connectionOptions.host = undefined
|
|
61
|
+
connectionOptions.protocol = url.protocol
|
|
62
|
+
connectionOptions.hostname = url.hostname
|
|
63
|
+
connectionOptions.port = url.port
|
|
64
|
+
if (!options.path) connectionOptions.path = url.path
|
|
51
65
|
}
|
|
52
66
|
}
|
|
67
|
+
if (connectionOptions.protocol !== undefined &&
|
|
68
|
+
connectionOptions.protocol !== 'http:' &&
|
|
69
|
+
connectionOptions.protocol !== 'https:') {
|
|
70
|
+
throw Object.assign(
|
|
71
|
+
new TypeError(`Unsupported request protocol: ${connectionOptions.protocol}`),
|
|
72
|
+
{ code: 'ERR_INVALID_PROTOCOL' }
|
|
73
|
+
)
|
|
74
|
+
}
|
|
53
75
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
76
|
+
const sourceHeaders = options.headers ?? {}
|
|
77
|
+
const headers = { ...sourceHeaders }
|
|
78
|
+
const isSecure = connectionOptions.protocol === 'https:'
|
|
79
|
+
const hasApiKey = sourceHeaders['dd-api-key'] !== undefined || sourceHeaders['DD-API-KEY'] !== undefined
|
|
80
|
+
|
|
81
|
+
// Local agents proxy with their own key. Strip unsafe keys instead of dropping the request.
|
|
82
|
+
if (hasApiKey && !canSendApiKey(connectionOptions.protocol, connectionOptions.hostname)) {
|
|
60
83
|
log.error(
|
|
61
84
|
'Not sending the Datadog API key over a non-TLS connection to %s. Configure an https intake URL.',
|
|
62
|
-
|
|
85
|
+
connectionOptions.hostname
|
|
63
86
|
)
|
|
64
|
-
delete
|
|
65
|
-
delete
|
|
87
|
+
delete headers['dd-api-key']
|
|
88
|
+
delete headers['DD-API-KEY']
|
|
66
89
|
}
|
|
67
90
|
|
|
91
|
+
headers['Content-Length'] = contentLength
|
|
92
|
+
docker.inject(headers)
|
|
93
|
+
connectionOptions.headers = headers
|
|
94
|
+
|
|
95
|
+
const directAgent = options.agent ?? (isSecure ? httpsAgent : httpAgent)
|
|
96
|
+
connectionOptions.agent = hasApiKey && isSecure
|
|
97
|
+
? getHttpsProxyAgent(connectionOptions, directAgent)
|
|
98
|
+
: directAgent
|
|
99
|
+
|
|
100
|
+
return connectionOptions
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @param {Buffer|string|Readable|Array<Buffer|string>} data
|
|
105
|
+
* @param {RequestOptions} options
|
|
106
|
+
* @param {(error: Error|null, result?: string|null, statusCode?: number,
|
|
107
|
+
* headers?: import('node:http').IncomingHttpHeaders, dropped?: boolean) => void} callback
|
|
108
|
+
*/
|
|
109
|
+
function request (data, options, callback) {
|
|
68
110
|
if (data instanceof Readable) {
|
|
69
111
|
const chunks = []
|
|
70
112
|
|
|
@@ -84,25 +126,16 @@ function request (data, options, callback) {
|
|
|
84
126
|
|
|
85
127
|
// The timeout should be kept low to avoid excessive queueing.
|
|
86
128
|
const timeout = options.timeout || 2000
|
|
87
|
-
const isSecure = options.protocol === 'https:'
|
|
88
|
-
const client = isSecure ? https : http
|
|
89
129
|
const dataArray = Array.isArray(data) ? data : [data]
|
|
90
130
|
const contentLength = byteLength(dataArray)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
agent = getHttpsProxyAgent(options, agent)
|
|
99
|
-
} catch (error) {
|
|
100
|
-
callback(error)
|
|
101
|
-
return
|
|
102
|
-
}
|
|
131
|
+
let connectionOptions
|
|
132
|
+
try {
|
|
133
|
+
connectionOptions = prepareRequestOptions(options, contentLength)
|
|
134
|
+
} catch (error) {
|
|
135
|
+
callback(error)
|
|
136
|
+
return
|
|
103
137
|
}
|
|
104
|
-
|
|
105
|
-
const connectionOptions = { ...options, agent }
|
|
138
|
+
const client = connectionOptions.protocol === 'https:' ? https : http
|
|
106
139
|
|
|
107
140
|
/**
|
|
108
141
|
* @param {import('node:http').IncomingMessage} res
|
|
@@ -111,7 +144,7 @@ function request (data, options, callback) {
|
|
|
111
144
|
* @param {(error: Error) => void} handleError
|
|
112
145
|
*/
|
|
113
146
|
const onResponse = (res, complete, handleError) => {
|
|
114
|
-
markEndpointReached(
|
|
147
|
+
markEndpointReached(connectionOptions)
|
|
115
148
|
|
|
116
149
|
const chunks = []
|
|
117
150
|
|
|
@@ -153,8 +186,8 @@ function request (data, options, callback) {
|
|
|
153
186
|
let errorMessage = ''
|
|
154
187
|
try {
|
|
155
188
|
const fullUrl = new URL(
|
|
156
|
-
|
|
157
|
-
|
|
189
|
+
String(connectionOptions.path),
|
|
190
|
+
connectionOptions.url || connectionOptions.hostname || `http://localhost:${connectionOptions.port}`
|
|
158
191
|
).href
|
|
159
192
|
errorMessage = `Error from ${fullUrl}: ${res.statusCode} ${http.STATUS_CODES[res.statusCode]}.`
|
|
160
193
|
} catch {
|
|
@@ -219,15 +252,15 @@ function request (data, options, callback) {
|
|
|
219
252
|
if (settled) return
|
|
220
253
|
clearImmediate(timeoutImmediate)
|
|
221
254
|
|
|
222
|
-
if (
|
|
223
|
-
attemptIndex < getMaxAttempts(
|
|
255
|
+
if (connectionOptions.retry !== false &&
|
|
256
|
+
attemptIndex < getMaxAttempts(connectionOptions) &&
|
|
224
257
|
isRetriableNetworkError(error)) {
|
|
225
258
|
settled = true
|
|
226
259
|
finalize()
|
|
227
|
-
const retryTimer = setTimeout(attempt, getRetryDelay(
|
|
260
|
+
const retryTimer = setTimeout(attempt, getRetryDelay(connectionOptions, attemptIndex), attemptIndex + 1)
|
|
228
261
|
// Background retries must not keep the host process alive. Lifecycle-owned
|
|
229
262
|
// requests can opt in when their final result must be observed.
|
|
230
|
-
if (!
|
|
263
|
+
if (!connectionOptions.keepProcessAlive) retryTimer.unref?.()
|
|
231
264
|
} else {
|
|
232
265
|
complete(error)
|
|
233
266
|
}
|
|
@@ -236,7 +269,7 @@ function request (data, options, callback) {
|
|
|
236
269
|
const req = client.request(connectionOptions, (res) => onResponse(res, complete, handleError))
|
|
237
270
|
|
|
238
271
|
req.once('close', finalize)
|
|
239
|
-
if (!
|
|
272
|
+
if (!connectionOptions.deferTimeoutAbort) req.once('timeout', finalize)
|
|
240
273
|
req.once('error', handleError)
|
|
241
274
|
|
|
242
275
|
const abortRequest = () => {
|
|
@@ -253,7 +286,7 @@ function request (data, options, callback) {
|
|
|
253
286
|
}
|
|
254
287
|
|
|
255
288
|
req.setTimeout(timeout, () => {
|
|
256
|
-
if (!
|
|
289
|
+
if (!connectionOptions.deferTimeoutAbort) {
|
|
257
290
|
abortRequest()
|
|
258
291
|
return
|
|
259
292
|
}
|
|
@@ -262,7 +295,7 @@ function request (data, options, callback) {
|
|
|
262
295
|
abortRequest()
|
|
263
296
|
finalize()
|
|
264
297
|
})
|
|
265
|
-
if (!
|
|
298
|
+
if (!connectionOptions.keepProcessAlive) timeoutImmediate.unref?.()
|
|
266
299
|
})
|
|
267
300
|
|
|
268
301
|
for (const buffer of dataArray) req.write(buffer)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { parseUrl } = require('./url')
|
|
4
|
+
|
|
3
5
|
const RATE_LIMIT_MAX_WAIT_MS = 30_000
|
|
4
6
|
|
|
5
7
|
const SINGLE_RETRY_BASE_MS = 5000
|
|
@@ -29,10 +31,11 @@ const reachedEndpoints = new Set()
|
|
|
29
31
|
|
|
30
32
|
/**
|
|
31
33
|
* @typedef {object} EndpointOptions
|
|
32
|
-
* @property {string} [
|
|
33
|
-
* @property {string} [
|
|
34
|
-
* @property {string} [
|
|
35
|
-
* @property {string|
|
|
34
|
+
* @property {string|URL|object} [url]
|
|
35
|
+
* @property {string|null} [socketPath]
|
|
36
|
+
* @property {string|null} [hostname]
|
|
37
|
+
* @property {string|null} [host]
|
|
38
|
+
* @property {string|number|null} [port]
|
|
36
39
|
*/
|
|
37
40
|
|
|
38
41
|
/**
|
|
@@ -47,9 +50,7 @@ function singleJitteredDelay () {
|
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
/**
|
|
50
|
-
* Stable
|
|
51
|
-
* per endpoint. UDS path beats host:port because both can coexist on the same
|
|
52
|
-
* options object after `parseUrl` runs.
|
|
53
|
+
* Stable destination key for prepared transport options.
|
|
53
54
|
*
|
|
54
55
|
* @param {EndpointOptions} options
|
|
55
56
|
*/
|
|
@@ -63,6 +64,10 @@ function getEndpointKey (options) {
|
|
|
63
64
|
*/
|
|
64
65
|
function inStartupPhase (options) {
|
|
65
66
|
if ((Date.now() - startedAtMs) >= STARTUP_GRACE_MS) return false
|
|
67
|
+
if (options.url) {
|
|
68
|
+
const url = parseUrl(options.url)
|
|
69
|
+
return !reachedEndpoints.has(url.protocol === 'unix:' ? url.pathname : getEndpointKey(url))
|
|
70
|
+
}
|
|
66
71
|
return !reachedEndpoints.has(getEndpointKey(options))
|
|
67
72
|
}
|
|
68
73
|
|
|
@@ -21,7 +21,7 @@ function isLoopbackHost (hostname) {
|
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* @param {string|undefined} protocol
|
|
24
|
-
* @param {string|undefined} hostname
|
|
24
|
+
* @param {string|undefined|null} hostname
|
|
25
25
|
*/
|
|
26
26
|
function canSendApiKey (protocol, hostname) {
|
|
27
27
|
return protocol === 'https:' || protocol === 'unix:' ||
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const tracer = require('../../../..')
|
|
4
|
+
const { AUTO_KEEP } = require('../../../../ext/priority')
|
|
5
|
+
const { writeDatadogTraceId, writeDatadogParentId, writeDatadogSamplingPriority } = require('../carrier')
|
|
6
|
+
const { wrapLambdaHandler } = require('./wrap')
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Returns Datadog propagation headers for the active Lambda invocation span.
|
|
10
|
+
*
|
|
11
|
+
* @returns {Record<string, string>} Trace propagation headers, or an empty object outside an invocation.
|
|
12
|
+
*/
|
|
13
|
+
function getTraceHeaders () {
|
|
14
|
+
const span = tracer.scope().active()
|
|
15
|
+
if (!span) return {}
|
|
16
|
+
|
|
17
|
+
// Ported from datadog-lambda-js's TraceContextService.currentTraceHeaders and
|
|
18
|
+
// SpanContextWrapper.sampleMode. This fixed Datadog carrier must not depend on the configured
|
|
19
|
+
// injection styles or force a sampling decision as tracer.inject() does.
|
|
20
|
+
const context = span.context()
|
|
21
|
+
const headers = {}
|
|
22
|
+
writeDatadogTraceId(headers, context.toTraceId())
|
|
23
|
+
writeDatadogParentId(headers, context.toSpanId())
|
|
24
|
+
writeDatadogSamplingPriority(headers, String(context._sampling?.priority ?? AUTO_KEEP))
|
|
25
|
+
return headers
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Submits a custom Lambda distribution metric.
|
|
30
|
+
*/
|
|
31
|
+
function sendDistributionMetric () {
|
|
32
|
+
throw new Error(notImplemented('sendDistributionMetric'))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Submits a timestamped custom Lambda distribution metric.
|
|
37
|
+
*/
|
|
38
|
+
function sendDistributionMetricWithDate () {
|
|
39
|
+
throw new Error(notImplemented('sendDistributionMetricWithDate'))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Renders a handler-load failure (error span + error metric) for a failure the plugin lifecycle
|
|
44
|
+
* cannot observe: the customer module failed during evaluation, so there is no invocation.
|
|
45
|
+
*
|
|
46
|
+
* @param {{ error: Error, functionName: string, startTime: number }} failure Init failure details.
|
|
47
|
+
*/
|
|
48
|
+
function reportInitFailure (failure) {
|
|
49
|
+
throw new Error(notImplemented('reportInitFailure'))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Builds the message for a facade entry point whose implementation has not landed yet.
|
|
54
|
+
*
|
|
55
|
+
* The five-function surface is a cross-major contract, so the names are reserved from the first
|
|
56
|
+
* release of the facade. Throwing keeps the gap loud: a silent no-op here would drop customer
|
|
57
|
+
* metrics with no error anywhere, which is the failure mode this migration exists to avoid.
|
|
58
|
+
* The shim's integration lands only after these are implemented, so the throw never ships to a
|
|
59
|
+
* shim user.
|
|
60
|
+
*
|
|
61
|
+
* @param {string} name Facade entry point.
|
|
62
|
+
*/
|
|
63
|
+
function notImplemented (name) {
|
|
64
|
+
return `dd-trace/lambda ${name}() is not implemented yet: Lambda metrics land with the metrics ` +
|
|
65
|
+
'pipeline (migration PR 12). Keep using datadog-lambda-js for custom metrics until then.'
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = {
|
|
69
|
+
getTraceHeaders,
|
|
70
|
+
reportInitFailure,
|
|
71
|
+
sendDistributionMetric,
|
|
72
|
+
sendDistributionMetricWithDate,
|
|
73
|
+
wrap: wrapLambdaHandler,
|
|
74
|
+
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { types: { isProxy } } = require('node:util')
|
|
4
|
-
|
|
5
3
|
const { channel } = require('../../../datadog-instrumentations/src/helpers/instrument')
|
|
4
|
+
const { copyHandlerMetadata, getDataProperty } =
|
|
5
|
+
require('../../../datadog-instrumentations/src/helpers/lambda-handler')
|
|
6
6
|
const { ERROR_MESSAGE, ERROR_TYPE } = require('../constants')
|
|
7
7
|
const log = require('../log')
|
|
8
8
|
const { ImpendingTimeout } = require('./runtime/errors')
|
|
9
9
|
const { extractContext } = require('./context')
|
|
10
10
|
|
|
11
|
-
const HANDLER_STREAMING = Symbol.for('aws.lambda.runtime.handler.streaming')
|
|
12
|
-
const HANDLER_HIGHWATERMARK = Symbol.for('aws.lambda.runtime.handler.streaming.highWaterMark')
|
|
13
11
|
const BEFORE_EXIT = Symbol.for('aws.lambda.beforeExit')
|
|
14
12
|
const timeoutChannel = channel('apm:aws:lambda:timeout')
|
|
15
13
|
const monitoredContexts = new WeakSet()
|
|
@@ -171,28 +169,7 @@ exports.datadog = function datadog (lambdaHandler, normalized = false) {
|
|
|
171
169
|
|
|
172
170
|
if (normalized) return monitored
|
|
173
171
|
|
|
174
|
-
|
|
175
|
-
Object.defineProperty(monitored, 'length', { value: getDataProperty(lambdaHandler, 'length') ?? 0 })
|
|
176
|
-
for (const name of [HANDLER_STREAMING, HANDLER_HIGHWATERMARK, '_ddWrapped']) {
|
|
177
|
-
const value = getDataProperty(lambdaHandler, name)
|
|
178
|
-
if (value !== undefined) monitored[name] = value
|
|
179
|
-
}
|
|
180
|
-
if (!isProxy(lambdaHandler)) {
|
|
181
|
-
for (const name of Reflect.ownKeys(lambdaHandler)) {
|
|
182
|
-
if (name === 'arguments' || name === 'caller') continue
|
|
183
|
-
const descriptor = Object.getOwnPropertyDescriptor(lambdaHandler, name)
|
|
184
|
-
if (!Object.hasOwn(descriptor, 'value')) continue
|
|
185
|
-
const existing = Object.getOwnPropertyDescriptor(monitored, name)
|
|
186
|
-
if (existing?.configurable === false) {
|
|
187
|
-
// Intrinsic function slots such as prototype cannot change their descriptor shape.
|
|
188
|
-
if (existing.writable) {
|
|
189
|
-
Object.defineProperty(monitored, name, { value: descriptor.value, writable: descriptor.writable })
|
|
190
|
-
}
|
|
191
|
-
} else {
|
|
192
|
-
Object.defineProperty(monitored, name, descriptor)
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
172
|
+
copyHandlerMetadata(lambdaHandler, monitored)
|
|
196
173
|
return monitored
|
|
197
174
|
}
|
|
198
175
|
|
|
@@ -226,18 +203,3 @@ function onCompletion (callback, clear) {
|
|
|
226
203
|
return Reflect.apply(callback, this, args)
|
|
227
204
|
}
|
|
228
205
|
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Reads metadata without executing application getters or Proxy traps.
|
|
232
|
-
*
|
|
233
|
-
* @param {unknown} target
|
|
234
|
-
* @param {string | symbol} name
|
|
235
|
-
*/
|
|
236
|
-
function getDataProperty (target, name) {
|
|
237
|
-
if (target === null || (typeof target !== 'object' && typeof target !== 'function')) return
|
|
238
|
-
while (target !== null && !isProxy(target)) {
|
|
239
|
-
const descriptor = Object.getOwnPropertyDescriptor(target, name)
|
|
240
|
-
if (descriptor) return descriptor.value
|
|
241
|
-
target = Object.getPrototypeOf(target)
|
|
242
|
-
}
|
|
243
|
-
}
|
|
@@ -1,22 +1,45 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const { channel } = require('dc-polyfill')
|
|
4
4
|
|
|
5
|
-
const log = require('../log')
|
|
6
5
|
const { getEnvironmentVariable, getValueFromEnvSources } = require('../config/helper')
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
|
|
7
|
+
const loadChannel = channel('dd-trace:instrumentation:load')
|
|
8
|
+
let initialized = false
|
|
9
|
+
|
|
10
|
+
// Called during tracer configuration so importing the facade early does not freeze Lambda detection.
|
|
11
|
+
module.exports = function initialize () {
|
|
12
|
+
if (initialized || getEnvironmentVariable('AWS_LAMBDA_FUNCTION_NAME') === undefined ||
|
|
13
|
+
isDisabled(getValueFromEnvSources('DD_TRACE_DISABLED_INSTRUMENTATIONS'))) return
|
|
14
|
+
|
|
15
|
+
registerHooks()
|
|
16
|
+
initialized = true
|
|
17
|
+
|
|
18
|
+
// Plugin disabling must leave the legacy shim's timeout hooks active. Handle the legacy alias
|
|
19
|
+
// here without changing the plugin manager's disabled-plugin registry.
|
|
20
|
+
if (!isDisabled(getValueFromEnvSources('DD_TRACE_DISABLED_PLUGINS'))) {
|
|
21
|
+
loadChannel.publish({ name: 'aws-lambda' })
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** @param {string | undefined} value Disabled integration names. */
|
|
26
|
+
function isDisabled (value) {
|
|
27
|
+
return value?.split(',').some(name => ['lambda', 'aws-lambda'].includes(name.trim())) ?? false
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function registerHooks () {
|
|
31
|
+
// Keep handler-loading dependencies lazy outside Lambda and when instrumentation is disabled.
|
|
32
|
+
const path = require('node:path')
|
|
33
|
+
|
|
34
|
+
const Hook = require('../../../datadog-instrumentations/src/helpers/hook')
|
|
35
|
+
const instrumentations = require('../../../datadog-instrumentations/src/helpers/instrumentations')
|
|
36
|
+
const { filename, pathSepExpr } = require('../../../datadog-instrumentations/src/helpers/register')
|
|
37
|
+
const log = require('../log')
|
|
38
|
+
const {
|
|
39
|
+
extractModuleNameAndHandlerPath,
|
|
40
|
+
extractModuleRootAndHandler,
|
|
41
|
+
getLambdaFilePaths,
|
|
42
|
+
} = require('./handler-paths')
|
|
20
43
|
const lambdaTaskRoot = getEnvironmentVariable('LAMBDA_TASK_ROOT')
|
|
21
44
|
const originalLambdaHandler = getValueFromEnvSources('DD_LAMBDA_HANDLER')
|
|
22
45
|
|
|
@@ -4,6 +4,7 @@ const path = require('path')
|
|
|
4
4
|
const { types: { isModuleNamespaceObject } } = require('node:util')
|
|
5
5
|
|
|
6
6
|
const { datadog } = require('../handler')
|
|
7
|
+
const { withTimeoutMonitor } = require('../wrap')
|
|
7
8
|
const { addHook } = require('../../../../datadog-instrumentations/src/helpers/instrument')
|
|
8
9
|
const shimmer = require('../../../../datadog-shimmer')
|
|
9
10
|
const { getEnvironmentVariable, getValueFromEnvSources } = require('../../config/helper')
|
|
@@ -21,7 +22,9 @@ function patchDatadogLambdaModule (datadogLambdaModule) {
|
|
|
21
22
|
|
|
22
23
|
/** @param {Function} datadogHandler */
|
|
23
24
|
function patchDatadogLambdaHandler (datadogHandler) {
|
|
24
|
-
return
|
|
25
|
+
return function (userHandler, ...args) {
|
|
26
|
+
return Reflect.apply(datadogHandler, this, [instrumentLambdaHandler(userHandler, args[0]), ...args])
|
|
27
|
+
}
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
/**
|
|
@@ -46,7 +49,7 @@ function patchLambdaModule (handlerPath) {
|
|
|
46
49
|
if (!descriptor.configurable && !descriptor.writable) return lambdaModule
|
|
47
50
|
// The monitor copies Lambda metadata without invoking application accessors or Proxy traps.
|
|
48
51
|
// Generic shimmer wrapping would copy the original properties back onto that safe wrapper.
|
|
49
|
-
descriptor.value =
|
|
52
|
+
descriptor.value = instrumentLambdaHandler(descriptor.value)
|
|
50
53
|
// Native ESM namespaces reject replacement even when their export reports writable: true.
|
|
51
54
|
const exports = isModuleNamespaceObject(lambdaModule)
|
|
52
55
|
? Object.create(lambdaModule, Object.getOwnPropertyDescriptors(lambdaModule))
|
|
@@ -54,10 +57,23 @@ function patchLambdaModule (handlerPath) {
|
|
|
54
57
|
Object.defineProperty(exports, handlerPath, descriptor)
|
|
55
58
|
return exports
|
|
56
59
|
}
|
|
57
|
-
return shimmer.wrap(lambdaModule, handlerPath,
|
|
60
|
+
return shimmer.wrap(lambdaModule, handlerPath, instrumentLambdaHandler)
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Only internal migration builds may delegate invocation-span ownership from the final shim.
|
|
66
|
+
* Old shims retain timeout monitoring, including their selected-completion helper hooks.
|
|
67
|
+
* Explicit facade wrapping is opt-in and independent of the automatic hooks.
|
|
68
|
+
*
|
|
69
|
+
* @param {Function} handler Customer handler.
|
|
70
|
+
* @param {Record<string, unknown>} [config] Per-handler overrides.
|
|
71
|
+
* @returns {Function} Monitored or invocation-wrapped handler.
|
|
72
|
+
*/
|
|
73
|
+
function instrumentLambdaHandler (handler, config) {
|
|
74
|
+
return withTimeoutMonitor(handler) // Import and return `wrapLambdaHandler(handler, config)` for migration testing.
|
|
75
|
+
}
|
|
76
|
+
|
|
61
77
|
const lambdaTaskRoot = getEnvironmentVariable('LAMBDA_TASK_ROOT')
|
|
62
78
|
const originalLambdaHandler = getValueFromEnvSources('DD_LAMBDA_HANDLER')
|
|
63
79
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { getWrappedHandler, wrapHandler } = require('../../../datadog-instrumentations/src/aws-lambda')
|
|
4
|
+
const { datadog: monitor } = require('./handler')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Reuses a raw timeout monitor, or its invocation wrapper after facade promotion.
|
|
8
|
+
*
|
|
9
|
+
* @param {Function} handler Customer handler.
|
|
10
|
+
* @returns {Function} Monitored handler.
|
|
11
|
+
*/
|
|
12
|
+
function withTimeoutMonitor (handler) {
|
|
13
|
+
if (typeof handler !== 'function') throw new TypeError('AWS Lambda handler must be a function')
|
|
14
|
+
// Share handler identity across tracer copies without modifying customer functions.
|
|
15
|
+
const ddGlobal = globalThis[Symbol.for('dd-trace')] ??= { beforeExitHandlers: new Set() }
|
|
16
|
+
const lambda = ddGlobal.lambda ??= {}
|
|
17
|
+
const monitors = lambda.monitors ??= new WeakMap()
|
|
18
|
+
const originals = lambda.originals ??= new WeakMap()
|
|
19
|
+
const original = originals.get(handler) || handler
|
|
20
|
+
const wrapped = getWrappedHandler(original)
|
|
21
|
+
if (wrapped) return wrapped
|
|
22
|
+
const existing = monitors.get(original)
|
|
23
|
+
if (existing) return existing
|
|
24
|
+
const monitored = monitor(original)
|
|
25
|
+
monitors.set(original, monitored)
|
|
26
|
+
originals.set(monitored, original)
|
|
27
|
+
return monitored
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Composes invocation scope -> timeout monitor -> selected completion -> customer handler.
|
|
32
|
+
*
|
|
33
|
+
* @param {Function} handler Customer handler or a monitor-only hook wrapper.
|
|
34
|
+
* @param {Record<string, unknown>} [config] Per-handler overrides.
|
|
35
|
+
* @returns {Function} Instrumented handler.
|
|
36
|
+
*/
|
|
37
|
+
function wrapLambdaHandler (handler, config) {
|
|
38
|
+
// Normalize the original so a hook-first call has the same completion boundary as facade-first.
|
|
39
|
+
// forceWrap(raw) replaces its wrapper; explicitly force-wrapping a span wrapper still nests it.
|
|
40
|
+
const originals = globalThis[Symbol.for('dd-trace')]?.lambda?.originals
|
|
41
|
+
return wrapHandler(originals?.get(handler) || handler, config, monitor)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = { withTimeoutMonitor, wrapLambdaHandler }
|
|
@@ -17,6 +17,7 @@ module.exports = {
|
|
|
17
17
|
SPAN_KINDS: ['llm', 'agent', 'workflow', 'task', 'tool', 'embedding', 'retrieval', 'experiment'],
|
|
18
18
|
SPAN_KIND: '_ml_obs.meta.span.kind',
|
|
19
19
|
SESSION_ID: '_ml_obs.session_id',
|
|
20
|
+
EXPERIMENT_TAGS: '_ml_obs.experiment_tags',
|
|
20
21
|
SESSION_ID_TRACE_DEFAULT_KEY: '_ml_obs.trace_session_id',
|
|
21
22
|
DECORATOR: '_ml_obs.decorator',
|
|
22
23
|
INTEGRATION: '_ml_obs.integration',
|
|
@@ -63,6 +64,7 @@ module.exports = {
|
|
|
63
64
|
DEFAULT_MODEL: 'custom',
|
|
64
65
|
|
|
65
66
|
INPUT_DOCUMENTS: '_ml_obs.meta.input.documents',
|
|
67
|
+
EXPERIMENT_EXPECTED_OUTPUT: '_ml_obs.meta.expected_output',
|
|
66
68
|
EXPERIMENT_INPUT: '_ml_obs.meta.input',
|
|
67
69
|
INPUT_MESSAGES: '_ml_obs.meta.input.messages',
|
|
68
70
|
INPUT_VALUE: '_ml_obs.meta.input.value',
|
|
@@ -888,17 +888,19 @@ class Experiment {
|
|
|
888
888
|
let errorType = null
|
|
889
889
|
let errorMessage = null
|
|
890
890
|
|
|
891
|
-
|
|
891
|
+
// Inherited by every span the task creates, so the multi-run rollups count their tokens and cost.
|
|
892
|
+
// Same key set Python propagates; the record id stays on the experiment span only.
|
|
893
|
+
const experimentTags = {
|
|
892
894
|
experiment_id: experimentId,
|
|
893
895
|
run_id: runId,
|
|
894
896
|
run_iteration: runIteration,
|
|
895
897
|
project_id: projectId,
|
|
896
898
|
dataset_id: datasetId,
|
|
897
|
-
dataset_record_id: datasetRecordId,
|
|
898
899
|
dataset_name: this.#dataset.name(),
|
|
899
900
|
experiment_name: this.#name,
|
|
900
901
|
}
|
|
901
|
-
if (this.#projectName !== undefined)
|
|
902
|
+
if (this.#projectName !== undefined) experimentTags.project_name = this.#projectName
|
|
903
|
+
const autoTags = { ...experimentTags, dataset_record_id: datasetRecordId }
|
|
902
904
|
const tags = mergeTags(this.#tags, { ...recordTagsToObject(record.tags), ...autoTags })
|
|
903
905
|
|
|
904
906
|
const execute = () => this.#runWithRetries(
|
|
@@ -912,22 +914,25 @@ class Experiment {
|
|
|
912
914
|
await this.#llmobs.trace({
|
|
913
915
|
kind: 'experiment',
|
|
914
916
|
name: this.#task.name || this.#name,
|
|
917
|
+
_experimentTags: experimentTags,
|
|
915
918
|
}, async (span) => {
|
|
916
919
|
spanContext = this.#llmobs.exportSpan(span)
|
|
917
920
|
try {
|
|
918
921
|
output = await execute()
|
|
919
922
|
} catch (err) {
|
|
920
|
-
this.#llmobs.
|
|
923
|
+
this.#llmobs._annotateExperimentSpan(span, {
|
|
921
924
|
inputData: record.input,
|
|
922
925
|
outputData: output,
|
|
926
|
+
expectedOutput: record.expectedOutput,
|
|
923
927
|
metadata: buildSpanMetadata(record.metadata, this.#config),
|
|
924
928
|
tags,
|
|
925
929
|
})
|
|
926
930
|
throw err
|
|
927
931
|
}
|
|
928
|
-
this.#llmobs.
|
|
932
|
+
this.#llmobs._annotateExperimentSpan(span, {
|
|
929
933
|
inputData: record.input,
|
|
930
934
|
outputData: output,
|
|
935
|
+
expectedOutput: record.expectedOutput,
|
|
931
936
|
metadata: buildSpanMetadata(record.metadata, this.#config),
|
|
932
937
|
tags,
|
|
933
938
|
})
|