Repository navigation
vercelAIIntegration: record AI SDK v7 runtimeContext (filtered by telemetry.includeRuntimeContext) as span attributes #24706
Description
Activity
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_agentspan- the same attributes copied to the child
generate_contentandexecute_toolspans toolContextonexecute_toolspans
We'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.Reacted by Rola Abuhasna- moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3
on Sep 24, 2026 @isaacs the vercel/ai fix was published in v7.0.114
Reacted by Rola Abuhasna- moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3
on Sep 25, 2026 - added a commit that references this issue
on Oct 6, 2026
Metadata
Metadata
Assignees
Projects
- StatusShow more project fieldsNo status
Problem Statement
AI SDK v7 removed
telemetry.metadata. Per-call metadata now goes inruntimeContext, and the app opts keys into telemetry withtelemetry.includeRuntimeContext(telemetry docs, runtime context docs).@ai-sdk/otelrecords the included keys asai.settings.runtimeContext.*. On v6 the equivalent data arrived throughexperimental_telemetry.metadataasvercel.ai.telemetry.metadata.*.The v7 channel subscriber in
@sentry/server-utils(vercel-ai-dc-subscriber, added in #21613) never readsruntimeContext, 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 combineregisterTelemetrywithvercelAIIntegration, so registering@ai-sdk/otelalongside it is not a workaround either.gen_ai.invoke_agentspan (and ideally itsgen_ai.generate_content/gen_ai.execute_toolchildren) carriesrequestIdandtenantId, and notapiToken.vercel.ai.operationId,vercel.ai.model.provider,vercel.ai.settings.maxRetriesand thegen_ai.*attributes.Checked against
@sentry/node10.71.0 and the@sentry/server-utilssubscriber in 10.75.3 and 11.0.0, withai7.0.100 / 7.0.113 on Node.Solution Brainstorm
buildInvokeAgentSpan, set one attribute perevent.runtimeContextkey.vercel.ai.settings.runtimeContext.<key>would match@ai-sdk/otel'sai.settings.runtimeContext.*under the existingai.*tovercel.ai.*renaming.generate_content/execute_toolspans through the existingcallIdmaps (likeoperationIdByCallId), since those channel events do not carryruntimeContext.event.toolContextonexecute_toolspans, which the AI SDK filters bytelemetry.includeToolsContext.Dependency on the AI SDK. In
ai<= 7.0.113 the channel publishesruntimeContext/toolsContextunfiltered, ignoringincludeRuntimeContext(vercel/ai#21442). Readingevent.runtimeContexton 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").