fix(client): handle update_current_trace on non recorded spans gracefully#1432
Merged
fix(client): handle update_current_trace on non recorded spans gracefully#1432
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Add check in
update_current_trace()inclient.pyto ensure updates only occur on recording spans.update_current_trace()inclient.py, add check forcurrent_otel_span.is_recording()to ensure updates only occur on recording spans.This description was created by
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_tracemethod.current_otel_span.attributes.get()on line 1668 without checking if the span was recordingand 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
Important Files Changed
File Analysis
is_recording()check to prevent attribute access on non-recording spans inupdate_current_traceSequence 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