dd-trace 5.136.0 → 5.138.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/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/index.d.ts +56 -0
- package/initialize.mjs +5 -3
- package/package.json +36 -32
- package/packages/datadog-esbuild/index.js +8 -15
- package/packages/datadog-esbuild/src/log.js +2 -29
- package/packages/datadog-instrumentations/src/ai.js +88 -122
- package/packages/datadog-instrumentations/src/aws-lambda.js +9 -0
- package/packages/datadog-instrumentations/src/cypress-config.js +20 -9
- package/packages/datadog-instrumentations/src/helpers/bundler-esm-exports.js +23 -1
- package/packages/datadog-instrumentations/src/helpers/bundler-log.js +38 -0
- package/packages/datadog-instrumentations/src/helpers/bundler-transform.js +9 -6
- package/packages/datadog-instrumentations/src/helpers/fetch.js +51 -6
- package/packages/datadog-instrumentations/src/helpers/hooks.js +0 -1
- package/packages/datadog-instrumentations/src/helpers/instrument.js +1 -3
- package/packages/datadog-instrumentations/src/helpers/rewriter/index.js +6 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentation-registry.js +12 -1
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/ai.js +2 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/graphql-jit.js +5 -3
- 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 +21 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/postgres.js +33 -4
- package/packages/datadog-instrumentations/src/helpers/rewriter/target-patterns.json +30 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/targets.json +6 -0
- package/packages/datadog-instrumentations/src/helpers/rewriter/transforms/postgres.js +122 -0
- 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 +32 -2
- package/packages/datadog-instrumentations/src/modelcontextprotocol-server.js +43 -0
- package/packages/datadog-instrumentations/src/next.js +184 -20
- package/packages/datadog-instrumentations/src/path-to-regexp.js +11 -11
- package/packages/datadog-instrumentations/src/router.js +52 -13
- package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +1 -1
- package/packages/datadog-instrumentations/src/vitest-main.js +10 -2
- package/packages/datadog-plugin-aws-lambda/src/arn.js +41 -0
- package/packages/datadog-plugin-aws-lambda/src/context/events.js +167 -0
- package/packages/datadog-plugin-aws-lambda/src/context/extractor.js +153 -0
- package/packages/datadog-plugin-aws-lambda/src/context/http.js +50 -0
- package/packages/datadog-plugin-aws-lambda/src/context/span-context.js +26 -0
- package/packages/datadog-plugin-aws-lambda/src/context/step-functions.js +142 -0
- package/packages/datadog-plugin-aws-lambda/src/context/types.d.ts +17 -0
- package/packages/datadog-plugin-aws-lambda/src/context/xray.js +67 -0
- package/packages/datadog-plugin-aws-lambda/src/event-type-guards.js +170 -0
- package/packages/datadog-plugin-aws-lambda/src/index.js +52 -4
- 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-azure-functions/src/index.js +68 -12
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +30 -4
- package/packages/datadog-plugin-cypress/src/support.mjs +1353 -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-fetch/src/index.js +7 -0
- package/packages/datadog-plugin-google-cloud-pubsub/src/consumer.js +10 -0
- package/packages/datadog-plugin-google-cloud-pubsub/src/producer.js +2 -0
- package/packages/datadog-plugin-google-cloud-pubsub/src/pubsub-push-subscription.js +7 -0
- 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 +14 -1
- package/packages/datadog-plugin-http/src/server.js +18 -4
- package/packages/datadog-plugin-http2/src/client.js +2 -1
- 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-postgres/src/index.js +118 -41
- 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-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-vite/index.js +537 -0
- package/packages/datadog-vite/src/log.js +5 -0
- package/packages/datadog-webpack/src/log.js +2 -29
- package/packages/dd-trace/src/aiguard/client.js +7 -9
- package/packages/dd-trace/src/aiguard/evaluation.js +7 -2
- 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/messages/utils.js +2 -2
- package/packages/dd-trace/src/aiguard/sdk.js +7 -2
- package/packages/dd-trace/src/appsec/api_security/normalized-route.js +273 -167
- package/packages/dd-trace/src/appsec/blocking/index.js +17 -1
- package/packages/dd-trace/src/appsec/channels.js +8 -0
- package/packages/dd-trace/src/appsec/downstream_requests.js +105 -0
- package/packages/dd-trace/src/appsec/graphql.js +10 -13
- 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/iast/taint-tracking/plugin.js +21 -14
- package/packages/dd-trace/src/appsec/index.js +9 -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 +64 -3
- 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 +47 -3
- package/packages/dd-trace/src/appsec/recommended.json +70 -3
- 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/carrier.js +7 -1
- package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +4 -2
- package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +31 -19
- package/packages/dd-trace/src/config/generated-config-types.d.ts +14 -5
- package/packages/dd-trace/src/config/index.js +73 -27
- package/packages/dd-trace/src/config/parsers.js +60 -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 +41 -13
- package/packages/dd-trace/src/datastreams/fnv.js +27 -0
- package/packages/dd-trace/src/datastreams/http.js +57 -0
- package/packages/dd-trace/src/datastreams/index.js +24 -0
- package/packages/dd-trace/src/datastreams/pathway.js +142 -28
- package/packages/dd-trace/src/datastreams/processor.js +27 -7
- 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 +4 -1
- 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/git_metadata.js +2 -1
- package/packages/dd-trace/src/index.js +6 -3
- package/packages/dd-trace/src/lambda/facade.js +6 -5
- package/packages/dd-trace/src/lambda/handler-paths.js +1 -1
- package/packages/dd-trace/src/llmobs/constants/tags.js +1 -0
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/index.js +86 -3
- package/packages/dd-trace/src/llmobs/plugins/modelcontextprotocol-sdk/utils.js +182 -1
- package/packages/dd-trace/src/llmobs/span_processor.js +3 -0
- package/packages/dd-trace/src/llmobs/tagger.js +9 -0
- package/packages/dd-trace/src/noop/span.js +0 -4
- package/packages/dd-trace/src/openfeature/agentless_configuration_source.js +3 -0
- package/packages/dd-trace/src/openfeature/configuration_source.js +20 -0
- package/packages/dd-trace/src/openfeature/flagging_provider.js +17 -0
- package/packages/dd-trace/src/opentelemetry/logs/otlp_transformer.js +2 -1
- package/packages/dd-trace/src/opentelemetry/metrics/otlp_transformer.js +2 -1
- package/packages/dd-trace/src/opentelemetry/otlp/otlp_transformer_base.js +16 -1
- package/packages/dd-trace/src/opentelemetry/trace/index.js +5 -4
- package/packages/dd-trace/src/opentelemetry/trace/otlp_http_trace_exporter.js +10 -6
- package/packages/dd-trace/src/opentelemetry/trace/otlp_transformer.js +42 -26
- package/packages/dd-trace/src/opentracing/propagation/text_map.js +4 -4
- package/packages/dd-trace/src/plugin_manager.js +2 -0
- package/packages/dd-trace/src/plugins/ci_plugin.js +104 -9
- package/packages/dd-trace/src/plugins/index.js +2 -0
- package/packages/dd-trace/src/plugins/util/ci.js +34 -0
- package/packages/dd-trace/src/plugins/util/http-otel-semantics.js +9 -14
- package/packages/dd-trace/src/plugins/util/inferred_proxy.js +3 -5
- package/packages/dd-trace/src/plugins/util/test.js +28 -1
- package/packages/dd-trace/src/plugins/util/url.js +9 -6
- package/packages/dd-trace/src/plugins/util/user-provided-git.js +4 -4
- 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/propagation-hash/index.js +7 -0
- package/packages/dd-trace/src/proxy.js +13 -1
- package/packages/dd-trace/src/register-loader.js +43 -0
- package/register.js +10 -44
- package/register.mjs +27 -0
- package/vendor/dist/@opentelemetry/core/LICENSE +11 -0
- package/vendor/dist/@opentelemetry/core/index.js +1 -1
- package/vite.d.ts +7 -0
- package/vite.js +3 -0
- package/lambda.d.ts +0 -39
- package/lambda.js +0 -3
- package/packages/datadog-plugin-cypress/src/support.js +0 -1348
|
@@ -7,4 +7,5 @@ captureDeclarations(test, TestRunner.getCurrentSuite)
|
|
|
7
7
|
globalThis[Symbol.for('dd-trace.vitest.browser-context-importer')] = () => import('vitest/browser')
|
|
8
8
|
globalThis[Symbol.for('dd-trace.vitest.skip-task')] = skip => skip('Skipped by Datadog Test Optimization')
|
|
9
9
|
|
|
10
|
-
await import('./vitest-no-worker-init-setup.mjs')
|
|
10
|
+
const { setup } = await import('./vitest-no-worker-init-setup.mjs')
|
|
11
|
+
setup()
|
package/index.d.ts
CHANGED
|
@@ -1957,6 +1957,58 @@ declare namespace tracer {
|
|
|
1957
1957
|
*/
|
|
1958
1958
|
arguments: string;
|
|
1959
1959
|
};
|
|
1960
|
+
/**
|
|
1961
|
+
* Set when the tool call runs an MCP tool: references an entry of the `mcpServers` evaluate option.
|
|
1962
|
+
*/
|
|
1963
|
+
mcp?: {
|
|
1964
|
+
/**
|
|
1965
|
+
* The `id` of the MCP server entry of the tool.
|
|
1966
|
+
*/
|
|
1967
|
+
server_id: string;
|
|
1968
|
+
};
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
/**
|
|
1972
|
+
* An MCP server referenced by the `mcp.server_id` of tool calls, sent in the `mcpServers` evaluate option.
|
|
1973
|
+
* The SDK sends these values to AI Guard and stores them on the AI Guard span as given, without redaction:
|
|
1974
|
+
* remove any credential before passing them.
|
|
1975
|
+
*/
|
|
1976
|
+
export interface McpServer {
|
|
1977
|
+
/**
|
|
1978
|
+
* Server ID that the tool calls reference with `mcp.server_id`.
|
|
1979
|
+
*/
|
|
1980
|
+
id: string;
|
|
1981
|
+
/**
|
|
1982
|
+
* Who runs the MCP client: `client` when the application runs it, `provider` when the model provider runs it.
|
|
1983
|
+
*/
|
|
1984
|
+
managed_by: 'client' | 'provider';
|
|
1985
|
+
/**
|
|
1986
|
+
* Transport of the server.
|
|
1987
|
+
*/
|
|
1988
|
+
transport: 'streamable_http' | 'sse' | 'stdio' | 'in_process' | 'unknown';
|
|
1989
|
+
/**
|
|
1990
|
+
* Configured name of the server.
|
|
1991
|
+
*/
|
|
1992
|
+
name?: string;
|
|
1993
|
+
/**
|
|
1994
|
+
* Origin of the server URL: scheme, host and port only. Remove userinfo, path, query and fragment before
|
|
1995
|
+
* passing it: many MCP providers put the API key there.
|
|
1996
|
+
*/
|
|
1997
|
+
url?: string;
|
|
1998
|
+
/**
|
|
1999
|
+
* Program name of a stdio server command. Pass the program name, not the full path, which can contain the
|
|
2000
|
+
* user name.
|
|
2001
|
+
*/
|
|
2002
|
+
command?: string;
|
|
2003
|
+
/**
|
|
2004
|
+
* Package or module that a stdio server runs. Leave out other arguments, which can contain paths, tokens or
|
|
2005
|
+
* secrets.
|
|
2006
|
+
*/
|
|
2007
|
+
args?: string[];
|
|
2008
|
+
/**
|
|
2009
|
+
* Original MCP tool name of each function name that the model uses.
|
|
2010
|
+
*/
|
|
2011
|
+
tools: { [functionName: string]: string };
|
|
1960
2012
|
}
|
|
1961
2013
|
|
|
1962
2014
|
/**
|
|
@@ -2162,6 +2214,9 @@ declare namespace tracer {
|
|
|
2162
2214
|
* `ai_guard` or starting with `ai_guard.` are reserved and ignored. Entries with an
|
|
2163
2215
|
* empty key, a key longer than 200 characters, a string value longer than 25000
|
|
2164
2216
|
* characters, or a value that is not a string, finite number or boolean are dropped.
|
|
2217
|
+
* - `mcpServers`: The MCP servers that the `mcp.server_id` of the tool calls reference. Sent with the
|
|
2218
|
+
* messages and reported on the AI Guard span; omitted when empty. The entries are sent
|
|
2219
|
+
* and stored as given and are not redacted: remove any credential from them first.
|
|
2165
2220
|
* @returns Promise resolving to an Evaluation with the security decision and reasoning.
|
|
2166
2221
|
* The promise rejects with AIGuardAbortError when `opts.block` is true and the evaluation result would block the request.
|
|
2167
2222
|
* The promise rejects with AIGuardClientError when communication with the AI Guard service fails.
|
|
@@ -2171,6 +2226,7 @@ declare namespace tracer {
|
|
|
2171
2226
|
opts?: {
|
|
2172
2227
|
block?: boolean,
|
|
2173
2228
|
tags?: { [key: string]: string | number | boolean },
|
|
2229
|
+
mcpServers?: McpServer[],
|
|
2174
2230
|
}
|
|
2175
2231
|
): Promise<Evaluation>;
|
|
2176
2232
|
}
|
package/initialize.mjs
CHANGED
|
@@ -26,6 +26,7 @@ const brokenLoaders = NODE_VERSION.startsWith('18.0')
|
|
|
26
26
|
const isNode20LoaderWorker = !isMainThread && NODE_VERSION.startsWith('20.0')
|
|
27
27
|
const useDefaultLoader = brokenLoaders || isNode20LoaderWorker
|
|
28
28
|
// Avoid CommonJS in the loader worker on Node 20.0: https://github.com/nodejs/node/issues/47566
|
|
29
|
+
// @ts-expect-error Node supports query strings in module specifiers.
|
|
29
30
|
const loaderHook = useDefaultLoader ? undefined : await import('./loader-hook.mjs?initialize')
|
|
30
31
|
|
|
31
32
|
let hasInsertedInit = false
|
|
@@ -43,7 +44,7 @@ export const globalPreload = isNode20LoaderWorker
|
|
|
43
44
|
/**
|
|
44
45
|
* @param {{ source?: string|Buffer|Uint8Array, format?: string }} result
|
|
45
46
|
* @param {unknown} _url_
|
|
46
|
-
* @param {{ format?: string, isMain?: boolean }} context
|
|
47
|
+
* @param {{ format?: string | null, isMain?: boolean }} context
|
|
47
48
|
* @returns {{ source?: string|Buffer|Uint8Array, format?: string }}
|
|
48
49
|
*/
|
|
49
50
|
function insertInit (result, _url_, context) {
|
|
@@ -103,7 +104,8 @@ if (isMainThread) {
|
|
|
103
104
|
// Only register the loader hook when instrumentation initialized. On a bailout the
|
|
104
105
|
// loader has nothing to instrument and can keep a short-lived process from exiting.
|
|
105
106
|
// `registerHooks` alone keeps the gate open once Node.js drops `register` (nodejs/node#67090).
|
|
106
|
-
|
|
107
|
-
|
|
107
|
+
const hasSyncHooks = 'registerHooks' in Module && typeof Module.registerHooks === 'function'
|
|
108
|
+
if (initialized && (hasSyncHooks || typeof Module.register === 'function')) {
|
|
109
|
+
await import('./register.mjs')
|
|
108
110
|
}
|
|
109
111
|
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dd-trace",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.138.0",
|
|
4
4
|
"description": "Datadog APM tracing client for JavaScript",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"env": "bash ./plugin-env",
|
|
9
|
-
"prepare": "node scripts/patch-istanbul-lib-coverage.js && node scripts/patch-v8-to-istanbul.js &&
|
|
9
|
+
"prepare": "node scripts/patch-istanbul-lib-coverage.js && node scripts/patch-v8-to-istanbul.js && npm exec --yes --package=bun -- bun install --cwd vendor --config=../bunfig.toml --silent --frozen-lockfile",
|
|
10
10
|
"prepack": "node scripts/release/swap-v5-types.js",
|
|
11
11
|
"bench": "node benchmark/index.js",
|
|
12
12
|
"bench:elevenlabs": "node benchmark/elevenlabs.js",
|
|
13
13
|
"bench:e2e:test-optimization": "node benchmark/e2e-test-optimization/benchmark-run.js",
|
|
14
|
-
"dependencies:dedupe": "yarn-deduplicate yarn.lock",
|
|
15
14
|
"generate:config:types": "node scripts/generate-config-types.js",
|
|
16
15
|
"generate:electron-package": "node scripts/generate-electron-package.js",
|
|
17
16
|
"verify:config:types": "node scripts/generate-config-types.js --check",
|
|
@@ -20,8 +19,9 @@
|
|
|
20
19
|
"verify:rewriter:targets": "node scripts/generate-rewriter-targets.js --check",
|
|
21
20
|
"generate:supported-integrations": "node scripts/generate-supported-integrations.js",
|
|
22
21
|
"type:check": "tsc --noEmit -p tsconfig.dev.json",
|
|
23
|
-
"type:
|
|
24
|
-
"type:doc:
|
|
22
|
+
"type:check:ci": "node scripts/type-check.js tsconfig.type-checked.json",
|
|
23
|
+
"type:doc:build": "cd docs && bun install --frozen-lockfile && bun run build",
|
|
24
|
+
"type:doc:test": "cd docs && bun install --frozen-lockfile && bun run test",
|
|
25
25
|
"lint": "bash ./scripts/lint.sh",
|
|
26
26
|
"lint:fix": "node scripts/check_licenses.js && node scripts/check-agents-md-size.js && node scripts/check-no-coverage-artifacts.js && node scripts/check-no-mcr-images.js && node scripts/check-docker-image-shas.js && node scripts/check-workflow-inline-js.js && eslint . --concurrency=auto --max-warnings 0 --fix",
|
|
27
27
|
"verify:carrier-fields": "node scripts/verify-carrier-fields.mjs",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"test:appsec": "mocha --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" \"packages/dd-trace/test/appsec/**/*.spec.js\"",
|
|
38
38
|
"test:appsec:ci": "node scripts/c8-ci.js test:appsec",
|
|
39
39
|
"test:appsec:plugins": "mocha \"packages/dd-trace/test/appsec/**/*.@(${PLUGINS}).plugin.spec.js\"",
|
|
40
|
-
"test:appsec:plugins:ci": "
|
|
40
|
+
"test:appsec:plugins:ci": "npm run services && node scripts/c8-ci.js test:appsec:plugins",
|
|
41
41
|
"test:debugger": "mocha \"packages/dd-trace/test/debugger/**/*.spec.js\"",
|
|
42
42
|
"test:debugger:ci": "node scripts/c8-ci.js test:debugger",
|
|
43
43
|
"test:eslint-rules": "node scripts/run-eslint-rule-tests.mjs eslint-rules/*.test.mjs",
|
|
@@ -49,10 +49,12 @@
|
|
|
49
49
|
"test:esbuild:ci": "node scripts/c8-ci.js test:esbuild",
|
|
50
50
|
"test:turbopack": "mocha \"packages/datadog-turbopack/test/**/*.spec.js\"",
|
|
51
51
|
"test:turbopack:ci": "node scripts/c8-ci.js test:turbopack",
|
|
52
|
+
"test:vite": "mocha \"packages/datadog-vite/test/**/*.spec.js\"",
|
|
53
|
+
"test:vite:ci": "node scripts/c8-ci.js test:vite",
|
|
52
54
|
"test:webpack": "mocha \"packages/datadog-webpack/test/**/*.spec.js\"",
|
|
53
55
|
"test:webpack:ci": "node scripts/c8-ci.js test:webpack",
|
|
54
56
|
"test:instrumentations": "mocha --fail-zero \"packages/datadog-instrumentations/test/@(${PLUGINS}).spec.js\"",
|
|
55
|
-
"test:instrumentations:ci": "
|
|
57
|
+
"test:instrumentations:ci": "npm run services && node scripts/c8-ci.js test:instrumentations",
|
|
56
58
|
"test:instrumentations:misc": "mocha \"packages/datadog-instrumentations/test/*/**/*.spec.{js,mjs}\"",
|
|
57
59
|
"test:instrumentations:misc:ci": "node scripts/c8-ci.js test:instrumentations:misc",
|
|
58
60
|
"test:core": "node scripts/mocha-parallel-files.js --expose-gc --timeout 30000 -- \"packages/datadog-core/test/**/*.spec.js\"",
|
|
@@ -65,12 +67,12 @@
|
|
|
65
67
|
"test:llmobs:sdk": "mocha --exclude \"packages/dd-trace/test/llmobs/plugins/**/*.spec.js\" \"packages/dd-trace/test/llmobs/**/*.spec.js\"",
|
|
66
68
|
"test:llmobs:sdk:ci": "node scripts/c8-ci.js test:llmobs:sdk",
|
|
67
69
|
"test:llmobs:plugins": "mocha \"packages/dd-trace/test/llmobs/plugins/@(${PLUGINS})/*.spec.js\"",
|
|
68
|
-
"test:llmobs:plugins:ci": "
|
|
70
|
+
"test:llmobs:plugins:ci": "npm run services && node scripts/c8-ci.js test:llmobs:plugins",
|
|
69
71
|
"test:openfeature": "mocha \"packages/dd-trace/test/evp_proxy/**/*.spec.js\" \"packages/dd-trace/test/openfeature/**/*.spec.js\"",
|
|
70
72
|
"test:openfeature:ci": "node scripts/c8-ci.js test:openfeature",
|
|
71
73
|
"test:plugins": "node --expose-gc ./node_modules/mocha/bin/mocha.js --fail-zero \"packages/datadog-plugin-@(${PLUGINS})/test/**/${SPEC:-*}*.spec.js\"",
|
|
72
|
-
"test:plugins:ci": "
|
|
73
|
-
"test:plugins:ci:flaky": "
|
|
74
|
+
"test:plugins:ci": "npm run services && node scripts/c8-ci.js test:plugins",
|
|
75
|
+
"test:plugins:ci:flaky": "npm run services && node scripts/c8-ci.js test:plugins --bail --retries 2",
|
|
74
76
|
"test:plugins:upstream": "node ./packages/dd-trace/test/plugins/suite.js",
|
|
75
77
|
"test:profiler": "node scripts/mocha-parallel-files.js --expose-gc --timeout 30000 -- \"packages/dd-trace/test/profiling/**/*.spec.js\"",
|
|
76
78
|
"test:profiler:ci": "node scripts/c8-ci.js test:profiler",
|
|
@@ -115,14 +117,15 @@
|
|
|
115
117
|
"test:integration:testopt:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 120000 \"integration-tests/ci-visibility/${SPEC:-*}.spec.js\"",
|
|
116
118
|
"test:integration:profiler": "mocha --timeout 180000 \"integration-tests/profiler/*.spec.js\"",
|
|
117
119
|
"test:integration:profiler:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 180000 \"integration-tests/profiler/*.spec.js\"",
|
|
118
|
-
"test:integration:plugins": "
|
|
119
|
-
"test:integration:plugins:coverage": "
|
|
120
|
+
"test:integration:plugins": "npm run services && mocha \"packages/datadog-plugin-@(${PLUGINS})/test/integration-test/**/${SPEC:-*}*.spec.js\"",
|
|
121
|
+
"test:integration:plugins:coverage": "npm run services && node ./integration-tests/coverage/run-suite.js \"packages/datadog-plugin-@(${PLUGINS})/test/integration-test/**/${SPEC:-*}*.spec.js\"",
|
|
120
122
|
"test:unit:plugins": "mocha \"packages/datadog-instrumentations/test/@(${PLUGINS}).spec.js\" \"packages/datadog-plugin-@(${PLUGINS})/test/**/*.spec.js\" --exclude \"packages/datadog-plugin-@(${PLUGINS})/test/integration-test/**/*.spec.js\"",
|
|
121
123
|
"test:release": "mocha \"scripts/release/**/*.spec.js\"",
|
|
122
124
|
"test:scripts": "mocha \"benchmark/e2e-test-optimization/*.spec.js\" \"benchmark/sirun/*.spec.js\" \"scripts/helpers/**/*.spec.js\" \"scripts/test/**/*.spec.js\" \"scripts/*.spec.mjs\"",
|
|
123
125
|
"test:shimmer": "mocha \"packages/datadog-shimmer/test/**/*.spec.js\"",
|
|
124
126
|
"test:shimmer:ci": "node scripts/c8-ci.js test:shimmer",
|
|
125
127
|
"verify:workflow-job-names": "node scripts/verify-workflow-job-names.js",
|
|
128
|
+
"verify:dependency-updates": "node scripts/verify-dependency-updates.js",
|
|
126
129
|
"verify-exercised-tests": "node scripts/verify-exercised-tests.js"
|
|
127
130
|
},
|
|
128
131
|
"repository": {
|
|
@@ -156,6 +159,8 @@
|
|
|
156
159
|
"esbuild.js",
|
|
157
160
|
"next.js",
|
|
158
161
|
"next.d.ts",
|
|
162
|
+
"vite.js",
|
|
163
|
+
"vite.d.ts",
|
|
159
164
|
"webpack.js",
|
|
160
165
|
"ext/**/*",
|
|
161
166
|
"index.d.ts",
|
|
@@ -168,8 +173,6 @@
|
|
|
168
173
|
"LICENSE.Apache",
|
|
169
174
|
"LICENSE.BSD3",
|
|
170
175
|
"loader-hook.mjs",
|
|
171
|
-
"lambda.d.ts",
|
|
172
|
-
"lambda.js",
|
|
173
176
|
"openfeature.d.ts",
|
|
174
177
|
"openfeature.js",
|
|
175
178
|
"openfeature/rules-based.js",
|
|
@@ -183,6 +186,7 @@
|
|
|
183
186
|
"packages/datadog-instrumentations/orchestrion.yml",
|
|
184
187
|
"README.md",
|
|
185
188
|
"register.js",
|
|
189
|
+
"register.mjs",
|
|
186
190
|
"vendor/dist/**/*.d.ts",
|
|
187
191
|
"vendor/dist/**/*.js",
|
|
188
192
|
"vendor/dist/**/*.wasm",
|
|
@@ -197,7 +201,7 @@
|
|
|
197
201
|
"optionalDependencies": {
|
|
198
202
|
"@datadog/libdatadog": "^0.21.0",
|
|
199
203
|
"@datadog/libdatadog-extras": "^0.21.0",
|
|
200
|
-
"@datadog/native-appsec": "
|
|
204
|
+
"@datadog/native-appsec": "12.0.0",
|
|
201
205
|
"@datadog/native-iast-taint-tracking": "4.2.1",
|
|
202
206
|
"@datadog/native-metrics": "4.0.0",
|
|
203
207
|
"@datadog/pprof": "5.20.1",
|
|
@@ -209,11 +213,11 @@
|
|
|
209
213
|
"devDependencies": {
|
|
210
214
|
"@actions/core": "^3.0.1",
|
|
211
215
|
"@actions/github": "^9.1.1",
|
|
212
|
-
"@babel/helpers": "^8.
|
|
216
|
+
"@babel/helpers": "^8.1.2",
|
|
213
217
|
"@eslint/eslintrc": "^3.3.7",
|
|
214
218
|
"@eslint/js": "^10.0.1",
|
|
215
219
|
"@eslint/plugin-kit": "^0.7.3",
|
|
216
|
-
"@datadog/openfeature-node-server": "2.
|
|
220
|
+
"@datadog/openfeature-node-server": "2.8.0",
|
|
217
221
|
"@msgpack/msgpack": "^3.1.3",
|
|
218
222
|
"@openfeature/core": "^1.12.0",
|
|
219
223
|
"@openfeature/server-sdk": "~1.23.0",
|
|
@@ -221,34 +225,32 @@
|
|
|
221
225
|
"@types/mocha": "^10.0.10",
|
|
222
226
|
"@types/node": "^18.19.106",
|
|
223
227
|
"@types/sinon": "^22.0.2",
|
|
224
|
-
"@vercel/nft": "^1.11.
|
|
225
|
-
"@yarnpkg/lockfile": "^1.1.0",
|
|
228
|
+
"@vercel/nft": "^1.11.7",
|
|
226
229
|
"benchmark": "^2.1.4",
|
|
227
230
|
"body-parser": "^2.4.0",
|
|
228
231
|
"bun": "1.4.4",
|
|
229
232
|
"c8": "^12.0.0",
|
|
230
233
|
"codeowners-audit": "^2.9.0",
|
|
231
|
-
"eslint": "^10.
|
|
232
|
-
"eslint-plugin-cypress": "^7.0.
|
|
233
|
-
"eslint-plugin-import-x": "^4.
|
|
234
|
-
"eslint-plugin-jsdoc": "^65.4.
|
|
234
|
+
"eslint": "^10.15.0",
|
|
235
|
+
"eslint-plugin-cypress": "^7.0.5",
|
|
236
|
+
"eslint-plugin-import-x": "^4.18.1",
|
|
237
|
+
"eslint-plugin-jsdoc": "^65.4.12",
|
|
235
238
|
"eslint-plugin-mocha": "^12.0.2",
|
|
236
239
|
"eslint-plugin-n": "^18.5.0",
|
|
237
240
|
"eslint-plugin-promise": "^7.3.0",
|
|
238
|
-
"eslint-plugin-regexp": "^3.3.
|
|
241
|
+
"eslint-plugin-regexp": "^3.3.3",
|
|
239
242
|
"eslint-plugin-sonarjs": "^4.2.2",
|
|
240
|
-
"eslint-plugin-unicorn": "^
|
|
243
|
+
"eslint-plugin-unicorn": "^80.0.0",
|
|
241
244
|
"express": "^5.3.0",
|
|
242
245
|
"glob": "^10.4.5",
|
|
243
|
-
"globals": "^17.
|
|
246
|
+
"globals": "^17.14.0",
|
|
244
247
|
"graphql": "*",
|
|
245
|
-
"husky": "^9.1.7",
|
|
246
248
|
"istanbul-lib-coverage": "^3.2.2",
|
|
247
249
|
"istanbul-lib-report": "^3.0.0",
|
|
248
250
|
"istanbul-reports": "^3.0.2",
|
|
249
251
|
"jsonc-parser": "^3.3.1",
|
|
250
252
|
"jszip": "^3.10.2",
|
|
251
|
-
"minimatch": "^11.0.
|
|
253
|
+
"minimatch": "^11.0.9",
|
|
252
254
|
"mocha": "^11.8.0",
|
|
253
255
|
"mocha-junit-reporter": "^2.2.1",
|
|
254
256
|
"mocha-multi-reporters": "^1.5.2",
|
|
@@ -261,7 +263,7 @@
|
|
|
261
263
|
"proxyquire": "^2.1.3",
|
|
262
264
|
"retry": "^0.13.1",
|
|
263
265
|
"semifies": "^1.0.0",
|
|
264
|
-
"semver": "^7.8.
|
|
266
|
+
"semver": "^7.8.6",
|
|
265
267
|
"sinon": "^22.1.0",
|
|
266
268
|
"source-map-support": "^0.5.21",
|
|
267
269
|
"test-exclude": "^8.0.0",
|
|
@@ -269,7 +271,9 @@
|
|
|
269
271
|
"typescript": "^6.0.3",
|
|
270
272
|
"v8-to-istanbul": "^9.0.0",
|
|
271
273
|
"workerpool": "^10.0.3",
|
|
272
|
-
"yaml": "^2.9.1"
|
|
273
|
-
|
|
274
|
-
|
|
274
|
+
"yaml": "^2.9.1"
|
|
275
|
+
},
|
|
276
|
+
"trustedDependencies": [
|
|
277
|
+
"bun"
|
|
278
|
+
]
|
|
275
279
|
}
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('node:fs')
|
|
4
4
|
const path = require('node:path')
|
|
5
|
-
const {
|
|
5
|
+
const { fileURLToPath } = require('node:url')
|
|
6
6
|
|
|
7
7
|
const instrumentations = require('../datadog-instrumentations/src/helpers/instrumentations')
|
|
8
8
|
const {
|
|
9
9
|
createEsmResolver,
|
|
10
|
+
createEsmWrapper,
|
|
10
11
|
processModule,
|
|
11
12
|
} = require('../datadog-instrumentations/src/helpers/bundler-esm-exports')
|
|
12
13
|
const { getGitMetadataBanner, isESMFile } = require('../datadog-instrumentations/src/helpers/bundler-utils')
|
|
@@ -348,20 +349,12 @@ ${build.initialOptions.banner.js}`
|
|
|
348
349
|
transform: build.esbuild.transformSync,
|
|
349
350
|
})
|
|
350
351
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
const _ = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
358
|
-
const set = {};
|
|
359
|
-
const get = {};
|
|
360
|
-
|
|
361
|
-
${[...setters.values()].join(';\n')};
|
|
362
|
-
|
|
363
|
-
register(${JSON.stringify(toRegister)}, _, set, get, ${JSON.stringify(data.raw)});
|
|
364
|
-
`
|
|
352
|
+
contents = createEsmWrapper({
|
|
353
|
+
path: args.path,
|
|
354
|
+
internal: data.internal,
|
|
355
|
+
specifier: data.raw,
|
|
356
|
+
setters: setters.values(),
|
|
357
|
+
})
|
|
365
358
|
} else {
|
|
366
359
|
contents = fs.readFileSync(args.path, 'utf8')
|
|
367
360
|
}
|
|
@@ -1,32 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const createBundlerLog = require('../../datadog-instrumentations/src/helpers/bundler-log')
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
const DD_TRACE_DEBUG = (process.env.DD_TRACE_DEBUG || '').trim().toLowerCase()
|
|
7
|
-
const DEBUG = DD_TRACE_DEBUG === 'true' || DD_TRACE_DEBUG === '1'
|
|
8
|
-
|
|
9
|
-
const noop = () => {}
|
|
10
|
-
|
|
11
|
-
const formatWithLogPrefix = (prefix, str, ...args) => {
|
|
12
|
-
if (typeof str === 'string') {
|
|
13
|
-
return format(`${prefix} ${str}`, ...args)
|
|
14
|
-
}
|
|
15
|
-
return format(prefix, str, ...args)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
module.exports = DEBUG
|
|
19
|
-
? {
|
|
20
|
-
debug (...args) {
|
|
21
|
-
// eslint-disable-next-line no-console
|
|
22
|
-
console.log(formatWithLogPrefix('[dd-trace/esbuild]', ...args))
|
|
23
|
-
},
|
|
24
|
-
warn (...args) {
|
|
25
|
-
// eslint-disable-next-line no-console
|
|
26
|
-
console.warn(formatWithLogPrefix('[dd-trace/esbuild] Warning:', ...args))
|
|
27
|
-
},
|
|
28
|
-
}
|
|
29
|
-
: {
|
|
30
|
-
debug: noop,
|
|
31
|
-
warn: noop,
|
|
32
|
-
}
|
|
5
|
+
module.exports = createBundlerLog('esbuild')
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const { channel, tracingChannel } = require('dc-polyfill')
|
|
4
4
|
const shimmer = require('../../datadog-shimmer')
|
|
5
|
-
const { addHook, getHooks } = require('./helpers/instrument')
|
|
6
5
|
|
|
7
6
|
const vercelAiTracingChannel = tracingChannel('dd-trace:vercel-ai')
|
|
8
7
|
const vercelAiSpanSetAttributesChannel = channel('dd-trace:vercel-ai:span:setAttributes')
|
|
@@ -145,143 +144,110 @@ function wrapTracer (tracer) {
|
|
|
145
144
|
})
|
|
146
145
|
}
|
|
147
146
|
|
|
148
|
-
|
|
147
|
+
// Orchestrion setup requires this module before activating the plugins. Module caching keeps these subscribers
|
|
148
|
+
// singletons even when both entry points or multiple copies of the SDK are loaded.
|
|
149
|
+
tracingChannel('orchestrion:ai:getTracer').subscribe({
|
|
150
|
+
end (ctx) {
|
|
151
|
+
const { arguments: args, result: tracer } = ctx
|
|
152
|
+
const { isEnabled } = args[0] ?? {}
|
|
149
153
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
addHook(hook, exports => {
|
|
158
|
-
if (orchestrionSubscribed) return exports
|
|
159
|
-
orchestrionSubscribed = true
|
|
160
|
-
|
|
161
|
-
const getTracerChannel = tracingChannel('orchestrion:ai:getTracer')
|
|
162
|
-
getTracerChannel.subscribe({
|
|
163
|
-
end (ctx) {
|
|
164
|
-
const { arguments: args, result: tracer } = ctx
|
|
165
|
-
const { isEnabled } = args[0] ?? {}
|
|
166
|
-
|
|
167
|
-
if (isEnabled !== false) {
|
|
168
|
-
wrapTracer(tracer)
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* We patch this function to ensure that the telemetry attributes/tags are set always,
|
|
175
|
-
* even when telemetry options are not specified. This is to ensure easy use of this integration.
|
|
176
|
-
*
|
|
177
|
-
* If it is explicitly disabled, however, we will not change the options.
|
|
178
|
-
*/
|
|
179
|
-
const selectTelemetryAttributesChannel = tracingChannel('orchestrion:ai:selectTelemetryAttributes')
|
|
180
|
-
selectTelemetryAttributesChannel.subscribe({
|
|
181
|
-
start (ctx) {
|
|
182
|
-
const { arguments: args } = ctx
|
|
183
|
-
const options = args[0]
|
|
184
|
-
|
|
185
|
-
if (options.telemetry?.isEnabled !== false) {
|
|
186
|
-
args[0] = {
|
|
187
|
-
...options,
|
|
188
|
-
telemetry: {
|
|
189
|
-
...options.telemetry,
|
|
190
|
-
isEnabled: true,
|
|
191
|
-
},
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
})
|
|
154
|
+
if (isEnabled !== false) {
|
|
155
|
+
wrapTracer(tracer)
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
})
|
|
196
159
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
160
|
+
// Collect telemetry attributes by default, without overriding an explicit opt-out.
|
|
161
|
+
tracingChannel('orchestrion:ai:selectTelemetryAttributes').subscribe({
|
|
162
|
+
start (ctx) {
|
|
163
|
+
const { arguments: args } = ctx
|
|
164
|
+
const options = args[0]
|
|
165
|
+
|
|
166
|
+
if (options.telemetry?.isEnabled !== false) {
|
|
167
|
+
args[0] = {
|
|
168
|
+
...options,
|
|
169
|
+
telemetry: {
|
|
170
|
+
...options.telemetry,
|
|
171
|
+
isEnabled: true,
|
|
172
|
+
},
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
})
|
|
202
177
|
|
|
203
|
-
|
|
178
|
+
tracingChannel('orchestrion:ai:includeRuntimeContext').subscribe({
|
|
179
|
+
start (ctx) {
|
|
180
|
+
const options = ctx.arguments[0]
|
|
181
|
+
const runtimeContext = options?.runtimeContext
|
|
182
|
+
const telemetry = options?.telemetry ?? options?.experimental_telemetry
|
|
204
183
|
|
|
205
|
-
|
|
206
|
-
if (!keys.length) return
|
|
184
|
+
if (!runtimeContext || typeof runtimeContext !== 'object' || telemetry?.isEnabled === false) return
|
|
207
185
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
if (includeRuntimeContext[key] === undefined) includeRuntimeContext[key] = true
|
|
211
|
-
}
|
|
186
|
+
const keys = Object.keys(runtimeContext)
|
|
187
|
+
if (!keys.length) return
|
|
212
188
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
includeRuntimeContext,
|
|
218
|
-
},
|
|
219
|
-
}
|
|
220
|
-
},
|
|
221
|
-
})
|
|
189
|
+
const includeRuntimeContext = { ...telemetry?.includeRuntimeContext }
|
|
190
|
+
for (const key of keys) {
|
|
191
|
+
if (includeRuntimeContext[key] === undefined) includeRuntimeContext[key] = true
|
|
192
|
+
}
|
|
222
193
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
// The SDK builds a model from a string id, in which case only the resolved instance is
|
|
230
|
-
// worth wrapping; when the caller passed an instance, that is the one the SDK calls.
|
|
231
|
-
if (typeof model === 'string' || model === ctx.result) {
|
|
232
|
-
wrapModel(ctx.result)
|
|
233
|
-
} else {
|
|
234
|
-
wrapModel(model)
|
|
235
|
-
wrappedModels.add(ctx.result)
|
|
236
|
-
}
|
|
194
|
+
ctx.arguments[0] = {
|
|
195
|
+
...options,
|
|
196
|
+
telemetry: {
|
|
197
|
+
...telemetry,
|
|
198
|
+
includeRuntimeContext,
|
|
237
199
|
},
|
|
238
|
-
}
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
})
|
|
239
203
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
204
|
+
// resolveLanguageModel is called by all LLM entry points (generateText, streamText, generateObject, streamObject).
|
|
205
|
+
tracingChannel('orchestrion:ai:resolveLanguageModel').subscribe({
|
|
206
|
+
end (ctx) {
|
|
207
|
+
const model = ctx.arguments[0]
|
|
208
|
+
|
|
209
|
+
// The SDK builds a model from a string id, in which case only the resolved instance is
|
|
210
|
+
// worth wrapping; when the caller passed an instance, that is the one the SDK calls.
|
|
211
|
+
if (typeof model === 'string' || model === ctx.result) {
|
|
212
|
+
wrapModel(ctx.result)
|
|
213
|
+
} else {
|
|
214
|
+
wrapModel(model)
|
|
215
|
+
wrappedModels.add(ctx.result)
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
})
|
|
243
219
|
|
|
244
220
|
const aiSdkTelemetryChannel = tracingChannel('ai:telemetry')
|
|
245
221
|
const aiSdkTelemetryStreamedChunkChannel = channel('dd-trace:vercel-ai:chunk')
|
|
246
222
|
|
|
247
|
-
//
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
// as of the v7 release, the ai sdk does not automatically aggregate streamed responses
|
|
253
|
-
// we will handle emitting the chunks directly for products to handle
|
|
254
|
-
addHook({ name: 'ai', versions: ['>=7.0.0'] }, exports => {
|
|
255
|
-
if (subscribed) return exports
|
|
256
|
-
subscribed = true
|
|
257
|
-
|
|
258
|
-
// ai sdk v7 only supported on node.js 22+
|
|
259
|
-
// inlining this import here so we only import in those cases
|
|
260
|
-
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
|
261
|
-
const { TransformStream } = require('node:stream/web')
|
|
223
|
+
// Only v7+ publishes this channel, so older SDKs never run the stream observer.
|
|
224
|
+
aiSdkTelemetryChannel.subscribe({
|
|
225
|
+
asyncEnd (ctx) {
|
|
226
|
+
// guard against this event being re-emitted.
|
|
227
|
+
if (!ctx.isStream || !ctx.result?.stream || ctx.streamConsumed) return
|
|
262
228
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
229
|
+
// ai sdk v7 only supported on node.js 22+
|
|
230
|
+
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
|
231
|
+
const { TransformStream } = require('node:stream/web')
|
|
232
|
+
const transform = new TransformStream({
|
|
233
|
+
transform (chunk, controller) {
|
|
234
|
+
const done = chunk.type === 'finish'
|
|
267
235
|
|
|
268
|
-
|
|
269
|
-
transform (chunk, controller) {
|
|
270
|
-
const done = chunk.type === 'finish'
|
|
236
|
+
aiSdkTelemetryStreamedChunkChannel.publish({ ctx, chunk, done })
|
|
271
237
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
aiSdkTelemetryChannel.asyncEnd.publish(ctx)
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
controller.enqueue(chunk) // pass through value
|
|
279
|
-
},
|
|
280
|
-
})
|
|
238
|
+
if (done) {
|
|
239
|
+
aiSdkTelemetryChannel.asyncEnd.publish(ctx)
|
|
240
|
+
}
|
|
281
241
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
242
|
+
controller.enqueue(chunk) // pass through value
|
|
243
|
+
},
|
|
244
|
+
})
|
|
285
245
|
|
|
286
|
-
|
|
246
|
+
// The telemetry result may be a copy, but its stream is shared with the SDK.
|
|
247
|
+
// Preserve that identity and attach the observer when the SDK pipes the stream.
|
|
248
|
+
shimmer.wrap(ctx.result.stream, 'pipeThrough', pipeThrough => function () {
|
|
249
|
+
const stream = pipeThrough.call(this, transform)
|
|
250
|
+
return pipeThrough.apply(stream, arguments)
|
|
251
|
+
})
|
|
252
|
+
},
|
|
287
253
|
})
|