Skip to content

feat(server-utils): Record AI SDK v7 runtime and tool context on Vercel AI spans - #25774

Merged
isaacs merged 3 commits into
developfrom
isaacs/js-3788
Oct 30, 2026
Merged

isaacs merged 3 commits into
developfrom
isaacs/js-3788

Conversation

@isaacs

@isaacs isaacs commented Oct 27, 2026

Copy link
Copy Markdown
Member

On ai 7 the telemetry.metadata option is gone. Per-call metadata goes in runtimeContext, and the app opts keys into telemetry with telemetry.includeRuntimeContext (and includeToolsContext for tool context). The channel subscriber did not read either field, so there was no way to put request-level data on gen_ai spans.

The subscriber now records each included runtimeContext key as vercel.ai.settings.context.<key> on the operation span and on its generate_content and execute_tool child spans. It records each included toolContext key as vercel.ai.toolCall.context.<key> on the execute_tool span. The runtimeContext names match @ai-sdk/otel (ai.settings.context.*) under the usual ai.* to vercel.ai.* renaming.

ai before 7.0.114 published the full context to the channel and ignored the include lists. A filtered context looks the same as an unfiltered one, so the subscriber only reads context from events that carry aiVersion, which ai added in 7.0.154. Older 7.x versions record no context, so keys the app did not opt in never leave it.

Fixes #24706
Fixes JS-3788

@isaacs
isaacs requested a review from a team as a code owner October 27, 2026 17:13
@isaacs
isaacs requested review from andreiborza and mydea and removed request for a team October 27, 2026 17:13
@linear-code

linear-code Bot commented Oct 27, 2026

Copy link
Copy Markdown

JS-3788

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 387e28d (PR test merge using develop at b63640b)

Against: b63640b (develop) · base run #64512

✅ Baseline matches: this diff contains only this PR's changes.

Path Size % Change Change
@sentry/browser 30.39 kB - -
@sentry/browser - with treeshaking flags 28.54 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.42 kB - -
@sentry/browser (incl. Tracing) 52.71 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.72 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.69 kB - -
@sentry/browser (incl. Tracing, Replay) 93.01 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.61 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 97.76 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 110.75 kB - -
@sentry/browser (incl. Feedback) 47.98 kB - -
@sentry/browser (incl. sendFeedback) 35.5 kB - -
@sentry/browser (incl. FeedbackAsync) 40.6 kB - -
@sentry/browser (incl. Metrics) 31.43 kB - -
@sentry/browser (incl. Logs) 31.72 kB - -
@sentry/browser (incl. Metrics & Logs) 32.44 kB - -
@sentry/react 32.28 kB - -
@sentry/react (incl. Tracing) 55.08 kB - -
@sentry/vue 38.66 kB - -
@sentry/vue (incl. Tracing) 55.73 kB - -
@sentry/svelte 30.42 kB - -
@sentry/remix (Remix 3 client bundle) 57.79 kB - -
CDN Bundle 32.18 kB - -
CDN Bundle (incl. Tracing) 53.23 kB - -
CDN Bundle (incl. Logs, Metrics) 34.46 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.17 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 75.87 kB - -
CDN Bundle (incl. Tracing, Replay) 91.45 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.38 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 97.55 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.55 kB - -
CDN Bundle - uncompressed 94.64 kB - -
CDN Bundle (incl. Tracing) - uncompressed 157.6 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.11 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.34 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.68 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 279.29 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 285.01 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 293 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 298.71 kB - -
@sentry/nextjs (client) 58.03 kB - -
@sentry/sveltekit (client) 53.23 kB - -
@sentry/core/server 44.24 kB - -
@sentry/core/browser 13.93 kB - -
@sentry/node 155.65 kB +0.11% +170 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.16 kB +0.01% +1 B 🔺
@sentry/node - without tracing 96.79 kB +0.03% +20 B 🔺
@sentry/node - without channel injection 136.02 kB +0.14% +177 B 🔺
@sentry/aws-serverless 104.99 kB +0.03% +21 B 🔺
@sentry/cloudflare (withSentry) - minified 197.94 kB - -
@sentry/cloudflare (withSentry) 491.97 kB - -
@sentry/nextjs/cloudflare (withSentry) - minified 218.48 kB - -

View base workflow run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7dcc279. Configure here.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 16 not successful, 35 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Failing after 31s Details
❌ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Failing after 24s Details
❌ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Failing after 25s Details
❌ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Failing after 53s Details
❌ CI: Optional E2E Tests / E2E supabase-nextjs Test (optional) Failing after 1m Details
❌ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Failing after 36s Details
❌ CI: Optional E2E Tests / E2E node-mastra Test (optional) Failing after 36s Details
❌ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Failing after 22s Details
❌ CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) Failing after 21s Details
❌ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Failing after 2m Details
❌ CI: Optional E2E Tests / E2E nextjs-14 (latest) Test (optional) Failing after 25s Details
❌ CI: Optional E2E Tests / E2E gen-ai-libraries (latest) Test (optional) Failing after 38s Details
❌ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Failing after 18s Details
❌ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Failing after 33s Details
❌ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Failing after 16s Details
❌ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Failing after 15s Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (deno) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E astro-7-static Test (optional) Successful in 45s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 49s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) Successful in 32s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 21s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve Test (optional) Successful in 42s Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 19s Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 43s Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 21s Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 40s Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Successful in 47s Details
✅ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 (tracer provider) Test (optional) Successful in 21s Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 22s Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions Test (optional) Successful in 17s Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) Successful in 42s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 18s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (latest) Test (optional) Successful in 43s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 35s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 24s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 23s Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 27s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 32s Details

andreiborza
andreiborza previously approved these changes Oct 28, 2026

@andreiborza andreiborza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM just one casing change request and adding these to conventions 🙏

@andreiborza
andreiborza dismissed their stale review October 28, 2026 16:33

Removing the approval so we don't accidentally merge this before sentry conventions are in.

@isaacs

isaacs commented Oct 28, 2026

Copy link
Copy Markdown
Member Author

@andreiborza I added a PR to sentry-conventions for the fields being added here, but there are a few others in that file from 3bfeb64 which are also not tracked in sentry-conventions. I think the move is land this and post a follow-up issue to clean those up? What do you think?

isaacs added a commit to getsentry/sentry-conventions that referenced this pull request Oct 30, 2026
…756)

* feat(attributes): Add Vercel AI runtime and tool context attributes

Add `vercel.ai.settings.context.<key>` and
`vercel.ai.tool_call.context.<key>`.

`ai` 7 removed `telemetry.metadata`. Per-call metadata now goes in
`runtimeContext` and `toolsContext`. The app opts keys into telemetry
with `telemetry.includeRuntimeContext` and
`telemetry.includeToolsContext`. The Vercel AI integration in
sentry-javascript records the included keys on gen_ai spans
(getsentry/sentry-javascript#25774).

The runtime context name matches `@ai-sdk/otel`, which emits
`ai.settings.context.<key>`, under the usual `ai.*` to `vercel.ai.*`
renaming. `@ai-sdk/otel` does not record tool context, so the tool
context name uses snake_case for its fixed segments.

The type is `string`, as for `vercel.ai.telemetry.metadata.<key>`.
Context values can have any type, so SDKs convert them to strings.

`ai` versions before 7.0.114 publish the full context on the
`ai:telemetry` channel and ignore the include lists. The attributes
tell SDKs to read context only from events that carry `aiVersion`
(added in `ai` 7.0.154), so keys the app did not opt in are not sent.

Related: getsentry/sentry-javascript#24706

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
isaacs and others added 3 commits October 30, 2026 11:28
…el AI spans

On `ai` 7 the `telemetry.metadata` option is gone. Per-call metadata
goes in `runtimeContext`, and the app opts keys into telemetry with
`telemetry.includeRuntimeContext` (and `includeToolsContext` for tool
context). The channel subscriber did not read either field, so there
was no way to put request-level data on gen_ai spans.

The subscriber now records each included `runtimeContext` key as
`vercel.ai.settings.context.<key>` on the operation span and on its
`generate_content` and `execute_tool` child spans. It records each
included `toolContext` key as `vercel.ai.toolCall.context.<key>` on
the `execute_tool` span. The `runtimeContext` names match
`@ai-sdk/otel` (`ai.settings.context.*`) under the usual `ai.*` to
`vercel.ai.*` renaming.

`ai` before 7.0.114 published the full context to the channel and
ignored the include lists. A filtered context looks the same as an
unfiltered one, so the subscriber only reads context from events that
carry `aiVersion`, which `ai` added in 7.0.154. Older 7.x versions
record no context, so keys the app did not opt in never leave it.

Fixes #24706
Fixes JS-3788

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Rename `vercel.ai.toolCall.context.<key>` to
`vercel.ai.tool_call.context.<key>`, because fixed segments in Sentry
conventions use snake_case. Record every context value as a string, to
match the `string` type of both attributes in sentry-conventions.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@isaacs
isaacs enabled auto-merge (squash) October 30, 2026 18:30
@isaacs
isaacs merged commit ef23ed5 into develop Oct 30, 2026
470 of 570 checks passed
@isaacs
isaacs deleted the isaacs/js-3788 branch October 30, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vercelAIIntegration: record AI SDK v7 runtimeContext (filtered by telemetry.includeRuntimeContext) as span attributes

4 participants