fix: update OCS langfuse integration for v4 SDK#3218
Merged
Conversation
Breaking changes in langfuse 3→4:
- FernLangfuse renamed to LangfuseAPI
- start_as_current_span() → start_as_current_observation()
- update_trace() removed; use propagate_attributes() context manager instead
(must wrap the outer observation to set session_id/user_id on root span)
- span.update(tags=...) no longer supported; use
_create_trace_tags_via_ingestion() for trace-level tags
- langfuse.api.resources.{commons,ingestion}.types namespace dropped;
now langfuse.api.{commons,ingestion}.types
Closes #3129
SmittieC
approved these changes
Apr 23, 2026
SmittieC
left a comment
Contributor
There was a problem hiding this comment.
Tested this locally and it seems to work fine
Contributor
Really? I was just testing and wasn't getting any langfuse trace links in the session |
Contributor
oh you know what, I didn't actually run |
Contributor
I'm digging into it so no need to persue |
In v4, client.get_trace_url() makes a blocking HTTP call to fetch the project_id. If that raises, TracingService's broad except used to drop the entire langfuse entry from trace_info, so ChatMessage.metadata ended up with no langfuse trace data. Isolate the URL fetch so trace_id still lands in metadata regardless. Capture the langfuse trace id via client.get_current_trace_id() on context entry and reuse it for get_trace_metadata() and add_trace_tags(). Add regression tests that exercise the TracingService -> LangFuseTracer path with a realistic mock client, including the URL-fetch failure case. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
snopoke
approved these changes
Apr 24, 2026
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.
Fixes the breaking changes introduced by the langfuse 3→4 SDK upgrade (#3129). Needs to be merged into that branch before #3129 is merged to main.
Breaking changes addressed
apps/service_providers/tracing/langfuse.pyFernLangfuseLangfuseAPIclient.start_as_current_span(...)client.start_as_current_observation(...)trace.update_trace(session_id=..., user_id=...)propagate_attributes(session_id=..., user_id=...)wrapping the observation (must be outer context so attrs land on root span)span.update(tags=tags)client._create_trace_tags_via_ingestion(trace_id=..., tags=tags)apps/service_providers/management/commands/migrate_langfuse_data.pylangfuse.api.resources.commons.typeslangfuse.api.commons.typeslangfuse.api.resources.ingestion.typeslangfuse.api.ingestion.typesWhat was NOT broken
LangfuseResourceManagerprivate API (_lock,_instances,reset()) — still intact in v4 ✅_create_client_from_instance— still intact ✅span.trace_id,client.get_trace_url()— still intact ✅langfuse.api.core.api_error.ApiError— still intact ✅IngestionEvent_*types — still inlangfuse.api.ingestion.types✅LangfuseCallbackHandler._get_parent_observation()— still intact ✅