fix(resource_manager): define tracer_provider if tracing_enabled=False #1465
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
Define
tracer_providerasNoneinresource_manager.pywhentracing_enabled=Falseto prevent attribute errors.self.tracer_providerasNonein_initialize_instance()inresource_manager.pywhentracing_enabled=Falseto prevent attribute errors.tracer_providerwhen tracing is disabled.This description was created by
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
AttributeErrorthat occurred whentracing_enabled=Falseby explicitly initializingself.tracer_provider = Nonebefore the conditional block.Key Changes:
self.tracer_provider = Noneat line 176 in_initialize_instance()methodtracing_enabled=False, thetracer_providerattribute was never defined since it was only set inside theif tracing_enabled:blockAttributeErrorwhenget_client()tried to accessinstance.tracer_provider(line 55 inget_client.py)Impact:
tracer_providerattribute in multi-client scenarios where clients with different tracing settings may coexistConfidence Score: 5/5
Important Files Changed
File Analysis
tracer_providertoNonebefore conditional assignment, preventing AttributeError whentracing_enabled=FalseSequence 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