dd-trace 6.0.0 → 6.1.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.
Files changed (77) hide show
  1. package/LICENSE-3rdparty.csv +1 -2
  2. package/index.d.ts +21 -1
  3. package/package.json +32 -29
  4. package/packages/datadog-instrumentations/src/ai.js +45 -0
  5. package/packages/datadog-instrumentations/src/apollo-server.js +5 -13
  6. package/packages/datadog-instrumentations/src/child_process.js +3 -3
  7. package/packages/datadog-instrumentations/src/claude-agent-sdk.js +587 -0
  8. package/packages/datadog-instrumentations/src/cucumber.js +102 -43
  9. package/packages/datadog-instrumentations/src/cypress-config.js +11 -3
  10. package/packages/datadog-instrumentations/src/fastify.js +27 -8
  11. package/packages/datadog-instrumentations/src/helpers/hooks.js +1 -0
  12. package/packages/datadog-instrumentations/src/helpers/instrument.js +7 -0
  13. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/ai.js +6 -6
  14. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/claude-agent-sdk.js +17 -0
  15. package/packages/datadog-instrumentations/src/helpers/rewriter/instrumentations/index.js +1 -0
  16. package/packages/datadog-instrumentations/src/jest.js +713 -63
  17. package/packages/datadog-instrumentations/src/mocha/main.js +24 -3
  18. package/packages/datadog-instrumentations/src/mocha/utils.js +128 -22
  19. package/packages/datadog-instrumentations/src/mocha/worker.js +13 -0
  20. package/packages/datadog-instrumentations/src/mongodb.js +74 -0
  21. package/packages/datadog-instrumentations/src/mongoose.js +4 -5
  22. package/packages/datadog-instrumentations/src/playwright.js +13 -9
  23. package/packages/datadog-instrumentations/src/vitest-main-no-worker-init.js +4 -0
  24. package/packages/datadog-instrumentations/src/vitest-main.js +28 -1
  25. package/packages/datadog-instrumentations/src/vitest-util.js +5 -0
  26. package/packages/datadog-instrumentations/src/vitest-worker.js +104 -34
  27. package/packages/datadog-plugin-ai/src/index.js +1 -1
  28. package/packages/datadog-plugin-ai/src/tracing.js +66 -3
  29. package/packages/datadog-plugin-ai/src/utils.js +17 -4
  30. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/context.js +1 -0
  31. package/packages/datadog-plugin-aws-durable-execution-sdk-js/src/handler.js +1 -0
  32. package/packages/datadog-plugin-child_process/src/index.js +13 -2
  33. package/packages/datadog-plugin-claude-agent-sdk/src/index.js +31 -0
  34. package/packages/datadog-plugin-claude-agent-sdk/src/tracing.js +107 -0
  35. package/packages/datadog-plugin-claude-agent-sdk/src/util.js +15 -0
  36. package/packages/datadog-plugin-cucumber/src/index.js +14 -23
  37. package/packages/datadog-plugin-cypress/src/cypress-plugin.js +351 -11
  38. package/packages/datadog-plugin-cypress/src/index.js +47 -2
  39. package/packages/datadog-plugin-cypress/src/plugin.js +1 -0
  40. package/packages/datadog-plugin-graphql/src/execute.js +21 -10
  41. package/packages/datadog-plugin-graphql/src/index.js +17 -1
  42. package/packages/datadog-plugin-graphql/src/utils.js +9 -2
  43. package/packages/datadog-plugin-graphql/src/validate.js +1 -1
  44. package/packages/datadog-plugin-jest/src/index.js +30 -14
  45. package/packages/datadog-plugin-mocha/src/index.js +39 -14
  46. package/packages/datadog-plugin-mongodb-core/src/bulk-write.js +43 -0
  47. package/packages/datadog-plugin-mongodb-core/src/index.js +8 -443
  48. package/packages/datadog-plugin-mongodb-core/src/query.js +452 -0
  49. package/packages/datadog-plugin-playwright/src/index.js +3 -2
  50. package/packages/datadog-plugin-vitest/src/index.js +51 -9
  51. package/packages/dd-trace/src/aiguard/index.js +9 -14
  52. package/packages/dd-trace/src/aiguard/integrations/index.js +34 -0
  53. package/packages/dd-trace/src/aiguard/integrations/openai.js +47 -33
  54. package/packages/dd-trace/src/aiguard/integrations/vercel-ai.js +42 -28
  55. package/packages/dd-trace/src/appsec/graphql.js +9 -6
  56. package/packages/dd-trace/src/appsec/iast/analyzers/nosql-injection-mongodb-analyzer.js +3 -10
  57. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/index.js +26 -1
  58. package/packages/dd-trace/src/ci-visibility/dynamic-instrumentation/worker/index.js +115 -24
  59. package/packages/dd-trace/src/ci-visibility/exporters/agent-proxy/index.js +3 -0
  60. package/packages/dd-trace/src/ci-visibility/exporters/agentless/index.js +3 -0
  61. package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +75 -7
  62. package/packages/dd-trace/src/ci-visibility/requests/upload-test-screenshot.js +156 -0
  63. package/packages/dd-trace/src/config/generated-config-types.d.ts +10 -0
  64. package/packages/dd-trace/src/config/supported-configurations.json +37 -0
  65. package/packages/dd-trace/src/crashtracking/crashtracker.js +2 -2
  66. package/packages/dd-trace/src/llmobs/plugins/ai/ddTelemetry.js +403 -0
  67. package/packages/dd-trace/src/llmobs/plugins/ai/index.js +8 -395
  68. package/packages/dd-trace/src/llmobs/plugins/ai/util.js +27 -0
  69. package/packages/dd-trace/src/llmobs/plugins/ai/vercelTelemetry.js +363 -0
  70. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/index.js +270 -0
  71. package/packages/dd-trace/src/llmobs/plugins/claude-agent-sdk/utils.js +10 -0
  72. package/packages/dd-trace/src/opentelemetry/span.js +5 -0
  73. package/packages/dd-trace/src/plugin_manager.js +16 -0
  74. package/packages/dd-trace/src/plugins/ci_plugin.js +147 -7
  75. package/packages/dd-trace/src/plugins/index.js +2 -0
  76. package/packages/dd-trace/src/plugins/util/test.js +4 -0
  77. package/packages/dd-trace/src/profiling/exporters/agent.js +28 -3
@@ -44,8 +44,6 @@
44
44
  "@oxc-project/types","https://github.com/oxc-project/oxc","['MIT']","['Boshen and oxc contributors']"
45
45
  "@tybys/wasm-util","https://github.com/toyobayashi/wasm-util","['MIT']","['toyobayashi']"
46
46
  "@types/estree","https://github.com/DefinitelyTyped/DefinitelyTyped","['MIT']","['DefinitelyTyped']"
47
- "acorn","https://github.com/acornjs/acorn","['MIT']","['acornjs']"
48
- "acorn-import-attributes","https://github.com/xtuc/acorn-import-attributes","['MIT']","['Sven Sauleau']"
49
47
  "argparse","https://github.com/nodeca/argparse","['Python-2.0']","['nodeca']"
50
48
  "astring","https://github.com/davidbonnet/astring","['MIT']","['David Bonnet']"
51
49
  "cjs-module-lexer","https://github.com/nodejs/cjs-module-lexer","['MIT']","['Guy Bedford']"
@@ -53,6 +51,7 @@
53
51
  "dc-polyfill","https://github.com/DataDog/dc-polyfill","['MIT']","['Thomas Hunter II']"
54
52
  "dd-trace","https://github.com/DataDog/dd-trace-js","['(Apache-2.0 OR BSD-3-Clause)']","['Datadog Inc. <info@datadoghq.com>']"
55
53
  "detect-newline","https://github.com/sindresorhus/detect-newline","['MIT']","['Sindre Sorhus']"
54
+ "es-module-lexer","https://github.com/guybedford/es-module-lexer","['MIT']","['Guy Bedford']"
56
55
  "escape-string-regexp","https://github.com/sindresorhus/escape-string-regexp","['MIT']","['Sindre Sorhus']"
57
56
  "esquery","https://github.com/estools/esquery","['BSD-3-Clause']","['Joel Feenstra']"
58
57
  "estraverse","https://github.com/estools/estraverse","['BSD-2-Clause']","['estools']"
