Repository navigation
fix(tracing): record provider stream failures in Langfuse - #4875
Merged
Merged
Conversation
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.
Description
When a provider emits a
ResponseTypeErrorchunk,langfuseChat.ChatStreamforwards the error to its caller but finishes the Langfuse generation with a nil error. A failed model call therefore has no error status in tracing, even though the same failure is visible to the user and the debug wrapper.Retain the stream error and pass it to
Generation.Finish, matching the debug wrapper's handling. Keep partial output, usage and all forwarded chunks unchanged. Production changes are confined to the tracing decorator; no protocol, configuration or API changes.Type of Change
Related Issue
Found during source review; no separate issue. Searched open/closed issues and PRs for Langfuse stream error, generation error and tracing. No direct duplicate found; #3529 adds request metadata rather than stream error handling.
This is independent of #4872, which changes cancellation handling in the outer concurrency decorator. There are no shared files or required merge order; this fix also works with the current main's concurrency wrapper.
Testing
Windows/amd64, CGO enabled with existing portable GCC/G++.
go test -race ./internal/models/chat ./internal/tracing/langfuse -count=1 -timeout=90spasses on Go 1.26.0; Go 1.27.0 also passed before adding the output/usage assertions.golangci-lint run --new-from-rev=origin/main ./internal/models/chat/...passes with CI-pinned v2.12.2 on Go 1.26.0 (0 issues).No real Langfuse instance, provider API or full-repository checks were used. The regression uses the existing OTLP/protobuf dependencies and does not change go.mod.
Checklist
git diff --check origin/main...HEADpassesPrepared with AI assistance.