Problem Statement
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.
await streamText({
model,
messages,
runtimeContext: { requestId: 'req_123', tenantId: 'acme', apiToken: 'secret' },
telemetry: {
isEnabled: true,
functionId: 'support-chat',
includeRuntimeContext: { requestId: true, tenantId: true },
},
});
- 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 / toolsContext unfiltered, 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").
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").