package/index.d.ts CHANGED
@@ -233,6 +233,7 @@ interface Plugins {
233
233
  "amqp10": tracer.plugins.amqp10;
234
234
  "amqplib": tracer.plugins.amqplib;
235
235
  "anthropic": tracer.plugins.anthropic;
236
+ "claude-agent-sdk": tracer.plugins.claude_agent_sdk;
236
237
  "apollo": tracer.plugins.apollo;
237
238
  "avsc": tracer.plugins.avsc;
238
239
  "aws-durable-execution-sdk-js": tracer.plugins.aws_durable_execution_sdk_js;
@@ -2191,6 +2192,12 @@ declare namespace tracer {
2191
2192
  */
2192
2193
  interface anthropic extends Instrumentation {}
2193
2194
 
2195
+ /**
2196
+ * This plugin automatically instruments the
2197
+ * [@anthropic-ai/claude-agent-sdk](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk) module.
2198
+ */
2199
+ interface claude_agent_sdk extends Instrumentation {}
2200
+
2194
2201
  /**
2195
2202
  * Currently this plugin automatically instruments
2196
2203
  * [@apollo/gateway](https://github.com/apollographql/federation) for module versions >= v2.3.0.
@@ -2535,6 +2542,7 @@ declare namespace tracer {
2535
2542
  * count toward the limit, regardless of `collapse`.
2536
2543
  *
2537
2544
  * @default -1
2545
+ * @env DD_TRACE_GRAPHQL_DEPTH
2538
2546
  */
2539
2547
  depth?: number;
2540
2548
 
@@ -2551,7 +2559,10 @@ declare namespace tracer {
2551
2559
  /**
2552
2560
  * An array of variable names to record. Can also be a callback that returns
2553
2561
  * the key/value pairs to record. For example, using
2554
- * `variables => variables` would record all variables.
2562
+ * `variables => variables` would record all variables. The environment
2563
+ * variable only accepts the array form (comma-separated variable names).
2564
+ *
2565
+ * @env DD_TRACE_GRAPHQL_VARIABLES
2555
2566
  */
2556
2567
  variables?: string[] | ((variables: { [key: string]: any }) => { [key: string]: any });
2557
2568
 
@@ -2560,9 +2571,18 @@ declare namespace tracer {
2560
2571
  * `users.*.name` span instead of `users.0.name`, `users.1.name`, etc)
2561
2572
  *
2562
2573
  * @default true
2574
+ * @env DD_TRACE_GRAPHQL_COLLAPSE
2563
2575
  */
2564
2576
  collapse?: boolean;
2565
2577
 
2578
+ /**
2579
+ * An array of error `extensions` keys to attach to the span error event
2580
+ * for each GraphQL error.
2581
+ *
2582
+ * @env DD_TRACE_GRAPHQL_ERROR_EXTENSIONS
2583
+ */
2584
+ errorExtensions?: string[];
2585
+
2566
2586
  /**
2567
2587
  * Whether to enable signature calculation for the resource name. This can
2568
2588
  * be disabled if your GraphQL operations always have a name. Note that when
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "6.0.0",
3
+ "version": "6.1.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 && cd vendor && npm ci --include=dev",
9
+ "prepare": "node scripts/patch-istanbul-lib-coverage.js && node scripts/patch-v8-to-istanbul.js && cd vendor && npm ci --include=dev",
10
10
  "prepack": "node scripts/release/swap-v5-types.js",
11
11
  "bench": "node benchmark/index.js",
12
12
  "bench:e2e:test-optimization": "node benchmark/e2e-test-optimization/benchmark-run.js",
@@ -22,50 +22,50 @@
22
22
  "lint:fix": "node scripts/check_licenses.js && node scripts/check-no-coverage-artifacts.js && node scripts/check-no-mcr-images.js && node scripts/check-docker-image-shas.js && eslint . --concurrency=auto --max-warnings 0 --fix",
23
23
  "lint:inspect": "npx @eslint/config-inspector@latest",
24
24
  "lint:codeowners": "codeowners-audit",
25
- "lint:codeowners:ci": "codeowners-audit --glob='**/*.spec.js' --glob='benchmark/sirun/**' --glob='.agents/**' --glob='.claude/**'",
25
+ "lint:codeowners:ci": "codeowners-audit --glob='**/*.spec.js' --glob='benchmark/sirun/**' --glob='.agents/**' --glob='.claude/**' --glob='integration-tests/**'",
26
26
  "lint:editorconfig": "editorconfig-checker",
27
27
  "release:proposal": "node scripts/release/proposal",
28
28
  "services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",
29
29
  "test": "echo '\nError: The root \"npm test\" command is intentionally disabled.\n\nInstead, run specific test suites:\n - npm run test:trace:core\n - npm run test:appsec\n - etc.\n\nOr run individual test files:\n npx mocha path/to/test.spec.js\n\nSee CONTRIBUTING.md (Testing section) for more details.\n' && exit 1",
30
30
  "test:aiguard": "mocha \"packages/dd-trace/test/aiguard/**/*.spec.js\"",
31
- "test:aiguard:ci": "nyc --silent node init && nyc -- npm run test:aiguard",
31
+ "test:aiguard:ci": "node scripts/c8-ci.js test:aiguard",
32
32
  "test:appsec": "mocha --exclude \"packages/dd-trace/test/appsec/**/*.plugin.spec.js\" \"packages/dd-trace/test/appsec/**/*.spec.js\"",
33
- "test:appsec:ci": "nyc --silent node init && nyc -- npm run test:appsec",
33
+ "test:appsec:ci": "node scripts/c8-ci.js test:appsec",
34
34
  "test:appsec:plugins": "mocha \"packages/dd-trace/test/appsec/**/*.@(${PLUGINS}).plugin.spec.js\"",
35
- "test:appsec:plugins:ci": "yarn services && nyc --silent node init && nyc -- npm run test:appsec:plugins",
35
+ "test:appsec:plugins:ci": "yarn services && node scripts/c8-ci.js test:appsec:plugins",
36
36
  "test:debugger": "mocha \"packages/dd-trace/test/debugger/**/*.spec.js\"",
37
- "test:debugger:ci": "nyc --silent node init && nyc -- npm run test:debugger",
37
+ "test:debugger:ci": "node scripts/c8-ci.js test:debugger",
38
38
  "test:eslint-rules": "node eslint-rules/*.test.mjs",
39
39
  "test:trace:core": "node scripts/mocha-parallel-files.js --expose-gc --timeout 30000 -- \"packages/dd-trace/test/*.spec.js\" \"packages/dd-trace/test/{agent,ci-visibility,config,crashtracking,datastreams,encode,exporters,msgpack,opentelemetry,opentracing,payload-tagging,plugins,remote_config,service-naming,standalone,telemetry,external-logger}/**/*.spec.js\"",
40
- "test:trace:core:ci": "nyc --silent node init && nyc -- npm run test:trace:core",
40
+ "test:trace:core:ci": "node scripts/c8-ci.js test:trace:core",
41
41
  "test:trace:guardrails": "mocha \"packages/dd-trace/test/guardrails/**/*.spec.js\"",
42
- "test:trace:guardrails:ci": "nyc --silent node init && nyc -- npm run test:trace:guardrails",
42
+ "test:trace:guardrails:ci": "node scripts/c8-ci.js test:trace:guardrails",
43
43
  "test:esbuild": "mocha \"packages/datadog-esbuild/test/**/*.spec.js\"",
44
- "test:esbuild:ci": "nyc --silent node init && nyc -- npm run test:esbuild",
44
+ "test:esbuild:ci": "node scripts/c8-ci.js test:esbuild",
45
45
  "test:webpack": "mocha \"packages/datadog-webpack/test/**/*.spec.js\"",
46
- "test:webpack:ci": "nyc --silent node init && nyc -- npm run test:webpack",
46
+ "test:webpack:ci": "node scripts/c8-ci.js test:webpack",
47
47
  "test:instrumentations": "mocha \"packages/datadog-instrumentations/test/@(${PLUGINS}).spec.js\"",
48
- "test:instrumentations:ci": "yarn services && nyc --silent node init && nyc -- npm run test:instrumentations",
48
+ "test:instrumentations:ci": "yarn services && node scripts/c8-ci.js test:instrumentations",
49
49
  "test:instrumentations:misc": "mocha \"packages/datadog-instrumentations/test/*/**/*.spec.{js,mjs}\"",
50
- "test:instrumentations:misc:ci": "nyc --silent node init && nyc -- npm run test:instrumentations:misc",
50
+ "test:instrumentations:misc:ci": "node scripts/c8-ci.js test:instrumentations:misc",
51
51
  "test:core": "node scripts/mocha-parallel-files.js --expose-gc --timeout 30000 -- \"packages/datadog-core/test/**/*.spec.js\"",
52
- "test:core:ci": "nyc --silent node init && nyc -- npm run test:core",
52
+ "test:core:ci": "node scripts/c8-ci.js test:core",
53
53
  "test:code-origin": "mocha \"packages/datadog-code-origin/test/**/*.spec.js\"",
54
- "test:code-origin:ci": "nyc --silent node init && nyc -- npm run test:code-origin",
54
+ "test:code-origin:ci": "node scripts/c8-ci.js test:code-origin",
55
55
  "test:lambda": "mocha \"packages/dd-trace/test/lambda/**/*.spec.js\"",
56
- "test:lambda:ci": "nyc --silent node init && nyc -- npm run test:lambda",
56
+ "test:lambda:ci": "node scripts/c8-ci.js test:lambda",
57
57
  "test:llmobs:sdk": "mocha --exclude \"packages/dd-trace/test/llmobs/plugins/**/*.spec.js\" \"packages/dd-trace/test/llmobs/**/*.spec.js\"",
58
- "test:llmobs:sdk:ci": "nyc --silent node init && nyc -- npm run test:llmobs:sdk",
58
+ "test:llmobs:sdk:ci": "node scripts/c8-ci.js test:llmobs:sdk",
59
59
  "test:llmobs:plugins": "mocha \"packages/dd-trace/test/llmobs/plugins/@(${PLUGINS})/*.spec.js\"",
60
- "test:llmobs:plugins:ci": "yarn services && nyc --silent node init && nyc -- npm run test:llmobs:plugins",
60
+ "test:llmobs:plugins:ci": "yarn services && node scripts/c8-ci.js test:llmobs:plugins",
61
61
  "test:openfeature": "mocha \"packages/dd-trace/test/openfeature/**/*.spec.js\"",
62
- "test:openfeature:ci": "nyc --silent node init && nyc -- npm run test:openfeature",
62
+ "test:openfeature:ci": "node scripts/c8-ci.js test:openfeature",
63
63
  "test:plugins": "node --expose-gc ./node_modules/mocha/bin/mocha.js \"packages/datadog-plugin-@(${PLUGINS})/test/**/${SPEC:-*}*.spec.js\"",
64
- "test:plugins:ci": "yarn services && nyc --silent node init && nyc -- npm run test:plugins",
65
- "test:plugins:ci:flaky": "yarn services && nyc --silent node init && nyc -- npm run test:plugins -- --bail --retries 2",
64
+ "test:plugins:ci": "yarn services && node scripts/c8-ci.js test:plugins",
65
+ "test:plugins:ci:flaky": "yarn services && node scripts/c8-ci.js test:plugins --bail --retries 2",
66
66
  "test:plugins:upstream": "node ./packages/dd-trace/test/plugins/suite.js",
67
67
  "test:profiler": "node scripts/mocha-parallel-files.js --expose-gc --timeout 30000 -- \"packages/dd-trace/test/profiling/**/*.spec.js\"",
68
- "test:profiler:ci": "nyc --silent node init && nyc -- npm run test:profiler",
68
+ "test:profiler:ci": "node scripts/c8-ci.js test:profiler",
69
69
  "test:integration": "mocha --timeout 60000 \"integration-tests/*.spec.js\"",
70
70
  "test:integration:coverage": "node ./integration-tests/coverage/run-suite.js --timeout 60000 \"integration-tests/*.spec.js\"",
71
71
  "test:integration:aiguard": "mocha --timeout 60000 \"integration-tests/aiguard/*.spec.js\"",
@@ -106,7 +106,7 @@
106
106
  "test:release": "mocha \"scripts/release/**/*.spec.js\"",
107
107
  "test:scripts": "mocha \"scripts/helpers/**/*.spec.js\" \"scripts/*.spec.mjs\"",
108
108
  "test:shimmer": "mocha \"packages/datadog-shimmer/test/**/*.spec.js\"",
109
- "test:shimmer:ci": "nyc --silent node init && nyc -- npm run test:shimmer",
109
+ "test:shimmer:ci": "node scripts/c8-ci.js test:shimmer",
110
110
  "verify:workflow-job-names": "node scripts/verify-workflow-job-names.js",
111
111
  "verify-exercised-tests": "node scripts/verify-exercised-tests.js"
112
112
  },
@@ -164,7 +164,7 @@
164
164
  ],
165
165
  "dependencies": {
166
166
  "dc-polyfill": "^0.1.11",
167
- "import-in-the-middle": "^3.2.0",
167
+ "import-in-the-middle": "^3.3.1",
168
168
  "opentracing": ">=0.14.7"
169
169
  },
170
170
  "optionalDependencies": {
@@ -196,14 +196,15 @@
196
196
  "benchmark": "^2.1.4",
197
197
  "body-parser": "^2.3.0",
198
198
  "bun": "1.3.14",
199
+ "c8": "^11.0.0",
199
200
  "codeowners-audit": "^2.9.0",
200
201
  "editorconfig-checker": "^6.1.1",
201
202
  "eslint": "^9.39.2",
202
- "eslint-plugin-cypress": "^6.4.1",
203
+ "eslint-plugin-cypress": "^6.4.2",
203
204
  "eslint-plugin-import": "^2.32.0",
204
- "eslint-plugin-jsdoc": "^63.0.8",
205
+ "eslint-plugin-jsdoc": "^63.0.10",
205
206
  "eslint-plugin-mocha": "^11.3.0",
206
- "eslint-plugin-n": "^18.2.0",
207
+ "eslint-plugin-n": "^18.2.1",
207
208
  "eslint-plugin-promise": "^7.3.0",
208
209
  "eslint-plugin-sonarjs": "^4.1.0",
209
210
  "eslint-plugin-unicorn": "^64.0.0",
@@ -219,7 +220,7 @@
219
220
  "mocha-junit-reporter": "^2.2.1",
220
221
  "mocha-multi-reporters": "^1.5.1",
221
222
  "multer": "^2.2.0",
222
- "nock": "^14.0.15",
223
+ "nock": "^14.0.16",
223
224
  "node-preload": "^0.2.1",
224
225
  "nyc": "^18.0.0",
225
226
  "octokit": "^5.0.3",
@@ -229,9 +230,11 @@
229
230
  "semifies": "^1.0.0",
230
231
  "semver": "^7.8.5",
231
232
  "sinon": "^22.0.0",
233
+ "test-exclude": "^8.0.0",
232
234
  "tiktoken": "^1.0.21",
233
235
  "typescript": "^6.0.3",
234
- "workerpool": "^10.0.2",
236
+ "v8-to-istanbul": "^9.0.0",
237
+ "workerpool": "^10.0.3",
235
238
  "yaml": "^2.9.0",
236
239
  "yarn-deduplicate": "^6.0.2"
237
240
  }
@@ -233,4 +233,49 @@ for (const hook of getHooks('ai')) {
233
233
  })
