fix(resource-manager): flush custom tracer provider if provided #1469
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
Fixes
flush()andshutdown()inresource_manager.pyto correctly flush custom tracer providers, with a type annotation added for clarity.flush()andshutdown()inresource_manager.pyto useself.tracer_providerinstead of global provider, ensuring custom tracer providers are flushed.Optional[TracerProvider]toself.tracer_provider.test_propagate_attributes.pyto correct assertion condition inget_span_by_name()to expect at least one span.This description was created by
for 00ef9a7. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Overview
Greptile Summary
Fixed
flush()andshutdown()methods to correctly flush custom tracer providers by using the storedself.tracer_providerinstance instead of calling the globalget_tracer_provider().tracer_providerwas passed to theLangfuseclient, theflush()andshutdown()methods would incorrectly attempt to flush the global tracer provider instead of the custom oneOptional[TracerProvider]toself.tracer_providerfor better code claritytracer_provideris always initializedConfidence Score: 5/5
NoneandProxyTracerProviderbefore callingforce_flush(), consistent with the existing pattern. Type annotation improvement adds clarity without changing behavior.Important Files Changed
File Analysis
flush()andshutdown()to use storedself.tracer_providerinstead of global provider, ensuring custom tracer providers are properly flushedSequence Diagram
sequenceDiagram participant Client as Langfuse Client participant RM as LangfuseResourceManager participant CustomTP as Custom TracerProvider participant GlobalTP as Global TracerProvider Note over Client,CustomTP: Initialization with Custom Tracer Provider Client->>RM: __init__(tracer_provider=CustomTP) RM->>RM: self.tracer_provider = CustomTP RM->>CustomTP: add_span_processor(LangfuseSpanProcessor) Note over Client,CustomTP: Creating and Processing Spans Client->>CustomTP: start_span() CustomTP-->>Client: span Client->>CustomTP: end_span() Note over Client,CustomTP: Before Fix - flush() called global provider Client->>RM: flush() RM->>GlobalTP: get_tracer_provider().force_flush() Note over CustomTP: Custom provider NOT flushed! Note over Client,CustomTP: After Fix - flush() uses stored provider Client->>RM: flush() RM->>RM: Check self.tracer_provider is not None RM->>CustomTP: self.tracer_provider.force_flush() CustomTP-->>RM: Spans flushed successfully Note over Client,CustomTP: Shutdown Behavior (same pattern) Client->>RM: shutdown() RM->>CustomTP: self.tracer_provider.force_flush() RM->>RM: _stop_and_join_consumer_threads()