Skip to content

Conversation

@hassiebp
Copy link
Contributor

@hassiebp hassiebp commented Dec 8, 2025

Important

Fixes flush() and shutdown() in resource_manager.py to correctly flush custom tracer providers, with a type annotation added for clarity.

  • Behavior:
    • Fixes flush() and shutdown() in resource_manager.py to use self.tracer_provider instead of global provider, ensuring custom tracer providers are flushed.
    • Adds type annotation Optional[TracerProvider] to self.tracer_provider.
  • Tests:
    • Updates test_propagate_attributes.py to correct assertion condition in get_span_by_name() to expect at least one span.

This description was created by Ellipsis 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() and shutdown() methods to correctly flush custom tracer providers by using the stored self.tracer_provider instance instead of calling the global get_tracer_provider().

  • Previously, when a custom tracer_provider was passed to the Langfuse client, the flush() and shutdown() methods would incorrectly attempt to flush the global tracer provider instead of the custom one
  • This change ensures that the custom tracer provider passed during initialization is properly flushed and shut down
  • Added type annotation Optional[TracerProvider] to self.tracer_provider for better code clarity
  • The fix complements the previous PR fix(resource_manager): define tracer_provider if tracing_enabled=False #1465 which ensured tracer_provider is always initialized

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The changes are straightforward and correct a clear bug where custom tracer providers weren't being flushed. The implementation properly checks for None and ProxyTracerProvider before calling force_flush(), consistent with the existing pattern. Type annotation improvement adds clarity without changing behavior.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
langfuse/_client/resource_manager.py 5/5 Fixed flush() and shutdown() to use stored self.tracer_provider instead of global provider, ensuring custom tracer providers are properly flushed

Sequence 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()
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 2900a43 into main Dec 12, 2025
12 checks passed
@hassiebp hassiebp deleted the hassieb/lfe-7980-bug-sdk-python-doesnt-flushshutdown-isolated-tracerprovider branch December 12, 2025 13:26
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.

2 participants