234
234
  }
235
235
 
236
+ const aiSdkTelemetryChannel = tracingChannel('ai:telemetry')
237
+ const aiSdkTelemetryStreamedChunkChannel = channel('dd-trace:vercel-ai:chunk')
238
+
239
+ // for testing, and possibly actual instrumentation use, we want to
240
+ // guard against double-subscribing to the asyncEnd channel of the
241
+ // vercel ai-provided tracingChannel
242
+ let subscribed = false
243
+
244
+ // as of the v7 release, the ai sdk does not automatically aggregate streamed responses
245
+ // we will handle emitting the chunks directly for products to handle
246
+ addHook({ name: 'ai', versions: ['>=7.0.0'] }, exports => {
247
+ if (subscribed) return exports
248
+ subscribed = true
249
+
250
+ // ai sdk v7 only supported on node.js 22+
251
+ // inlining this import here so we only import in those cases
252
+ // eslint-disable-next-line n/no-unsupported-features/node-builtins
253
+ const { TransformStream } = require('node:stream/web')
254
+
255
+ aiSdkTelemetryChannel.subscribe({
256
+ asyncEnd (ctx) {
257
+ // guard against this event being re-emitted.
258
+ if (!ctx.isStream || !ctx.result?.stream || ctx.streamConsumed) return
259
+
260
+ const transform = new TransformStream({
261
+ transform (chunk, controller) {
262
+ const done = chunk.type === 'finish'
263
+
264
+ aiSdkTelemetryStreamedChunkChannel.publish({ ctx, chunk, done })
265
+
266
+ if (done) {
267
+ aiSdkTelemetryChannel.asyncEnd.publish(ctx)
268
+ }
269
+
270
+ controller.enqueue(chunk) // pass through value
271
+ },
272
+ })
273
+
274
+ ctx.result.stream = ctx.result.stream.pipeThrough(transform)
275
+ },
276
+ })
277
+
278
+ return exports
279
+ })
280
+
236
281
  module.exports = { wrapModelWithLifecycle }
@@ -112,24 +112,16 @@ function apolloDrainHttpServerHook (drainModule) {
112
112
  return drainModule
113
113
  }
114
114
 
115
- addHook({ name: '@apollo/server', file: 'dist/cjs/ApolloServer.js', versions: ['4'] }, apolloServerHook)
115
+ addHook({ name: '@apollo/server', file: 'dist/cjs/ApolloServer.js', versions: ['>=4'] }, apolloServerHook)
116
116
 
117
117
  addHook({ name: '@apollo/server', file: 'dist/cjs/express4/index.js', versions: ['4'] }, apolloExpress4Hook)
118
118
 
119
- addHook({ name: '@apollo/server', file: 'dist/cjs/utils/HeaderMap.js', versions: ['4'] }, apolloHeaderMapHook)
120
-
121
119
  addHook(
122
- { name: '@apollo/server', file: 'dist/cjs/plugin/drainHttpServer/index.js', versions: ['>=5.0.0'] },
123
- apolloDrainHttpServerHook
120
+ { name: '@apollo/server', file: 'dist/cjs/utils/HeaderMap.js', versions: ['>=4'] },
121
+ apolloHeaderMapHook
124
122
  )
125
123
 
126
124
  addHook(
127
- { name: '@apollo/server', file: 'dist/cjs/runHttpQuery.js', versions: ['>=5.0.0'] },
128
- (runHttpQueryModule) => {
129
- shimmer.wrap(runHttpQueryModule, 'runHttpQuery', function wrapRunHttpQuery (originalRunHttpQuery) {
130
- return wrapExecuteHTTPGraphQLRequest(originalRunHttpQuery)
131
- })
132
-
133
- return runHttpQueryModule
134
- }
125
+ { name: '@apollo/server', file: 'dist/cjs/plugin/drainHttpServer/index.js', versions: ['>=5.0.0'] },
126
+ apolloDrainHttpServerHook
135
127
  )
