Repository navigation
feat(#126): migrate Langfuse to JS SDK v5 for the v4 observations model - #162
Conversation
sugat009
left a comment
There was a problem hiding this comment.
Thank you for the migration. The v5 wiring is correct. I tested it against a local fake Langfuse.
Two items block the merge: index.ts:35 and index.ts:24. Both have one-click suggestions.
CI is green. With all the suggestions applied, 1023 tests pass locally.
sugat009
left a comment
There was a problem hiding this comment.
Thank you. All 7 round-1 points are fixed. I checked each one on 012d77e:
- A failed span export now logs a warning, the score still goes out, and the run keeps its exit code (0, or 2 on a rate limit).
- With no keys, or with one key only, nothing is sent.
Local gates pass: fresh npm ci, build, lint, validate-schema, and test:coverage with 1023 tests. The CI test job did not run on this head, because it runs only for PRs to main.
note (non-blocking): .env.example:66-67 sets placeholder keys (pk-lf-...). The README tells new developers to copy that file and edit only ANTHROPIC_API_KEY. The new key check then sees two keys, and tracing stays on with invalid keys. Commenting out those two lines would close this. The file is outside this diff, so I note it here.
Replace langfuse@3 (legacy batch ingestion, removed on Langfuse Cloud 2026-11-16) with @langfuse/tracing, @langfuse/otel and @langfuse/client over OpenTelemetry. - withTrace propagates session id, tags and metadata to every observation, including generations, so session cost aggregates work - overall input/output live on the root observation - scores go through LangfuseClient; one shutdown flushes spans and scores - metadata values are strings per the v5 propagation contract Verified with a live API-path run: trace, session, score, token usage and inferred cost all ingested.
Tracing now stays off when LANGFUSE_PUBLIC_KEY or LANGFUSE_SECRET_KEY is unset, so spans with prompt text are not sent unauthenticated. shutdownLangfuse() logs span and score flush failures instead of rejecting. The unused client timeout is dropped and the docs now state the 60 s SDK default for scores.
Co-authored-by: Sugat Bajracharya <30311933+sugat009@users.noreply.github.com>
987f66c to
5b7e01f
Compare
Description
Stacked on #127: migrates the Langfuse tracing added there from the legacy
langfusev3 npm package to the OpenTelemetry-based JS SDK v5 (@langfuse/tracing,@langfuse/otel,@langfuse/client), targeting Langfuse's v4 observations-first data model. The legacy batch-ingestion API that v3 uses is removed from Langfuse Cloud on 2026-11-16.src/observabilitynow exposeswithTrace,observeGeneration,scoreTrace, andshutdownLangfuse. Session id, tags, and metadata are propagated to every observation, so session and tag aggregations include generation cost.usageDetailson the API path andcostDetailson the Claude CLI path.@langfuse/clientdefault of 60s (5.11.1 ignores itstimeoutoption). Langfuse is shut down once per run, and flush failures only log a warning.LANGFUSE_PUBLIC_KEYandLANGFUSE_SECRET_KEYare both set.docs/observability.mdis updated for the new API.Verification:
distill-outcomescore, token usage, and inferred cost all arrived.Part of the #127 → #162 → #163 stack; merge after #127.
#126
Code review checklist
License
The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.