fix(client): set AS_ROOT attribute to False in Langfuse remote span context #1266
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.
When using multi-level span with SDK v3, with remote parent span (pass
langfuse_trace_id
andlangfuse_parent_observation_id
), the trace input and output reflects the input and output of the latest executed span (the inner one). This creates opposite default behavior to what is written in the documentation and how it behaves if they are not passed:I reproduced the issue with the following code on version
3.2.1
:Following a trace and an activity examples with the issue:


And here a trace example after the fix:

Important
Sets
AS_ROOT
toFalse
for remote parent spans inclient.py
, fixing trace input/output behavior for multi-level spans.LangfuseOtelSpanAttributes.AS_ROOT
toFalse
in_create_span_with_parent_context()
inclient.py
for remote parent spans.This description was created by
for d9eaf51. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Summary
This PR fixes a critical behavioral inconsistency in the Python SDK v3 related to trace input/output handling when using remote parent spans. The change modifies how the
AS_ROOT
attribute is set in the OpenTelemetry span context.Specifically, when using remote parent spans (by passing
langfuse_trace_id
andlangfuse_parent_observation_id
), the trace was incorrectly using the input/output from the most recently executed (innermost) span instead of the root span. This behavior contradicted both the documentation and the intended v3 API design, which specifies that trace input/output should be automatically set from the root observation.The fix involves setting
AS_ROOT
toFalse
in the Langfuse remote span context, ensuring consistent behavior between remote and local span tracking.Confidence score: 5/5
langfuse/_client/client.py
- verify the AS_ROOT attribute setting logic