feat(langfuse): add opt-in Langfuse observability integration

Add Langfuse as an OTel trace transport for MCP request lifecycle tracking.

Changes:
- New src/lib/langfuse-transport.ts: initializes LangfuseSpanProcessor when
  ASK262_LANGFUSE_ENABLED=true with valid credentials
- src/lib/tracing.ts: add metadata to TraceContext, propagate it to child spans,
  use startActiveSpan for proper OTel context, add setupTracing() entry point,
  add getSessionMetadata() for version/transport metadata
- src/lib/logger.ts: include TraceContext.metadata in JSON log mixin
- src/mcp-server-{http,stdio}.ts: call setupTracing() at startup, pass
  version/transport metadata through withSpan/withSpanContext
- src/lib/fireworks-embeddings.ts: wrap API calls in withSpan() with gen_ai
  attributes for Langfuse generation/cost tracking
- .env.example: add LANGFUSE_* configuration variables
- AGENTS.md: document Langfuse integration
- package.json: add @langfuse/tracing, @langfuse/otel, @opentelemetry/sdk-node
This commit is contained in:
2026-04-27 18:31:19 +05:30
parent 40b439307e
commit 627b80008e
9 changed files with 466 additions and 97 deletions
+6
View File
@@ -61,6 +61,8 @@ Copy `.env.example` to `.env`:
- `OLLAMA_HOST` - Ollama URL (default: http://localhost:11434)
- `ASK262_PORT` - HTTP server port (default: 8081)
- `MCP_PUBLIC_URL` - Public URL for inspector
- `ASK262_LANGFUSE_ENABLED` - Enable Langfuse tracing (optional)
- `LANGFUSE_PUBLIC_KEY` / `LANGFUSE_SECRET_KEY` - Langfuse credentials (required when enabled)
## Key Dependencies
@@ -76,3 +78,7 @@ Copy `.env.example` to `.env`:
- Run `bun run type-check` before committing
- Ingest/build are slow (local embedding generation)
- Don't lint/format external dirs (`engine262/`, `spec-built/`, `graphology/`)
## Observability
Ask262 uses OpenTelemetry for tracing. When `ASK262_LANGFUSE_ENABLED=true` is set with valid Langfuse credentials, all OTel spans are exported to Langfuse automatically. No code changes are needed — it's purely a transport configuration. Metadata (version, transport type) is attached to every trace and included in both Langfuse and JSON logs.