Skip to content

chore: migrate demo chatbot to AI SDK 7 with LangfuseVercelAiSdkIntegration#3247

Open
hassiebp wants to merge 1 commit into
mainfrom
migrate-chatbot-ai-sdk-v7
Open

chore: migrate demo chatbot to AI SDK 7 with LangfuseVercelAiSdkIntegration#3247
hassiebp wants to merge 1 commit into
mainfrom
migrate-chatbot-ai-sdk-v7

Conversation

@hassiebp

@hassiebp hassiebp commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Migrates the demo QA chatbot (and the other AI SDK consumers in this repo) to AI SDK 7, using the new LangfuseVercelAiSdkIntegration from @langfuse/vercel-ai-sdk for tracing.

Changes

  • package.json: bump ai to ^7.0.16 and matching provider packages (@ai-sdk/openai ^4, @ai-sdk/react ^4, @ai-sdk/mcp ^2, @ai-sdk/openai-compatible ^3); add @langfuse/vercel-ai-sdk@5.9.1; align all @langfuse/* packages to 5.9.1 (the integration requires @langfuse/core ^5.9.1 — mixed versions would create duplicate core instances)
  • src/instrumentation.ts: register the integration once at startup via registerTelemetry(new LangfuseVercelAiSdkIntegration()); the existing multi-region LangfuseSpanProcessor setup is unchanged
  • components/qaChatbot/apiHandler.ts: replace experimental_telemetry with v7's callback-based telemetry — the Langfuse prompt is linked via runtimeContext.langfusePrompt + telemetry.includeRuntimeContext.langfusePrompt: true, and telemetry.functionId: "qa-chatbot" names the agent span
  • components/sentimentClassifier/apiHandler.ts: same swap; telemetry is on by default once an integration is registered, so it only sets functionId
  • app/api/chat/route.ts (Inkeep proxy): explicit telemetry: { isEnabled: false } — AI SDK 7 traces every call by default after registration, and this previously untraced route would otherwise send Inkeep search chats to the public demo Langfuse projects

Verification

  • tsc --noEmit: zero errors in touched files (remaining 54 are pre-existing fumadocs generated-types errors)
  • Dev server boots; POST /api/qa-chatbot executes the full new code path, failing only at the Langfuse prompt fetch with 401 (no credentials in the local workspace — expected)
  • Standalone script with a mock model + in-memory span exporter confirms the integration emits Langfuse-shaped spans: the generation span carries langfuse.observation.prompt.name/version (prompt linking works) and the agent span carries gen_ai.agent.name: "qa-chatbot"
  • pnpm run format passes

Post-deploy check

Local verification stops at the auth boundary; after deploy with real keys, confirm prompt links and trace I/O look right in the demo Langfuse projects.

🤖 Generated with Claude Code

Greptile Summary

This PR migrates all AI SDK consumers in the docs repo from v6 to v7, replacing the deprecated experimental_telemetry / metadata approach with AI SDK 7's callback-based telemetry system via LangfuseVercelAiSdkIntegration. All Langfuse packages are aligned to 5.9.1, and the multi-region OTel span processor setup is preserved unchanged.

  • src/instrumentation.ts: Adds registerTelemetry(new LangfuseVercelAiSdkIntegration()) after the existing tracerProvider.register() call; the integration is a thin OTel enrichment layer (no separate exporter — no duplicate spans) that enables prompt linking and functionId-based agent naming for the span processor.
  • components/qaChatbot/apiHandler.ts & components/sentimentClassifier/apiHandler.ts: Swap experimental_telemetry for v7's telemetry + runtimeContext; the QA chatbot passes the live LangfusePrompt object (not toJSON()) via runtimeContext.langfusePrompt with includeRuntimeContext: { langfusePrompt: true }, which the integration uses for prompt version linking.
  • app/api/chat/route.ts (Inkeep proxy): Adds telemetry: { isEnabled: false } to prevent the now-default auto-tracing from capturing Inkeep search traffic into the public Langfuse projects.

Confidence Score: 5/5

The migration correctly replaces the deprecated experimental_telemetry API with AI SDK v7's callback-based telemetry across all three affected routes; the Inkeep proxy is correctly opted out, and the multi-region OTel export pipeline is left untouched.

All AI SDK call sites are updated and accounted for. The LangfuseVercelAiSdkIntegration is a span-enrichment layer, not a second exporter, so the existing LangfuseSpanProcessor setup does not produce duplicate traces. Package versions are internally consistent. No functional changes to request handling, rate limiting, or error paths.

No files require special attention. The pnpm-lock.yaml is auto-generated and consistent with the package.json bumps.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Route as Next.js Route Handler
    participant SDK as AI SDK v7 (streamText/generateObject)
    participant Integ as LangfuseVercelAiSdkIntegration
    participant OTel as NodeTracerProvider
    participant SP as LangfuseSpanProcessor (x4 regions)
    participant LF as Langfuse API

    Note over Route,LF: Startup (instrumentation.ts)
    OTel->>SP: register span processors (EU/US/JP/internal)
    Integ-->>SDK: registerTelemetry()

    Note over Route,LF: Request time
    Route->>SDK: streamText with runtimeContext and telemetry
    SDK->>Integ: enrichSpan hook adds prompt.name/version, gen_ai.agent.name
    SDK->>OTel: emit ai.streamText spans (enriched)
    OTel->>SP: onStart / onEnd spans
    SP->>LF: export to each Langfuse project

    Note over Route,LF: Inkeep proxy (telemetry disabled)
    Route->>SDK: streamText with isEnabled false
    SDK--xInteg: no callbacks fired
    SDK--xOTel: no spans emitted
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Route as Next.js Route Handler
    participant SDK as AI SDK v7 (streamText/generateObject)
    participant Integ as LangfuseVercelAiSdkIntegration
    participant OTel as NodeTracerProvider
    participant SP as LangfuseSpanProcessor (x4 regions)
    participant LF as Langfuse API

    Note over Route,LF: Startup (instrumentation.ts)
    OTel->>SP: register span processors (EU/US/JP/internal)
    Integ-->>SDK: registerTelemetry()

    Note over Route,LF: Request time
    Route->>SDK: streamText with runtimeContext and telemetry
    SDK->>Integ: enrichSpan hook adds prompt.name/version, gen_ai.agent.name
    SDK->>OTel: emit ai.streamText spans (enriched)
    OTel->>SP: onStart / onEnd spans
    SP->>LF: export to each Langfuse project

    Note over Route,LF: Inkeep proxy (telemetry disabled)
    Route->>SDK: streamText with isEnabled false
    SDK--xInteg: no callbacks fired
    SDK--xOTel: no spans emitted
Loading

Reviews (1): Last reviewed commit: "feat: migrate demo chatbot to AI SDK 7 w..." | Re-trigger Greptile

…ation

Upgrade ai to v7 and matching @ai-sdk/* packages, align all @langfuse/*
packages to 5.9.1, and add @langfuse/vercel-ai-sdk. Tracing now uses the
callback-based telemetry system: the integration is registered once in
instrumentation.ts, prompt linking flows through runtimeContext, and the
Inkeep proxy route explicitly opts out to stay untraced.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 6, 2026
@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
langfuse-docs Ready Ready Preview, Comment Jul 6, 2026 4:42pm

Request Review

@dosubot dosubot Bot added dependencies Pull requests that update a dependency file enhancement New feature or request labels Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

@claude review

@hassiebp hassiebp changed the title Migrate demo chatbot to AI SDK 7 with LangfuseVercelAiSdkIntegration chore: migrate demo chatbot to AI SDK 7 with LangfuseVercelAiSdkIntegration Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file enhancement New feature or request size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant