chore: migrate demo chatbot to AI SDK 7 with LangfuseVercelAiSdkIntegration#3247
Open
hassiebp wants to merge 1 commit into
Open
chore: migrate demo chatbot to AI SDK 7 with LangfuseVercelAiSdkIntegration#3247hassiebp wants to merge 1 commit into
hassiebp wants to merge 1 commit into
Conversation
…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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@claude review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrates the demo QA chatbot (and the other AI SDK consumers in this repo) to AI SDK 7, using the new
LangfuseVercelAiSdkIntegrationfrom@langfuse/vercel-ai-sdkfor tracing.Changes
package.json: bumpaito ^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 viaregisterTelemetry(new LangfuseVercelAiSdkIntegration()); the existing multi-regionLangfuseSpanProcessorsetup is unchangedcomponents/qaChatbot/apiHandler.ts: replaceexperimental_telemetrywith v7's callback-based telemetry — the Langfuse prompt is linked viaruntimeContext.langfusePrompt+telemetry.includeRuntimeContext.langfusePrompt: true, andtelemetry.functionId: "qa-chatbot"names the agent spancomponents/sentimentClassifier/apiHandler.ts: same swap; telemetry is on by default once an integration is registered, so it only setsfunctionIdapp/api/chat/route.ts(Inkeep proxy): explicittelemetry: { 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 projectsVerification
tsc --noEmit: zero errors in touched files (remaining 54 are pre-existing fumadocs generated-types errors)POST /api/qa-chatbotexecutes the full new code path, failing only at the Langfuse prompt fetch with 401 (no credentials in the local workspace — expected)langfuse.observation.prompt.name/version(prompt linking works) and the agent span carriesgen_ai.agent.name: "qa-chatbot"pnpm run formatpassesPost-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/metadataapproach with AI SDK 7's callback-based telemetry system viaLangfuseVercelAiSdkIntegration. All Langfuse packages are aligned to 5.9.1, and the multi-region OTel span processor setup is preserved unchanged.src/instrumentation.ts: AddsregisterTelemetry(new LangfuseVercelAiSdkIntegration())after the existingtracerProvider.register()call; the integration is a thin OTel enrichment layer (no separate exporter — no duplicate spans) that enables prompt linking andfunctionId-based agent naming for the span processor.components/qaChatbot/apiHandler.ts&components/sentimentClassifier/apiHandler.ts: Swapexperimental_telemetryfor v7'stelemetry+runtimeContext; the QA chatbot passes the liveLangfusePromptobject (nottoJSON()) viaruntimeContext.langfusePromptwithincludeRuntimeContext: { langfusePrompt: true }, which the integration uses for prompt version linking.app/api/chat/route.ts(Inkeep proxy): Addstelemetry: { 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%%{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 emittedReviews (1): Last reviewed commit: "feat: migrate demo chatbot to AI SDK 7 w..." | Re-trigger Greptile