Skip to content

Conversation

@DayuanJiang
Copy link
Owner

@DayuanJiang DayuanJiang commented Dec 3, 2025

Summary

Add optional Langfuse observability integration for LLM tracing and analytics.

Features

  • Session tracking with unique sessionId per conversation (resets on clear)
  • User tracking via IP address (x-forwarded-for header)
  • Fully optional - only enabled if LANGFUSE_PUBLIC_KEY env var is set
  • Zero overhead for users who don't use Langfuse

Changes

  • Add instrumentation.ts with LangfuseSpanProcessor setup
  • Add experimental_telemetry to streamText calls (conditional)
  • Add sessionId state management in chat-panel.tsx
  • Add environment variable validation
  • Update env.example with Langfuse configuration docs

Setup (Optional)

# Add to .env.local
LANGFUSE_PUBLIC_KEY=pk-lf-...
LANGFUSE_SECRET_KEY=sk-lf-...
LANGFUSE_BASEURL=https://cloud.langfuse.com  # EU region
# or https://us.cloud.langfuse.com for US

Test Plan

  • Verify telemetry works with Langfuse configured
  • Verify no errors when Langfuse is not configured
  • Verify session resets on clear conversation
  • Code reviewed by 3 agents

- Add instrumentation.ts with Langfuse OpenTelemetry exporter
- Enable experimental telemetry on streamText calls
- Add instrumentationHook to Next.js config
- Install required dependencies (@vercel/otel, langfuse-vercel, etc.)
@vercel
Copy link

vercel bot commented Dec 3, 2025

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

Project Deployment Preview Comments Updated (UTC)
next-ai-draw-io Ready Ready Preview Comment Dec 3, 2025 3:17pm

- Add session tracking with unique sessionId per conversation
- Add user tracking via IP address (x-forwarded-for header)
- Make telemetry conditional - only enabled if LANGFUSE_PUBLIC_KEY is set
- Add environment variable validation in instrumentation.ts
- Add sessionId validation (type check + 200 char limit)
- Update env.example with Langfuse configuration docs
- Remove unused langfuse-vercel and @vercel/otel packages
@DayuanJiang DayuanJiang merged commit fa1b02a into main Dec 3, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants