You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
vercelAIIntegration: record AI SDK v7 runtimeContext (filtered by telemetry.includeRuntimeContext) as span attributes #24706
AI SDK v7 removed telemetry.metadata. Per-call metadata now goes in runtimeContext, and the app opts keys into telemetry with telemetry.includeRuntimeContext (telemetry docs, runtime context docs). @ai-sdk/otel records the included keys as ai.settings.runtimeContext.*. On v6 the equivalent data arrived through experimental_telemetry.metadata as vercel.ai.telemetry.metadata.*.
The v7 channel subscriber in @sentry/server-utils (vercel-ai-dc-subscriber, added in #21613) never reads runtimeContext, so on v7 there is no way to attach request-level metadata (user, tenant, request id, ...) to gen_ai spans. The integration docs say not to combine registerTelemetry with vercelAIIntegration, so registering @ai-sdk/otel alongside it is not a workaround either.
Expected: the gen_ai.invoke_agent span (and ideally its gen_ai.generate_content / gen_ai.execute_tool children) carries requestId and tenantId, and not apiToken.
Actual: none of the keys appear. The span has only vercel.ai.operationId, vercel.ai.model.provider, vercel.ai.settings.maxRetries and the gen_ai.* attributes.
Checked against @sentry/node 10.71.0 and the @sentry/server-utils subscriber in 10.75.3 and 11.0.0, with ai 7.0.100 / 7.0.113 on Node.
Solution Brainstorm
In buildInvokeAgentSpan, set one attribute per event.runtimeContext key. vercel.ai.settings.runtimeContext.<key> would match @ai-sdk/otel's ai.settings.runtimeContext.* under the existing ai.* to vercel.ai.* renaming.
Copy the same attributes onto child generate_content / execute_tool spans through the existing callId maps (like operationIdByCallId), since those channel events do not carry runtimeContext.
Optionally, record event.toolContext on execute_tool spans, which the AI SDK filters by telemetry.includeToolsContext.
Dependency on the AI SDK. In ai <= 7.0.113 the channel publishes runtimeContext / toolsContextunfiltered, ignoring includeRuntimeContext (vercel/ai#21442). Reading event.runtimeContext on those versions would send keys the app never opted in to telemetry. The fix is open in vercel/ai#21447, which filters channel events the same way as registered integrations. So this should only read the field on AI SDK versions that include that fix, or otherwise guard against unfiltered context.
Additional Context
#24660 notes the same gap from the Cloudflare Think side ("neither subscriber reads either field").
Thanks for the detailed report and for tracking down the AI SDK side of this!
You're right. The v7 channel subscriber never reads runtimeContext, so there is currently no way to attach per-call metadata to gen_ai spans on ai 7. It's a gap in the feature: on v6 the metadata came from the AI SDK's own OTel attributes, and nothing replaced that when telemetry.metadata went away.
We don't want to read event.runtimeContext until the AI SDK filters it. As you noted, ai <= 7.0.113 publishes the full context to the channel. The channel event also doesn't carry the includeRuntimeContext allowlist, so we can't apply the filter ourselves. And a filtered context looks the same as an unfiltered one, so we can't detect which case we're in. If we read the field today, apps on those versions would send keys they never opted in, like the apiToken in your example.
vercel/ai#21447 merged today but isn't in a release yet. Once a release includes it, we can add support along the lines you suggested:
vercel.ai.settings.runtimeContext.<key> on the invoke_agent span
the same attributes copied to the child generate_content and execute_tool spans
toolContext on execute_tool spans
We'll document the minimum ai version for this once it's added. Until then, as a workaround you can set attributes on the enclosing span yourself, for example Sentry.getActiveSpan()?.setAttribute('tenantId', 'acme') inside a Sentry.startSpan around the call.
While looking into this, I also found and confirmed a regression in SDK v11: experimental_telemetry.metadata on ai 6 no longer reaches the gen_ai spans. SDK v10 recorded it as vercel.ai.telemetry.metadata.*. I'll post a separate issue for that.
Hey, just jumping in for Isaac: Now that the fix is released we can take another look at adding runtime and tool contexts. @andreiborza and @isaacs are aware.
Activity
linear-code commentedon Sep 24, 2026
JS-3788
isaacs commentedon Sep 24, 2026
Thanks for the detailed report and for tracking down the AI SDK side of this!
You're right. The v7 channel subscriber never reads
runtimeContext, so there is currently no way to attach per-call metadata to gen_ai spans onai7. It's a gap in the feature: on v6 the metadata came from the AI SDK's own OTel attributes, and nothing replaced that whentelemetry.metadatawent away.We don't want to read
event.runtimeContextuntil the AI SDK filters it. As you noted,ai<= 7.0.113 publishes the full context to the channel. The channel event also doesn't carry theincludeRuntimeContextallowlist, so we can't apply the filter ourselves. And a filtered context looks the same as an unfiltered one, so we can't detect which case we're in. If we read the field today, apps on those versions would send keys they never opted in, like theapiTokenin your example.vercel/ai#21447 merged today but isn't in a release yet. Once a release includes it, we can add support along the lines you suggested:
vercel.ai.settings.runtimeContext.<key>on theinvoke_agentspangenerate_contentandexecute_toolspanstoolContextonexecute_toolspansWe'll document the minimum
aiversion for this once it's added. Until then, as a workaround you can set attributes on the enclosing span yourself, for exampleSentry.getActiveSpan()?.setAttribute('tenantId', 'acme')inside aSentry.startSpanaround the call.While looking into this, I also found and confirmed a regression in SDK v11:
experimental_telemetry.metadataonai6 no longer reaches the gen_ai spans. SDK v10 recorded it asvercel.ai.telemetry.metadata.*. I'll post a separate issue for that.BrandonNoad commentedon Sep 25, 2026
@isaacs the vercel/ai fix was published in v7.0.114
fix(server-utils): Record Vercel AI `experimental_telemetry.metadata`…
fix(server-utils): Record Vercel AI `experimental_telemetry.metadata`…
fix(server-utils): Record Vercel AI `experimental_telemetry.metadata`…
fix(server-utils): Record Vercel AI `experimental_telemetry.metadata`…
fix(server-utils): Record Vercel AI `experimental_telemetry.metadata`…
fix(server-utils): Derive the Vercel AI conversation id from the Open…
BrandonNoad commentedon Oct 13, 2026
Hi @isaacs, just checking in on this one. Now that the filtering fix is out in
ai7.0.114, is this on the roadmap, and is there a rough timeline?Happy to help test a prerelease if that's useful. Thanks!
runtimeContextandtoolContexton AI SDK v7 spans #25352runtimeContextandtoolContexton AI SDK v7 spans #25352Lms24 commentedon Oct 14, 2026
Hey, just jumping in for Isaac: Now that the fix is released we can take another look at adding runtime and tool contexts. @andreiborza and @isaacs are aware.