Skip to content

Conversation

@hassiebp
Copy link
Contributor

@hassiebp hassiebp commented Dec 3, 2025

Important

Define tracer_provider as None in resource_manager.py when tracing_enabled=False to prevent attribute errors.

  • Behavior:
    • Define self.tracer_provider as None in _initialize_instance() in resource_manager.py when tracing_enabled=False to prevent attribute errors.
  • Misc:
    • No changes to existing logic or functionality beyond defining tracer_provider when tracing is disabled.

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

Disclaimer: Experimental PR review

Greptile Overview

Greptile Summary

This PR fixes an AttributeError that occurred when tracing_enabled=False by explicitly initializing self.tracer_provider = None before the conditional block.

Key Changes:

  • Added self.tracer_provider = None at line 176 in _initialize_instance() method
  • Previously, when tracing_enabled=False, the tracer_provider attribute was never defined since it was only set inside the if tracing_enabled: block
  • This caused an AttributeError when get_client() tried to access instance.tracer_provider (line 55 in get_client.py)

Impact:

  • Ensures the attribute always exists regardless of the tracing configuration
  • Allows safe access to tracer_provider attribute in multi-client scenarios where clients with different tracing settings may coexist
  • No functional changes to the tracing behavior itself

Confidence Score: 5/5

  • This PR is safe to merge - it's a minimal defensive fix that prevents AttributeError
  • The change is a one-line defensive fix that explicitly initializes an attribute to None, preventing AttributeError when accessing it later. The fix follows Python best practices by ensuring all instance attributes are defined in init regardless of conditional logic. No logical changes to existing behavior, only prevents potential runtime errors.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
langfuse/_client/resource_manager.py 5/5 Initializes tracer_provider to None before conditional assignment, preventing AttributeError when tracing_enabled=False

Sequence Diagram

sequenceDiagram
    participant Client as Langfuse Client
    participant RM as LangfuseResourceManager
    participant GC as get_client()
    
    Note over Client,RM: Initialization Flow
    Client->>RM: __new__(tracing_enabled=False)
    RM->>RM: _initialize_instance()
    RM->>RM: Set self.tracer_provider = None
    Note over RM: BEFORE FIX: AttributeError if<br/>tracing_enabled=False and<br/>tracer_provider accessed later
    Note over RM: AFTER FIX: Always defined,<br/>set to None initially
    alt tracing_enabled=True
        RM->>RM: Initialize tracer_provider
        RM->>RM: Set self.tracer_provider = tracer_provider
    else tracing_enabled=False
        Note over RM: tracer_provider remains None
    end
    
    Note over GC: Later Access
    GC->>RM: Access instance.tracer_provider
    RM-->>GC: Returns None (no AttributeError)
    GC->>Client: Create new client with tracer_provider=None
Loading

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 7e8f070 into main Dec 3, 2025
12 checks passed
@hassiebp hassiebp deleted the hassieb/lfe-7944-bug-langfuseresourcemanager-object-has-no-attribute branch December 3, 2025 17:48
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: 'LangfuseResourceManager' object has no attribute 'tracer_provider'

2 participants