@@ -129,7 +129,7 @@ function wrapChildProcessCustomPromisifyMethod (customPromisifyMethod, shell) {
129
129
  const context = createContextFromChildProcessInfo(childProcessInfo)
130
130
  context.callArgs = callArgs
131
131
 
132
- const { start, end, asyncStart, asyncEnd, error } = childProcessChannel
132
+ const { start, end, asyncStart, asyncEnd, error: errorChannel } = childProcessChannel
133
133
  start.publish(context)
134
134
 
135
135
  let result
@@ -140,7 +140,7 @@ function wrapChildProcessCustomPromisifyMethod (customPromisifyMethod, shell) {
140
140
  result = customPromisifyMethod.apply(this, context.callArgs)
141
141
  } catch (error) {
142
142
  context.error = error
143
- error.publish(context)
143
+ errorChannel.publish(context)
144
144
  throw error
145
145
  } finally {
146
146
  end.publish(context)
@@ -149,7 +149,7 @@ function wrapChildProcessCustomPromisifyMethod (customPromisifyMethod, shell) {
149
149
 
150
150
  function reject (err) {
151
151
  context.error = err
152
- error.publish(context)
152
+ errorChannel.publish(context)
153
153
  asyncStart.publish(context)
154
154
 
155
155
  asyncEnd.publish(context)