Skip to content

docs: fix invalid langfuse.trace() context manager in OTel setup guide#3092

Open
i-anubhav-anand wants to merge 1 commit into
langfuse:mainfrom
i-anubhav-anand:docs/fix-otel-setup-trace-api
Open

docs: fix invalid langfuse.trace() context manager in OTel setup guide#3092
i-anubhav-anand wants to merge 1 commit into
langfuse:mainfrom
i-anubhav-anand:docs/fix-otel-setup-trace-api

Conversation

@i-anubhav-anand

@i-anubhav-anand i-anubhav-anand commented Jun 14, 2026

Copy link
Copy Markdown

What does this PR do?

The Python tab in the "Set trace-level data explicitly" section of the Using Langfuse with an existing OpenTelemetry setup FAQ page showed:

with langfuse.trace(name="my-operation", user_id="user-123", session_id="session-456") as trace:
    # Your code here

This is not valid: langfuse.trace() does not exist in the v3/v4 Python SDK and was never a context manager, so anyone copying the snippet hits an AttributeError. The rest of the page already uses the v4 API (the JS/TS tab uses propagateAttributes).

This PR replaces it with the canonical v4 propagate_attributes() context manager, which is the documented replacement for update_current_trace() per the v3-to-v4 migration guide (nametrace_name), and mirrors the JS/TS tab on the same page:

from langfuse import propagate_attributes

with propagate_attributes(trace_name="my-operation", user_id="user-123", session_id="session-456"):
    # Your code here

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • This change requires a documentation update

Checklist

  • Self-reviewed the change
  • Single hand-authored MDX file (not a generated cookbook page)

Greptile Summary

Fixes a broken Python code snippet in the "Set trace-level data explicitly" section of the existing-OTel-setup FAQ by replacing the non-existent langfuse.trace() context manager with the correct v4 propagate_attributes() API.

  • Replaces langfuse.trace(name=...) — which does not exist in the v3/v4 SDK — with from langfuse import propagate_attributes followed by propagate_attributes(trace_name=..., user_id=..., session_id=...), matching the documented v4 migration path.
  • The fix now mirrors the JS/TS tab on the same page that already used propagateAttributes.

Confidence Score: 5/5

Single-file documentation fix replacing a non-functional Python snippet with the correct v4 API call — no runtime code is touched and the change is straightforwardly correct.

The replacement uses the right function name (propagate_attributes), the right parameter (trace_name instead of name), includes the necessary import at the top of the snippet, and matches both the JS/TS counterpart on the same page and the official v3→v4 migration guide. No logic, no runtime behavior, and no other files are affected.

No files require special attention.

Sequence Diagram

sequenceDiagram
    participant User as Developer
    participant SDK as Langfuse v4 SDK
    participant OTel as OpenTelemetry

    User->>SDK: propagate_attributes(trace_name, user_id, session_id)
    SDK->>OTel: Set trace-level attributes on active span context
    OTel-->>SDK: Context propagated
    SDK-->>User: Context manager yields
    User->>OTel: Instrumented code runs within context
    OTel-->>SDK: Spans captured with propagated attributes
    SDK-->>User: Trace visible in Langfuse with correct metadata
Loading

Reviews (1): Last reviewed commit: "docs: fix invalid langfuse.trace() conte..." | Re-trigger Greptile

The Python tab in the existing-OTel-setup guide showed
`with langfuse.trace(...) as trace:`, which is not a valid Python SDK API
(`langfuse.trace()` does not exist in v3/v4 and was never a context manager),
so the snippet raises AttributeError if copied.

Replace it with the canonical `propagate_attributes()` context manager, which
mirrors the JS/TS tab's `propagateAttributes` and matches the v3-to-v4
migration guide (`name` -> `trace_name`).

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@vercel

vercel Bot commented Jun 14, 2026

Copy link
Copy Markdown

@i-anubhav-anand is attempting to deploy a commit to the langfuse Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 14, 2026
@CLAassistant

CLAassistant commented Jun 14, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@dosubot dosubot Bot added bug Something isn't working docs labels Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working docs size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants