Skip to content

fix: update OCS langfuse integration for v4 SDK#3218

Merged
snopoke merged 2 commits into
dependabot/uv/langfuse-4.0.4from
fix/langfuse-v4-upgrade
Apr 24, 2026
Merged

fix: update OCS langfuse integration for v4 SDK#3218
snopoke merged 2 commits into
dependabot/uv/langfuse-4.0.4from
fix/langfuse-v4-upgrade

Conversation

@ocs-percy

Copy link
Copy Markdown
Collaborator

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.py

v3 v4
FernLangfuse LangfuseAPI
client.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.py

v3 v4
langfuse.api.resources.commons.types langfuse.api.commons.types
langfuse.api.resources.ingestion.types langfuse.api.ingestion.types

What was NOT broken

  • LangfuseResourceManager private 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 ✅
  • All IngestionEvent_* types — still in langfuse.api.ingestion.types
  • LangfuseCallbackHandler._get_parent_observation() — still intact ✅

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
Comment thread apps/service_providers/tracing/langfuse.py Outdated

@SmittieC SmittieC left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this locally and it seems to work fine

@snopoke

snopoke commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Tested this locally and it seems to work fine

Really? I was just testing and wasn't getting any langfuse trace links in the session

@SmittieC

Copy link
Copy Markdown
Contributor

Tested this locally and it seems to work fine

Really? I was just testing and wasn't getting any langfuse trace links in the session

oh you know what, I didn't actually run uv sync when I checked out the branch 🤭

@snopoke

snopoke commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Tested this locally and it seems to work fine

Really? I was just testing and wasn't getting any langfuse trace links in the session

oh you know what, I didn't actually run uv sync when I checked out the branch 🤭

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 snopoke merged commit a2cf976 into dependabot/uv/langfuse-4.0.4 Apr 24, 2026
11 checks passed
@snopoke snopoke deleted the fix/langfuse-v4-upgrade branch April 24, 2026 04:55
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.

3 participants