Skip to content

Conversation

@hassiebp
Copy link
Contributor

@hassiebp hassiebp commented Nov 11, 2025

Important

Add check in update_current_trace() in client.py to ensure updates only occur on recording spans.

  • Behavior:
    • In update_current_trace() in client.py, add check for current_otel_span.is_recording() to ensure updates only occur on recording spans.
  • Misc:
    • No changes to function signatures or additional functionality added.

This description was created by Ellipsis for 04877ec. You can customize this summary. It will automatically update as commits are pushed.

Disclaimer: Experimental PR review

Greptile Overview

Greptile Summary

Added defensive check to prevent accessing attributes on non-recording OpenTelemetry spans in the update_current_trace method.

  • Previously, the code would attempt to access current_otel_span.attributes.get() on line 1668 without checking if the span was recording
  • In OpenTelemetry, non-recording spans (e.g., sampled-out spans) don't allow attribute access and would cause errors
  • The fix adds and current_otel_span.is_recording() to the conditional check, consistent with similar patterns used elsewhere in the codebase (e.g., langfuse/_client/span.py:240, langfuse/_client/propagation.py:358)

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is a simple defensive check that follows established patterns in the codebase. It prevents a potential error when accessing attributes on non-recording spans, making the code more robust without changing any functional behavior for recording spans.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
langfuse/_client/client.py 5/5 Added is_recording() check to prevent attribute access on non-recording spans in update_current_trace

Sequence Diagram

sequenceDiagram
    participant User
    participant Langfuse
    participant OtelSpan
    participant SpanWrapper
    
    User->>Langfuse: update_current_trace()
    Langfuse->>Langfuse: Check _tracing_enabled
    alt Tracing disabled
        Langfuse-->>User: Return early
    end
    
    Langfuse->>Langfuse: _get_current_otel_span()
    Langfuse->>OtelSpan: Check is not None
    Langfuse->>OtelSpan: is_recording()
    
    alt Span is recording
        OtelSpan-->>Langfuse: true
        Langfuse->>OtelSpan: attributes.get()
        OtelSpan-->>Langfuse: observation_type
        Langfuse->>Langfuse: _get_span_class()
        Langfuse->>SpanWrapper: Create wrapper instance
        Langfuse->>SpanWrapper: update_trace()
        SpanWrapper-->>Langfuse: Success
    else Span not recording
        OtelSpan-->>Langfuse: false
        Note over Langfuse: Skip update (no error)
    end
    
    Langfuse-->>User: Return
Loading

@hassiebp hassiebp enabled auto-merge (squash) November 11, 2025 09:30
@hassiebp hassiebp linked an issue Nov 11, 2025 that may be closed by this pull request
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.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@hassiebp hassiebp merged commit d8c624a into main Nov 11, 2025
12 checks passed
@hassiebp hassiebp deleted the fix-update-current-trace-recording branch November 11, 2025 09:37
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.

bug(sdk-python):

2 participants