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.
Important
Adds
propagate_attributes()for attribute propagation and integrates it into trace updates, with minor test modifications.propagate_attributes()inattribute_propagation.pyto propagate attributes from a dictionary to a span and context.propagate_attributes()inupdate_trace()inspan.pyto propagate trace attributes._create_observation_from_otel_span()inclient.py.test_score_trace_nested_observation()intest_core_sdk.pyby commenting out assertions related to trace verification.This description was created by
for 82bd844. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Summary
Updated On: 2025-09-17 07:34:44 UTC
This PR implements baggage propagation functionality in the Langfuse Python SDK, allowing trace-level attributes to be propagated across OpenTelemetry contexts. The implementation introduces a new
attribute_propagation.pymodule that uses OpenTelemetry's baggage mechanism to share trace attributes (like user_id, session_id, metadata, etc.) between parent and child spans in distributed tracing scenarios.The key changes include:
New Baggage Propagation Module: The
attribute_propagation.pyfile implements apropagate_attributesfunction that converts dictionary attributes to string values and sets them as OpenTelemetry baggage items, making them accessible across span contexts.Span Update Integration: The
update_tracemethod inLangfuseObservationWrappernow callspropagate_attributesto automatically propagate trace attributes when traces are updated, ensuring child spans have access to parent trace context.Test Modifications: The test suite has been updated to use the new parent-child span relationship pattern (
parent_span.start_span()instead oflangfuse.start_span()) and includes metadata propagation testing, though verification assertions are temporarily disabled.Code Cleanup: Removed obsolete commented code from the observation creation flow that was no longer needed after refactoring how span attributes are managed.
This feature enables better trace context management in distributed systems by ensuring that important trace-level metadata is automatically available to all observations within a trace hierarchy, following OpenTelemetry standards for context propagation.
PR Description Notes:
Confidence score: 2/5
langfuse/_client/attribute_propagation.pyandlangfuse/_client/span.pyfor production-breaking debug outputContext used:
Rule - Open a GitHub issue or discussion first before submitting PRs to explain the rationale and necessity of the proposed changes, as required by the contributing guide. (link)