Skip to content

vercelAIIntegration: Record runtimeContext and toolContext on AI SDK v7 spans #25352

Closed as not planned

Description

@andreiborza

Part of #24706 (#24706).

ai@7.0.114 filters runtimeContext and toolContext on the tracing channel by telemetry.includeRuntimeContext / includeToolsContext (vercel/ai#21447). The v7 subscriber (packages/server-utils/src/integrations/vercel-ai/vercel-ai-dc-subscriber.ts) does not read these fields yet.

Scope:

  • Set vercel.ai.settings.runtimeContext.<key> on the invoke_agent span for each key in event.runtimeContext.
  • Copy the same attributes to the child generate_content and execute_tool spans. Use the callId maps, because the child events do not carry runtimeContext.
  • Record event.toolContext on execute_tool spans.
  • Do not read these fields on ai < 7.0.114. Those versions send unfiltered context, which can contain secrets.

Done when:

  • Integration tests on ai@>=7.0.114 show that included keys are on all 3 span types and excluded keys are not.
  • A test on ai@7.0.113 (or a guard test) shows that no context attributes are set.

Open question: How do we detect the version? We can check the ai version or the event shape, or we can add a new min version for the v7 subscriber.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions