Skip to content

Conversation

@maxdeichmann
Copy link
Member

@maxdeichmann maxdeichmann commented Sep 17, 2025

Important

Adds propagate_attributes() for attribute propagation and integrates it into trace updates, with minor test modifications.

  • New Functionality:
    • Adds propagate_attributes() in attribute_propagation.py to propagate attributes from a dictionary to a span and context.
  • Integration:
    • Integrates propagate_attributes() in update_trace() in span.py to propagate trace attributes.
  • Code Cleanup:
    • Removes commented-out code in _create_observation_from_otel_span() in client.py.
  • Tests:
    • Modifies test_score_trace_nested_observation() in test_core_sdk.py by commenting out assertions related to trace verification.

This description was created by Ellipsis 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.py module 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:

  1. New Baggage Propagation Module: The attribute_propagation.py file implements a propagate_attributes function that converts dictionary attributes to string values and sets them as OpenTelemetry baggage items, making them accessible across span contexts.

  2. Span Update Integration: The update_trace method in LangfuseObservationWrapper now calls propagate_attributes to automatically propagate trace attributes when traces are updated, ensuring child spans have access to parent trace context.

  3. Test Modifications: The test suite has been updated to use the new parent-child span relationship pattern (parent_span.start_span() instead of langfuse.start_span()) and includes metadata propagation testing, though verification assertions are temporarily disabled.

  4. 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:

  • The pull request lacks a meaningful title (just "push") and has no description, making it difficult to understand the intended purpose and scope of changes.

Confidence score: 2/5

  • This PR has significant issues that make it unsafe to merge in its current state
  • Score lowered due to debug print statements that will spam production logs, disabled test assertions, and lack of error handling in critical propagation logic
  • Pay close attention to langfuse/_client/attribute_propagation.py and langfuse/_client/span.py for production-breaking debug output

Context 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)

@maxdeichmann maxdeichmann changed the title push baggage prop Sep 17, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, 1 comment

Edit Code Review Bot Settings | Greptile



for key, value in dict_to_propagate.items():
print(f"Propagating attribute {key} with value {value}")
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Debug print statement will expose potentially sensitive trace data in production logs - should be removed or wrapped in a debug check

Suggested change
print(f"Propagating attribute {key} with value {value}")
# Debug logging removed to prevent exposure of sensitive trace data

@Steffen911
Copy link
Member

Replaced by #1349

@Steffen911 Steffen911 closed this Sep 17, 2025
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