turn_trace_observer
Turn trace observer for OpenTelemetry tracing in Pipecat.
This module provides an observer that creates trace spans for each conversation turn, integrating with the turn tracking system to provide hierarchical tracing of conversation flows.
- class pipecat.utils.tracing.turn_trace_observer.TurnTraceObserver(turn_tracker: TurnTrackingObserver, latency_tracker: UserBotLatencyObserver, conversation_id: str | None = None, additional_span_attributes: dict | None = None, tracing_context: TracingContext | None = None, **kwargs)[source]
Bases:
BaseObserverObserver that creates trace spans for each conversation turn.
This observer uses TurnTrackingObserver to track turns and creates OpenTelemetry spans for each turn. Service spans (STT, LLM, TTS) become children of the turn spans.
If conversation tracing is enabled, turns become children of a conversation span that encapsulates the entire session.
- __init__(turn_tracker: TurnTrackingObserver, latency_tracker: UserBotLatencyObserver, conversation_id: str | None = None, additional_span_attributes: dict | None = None, tracing_context: TracingContext | None = None, **kwargs)[source]
Initialize the turn trace observer.
- Parameters:
turn_tracker – The turn tracking observer to monitor.
latency_tracker – The latency tracking observer for user-bot latency.
conversation_id – Optional conversation ID for grouping turns.
additional_span_attributes – Additional attributes to add to spans.
tracing_context – Pipeline-scoped tracing context for span hierarchy.
**kwargs – Additional arguments passed to parent class.
- async on_push_frame(data: FramePushed)[source]
Process a frame without modifying it.
Handles StartFrame to begin conversation tracing early, ensuring that any spans created before Turn 1 (e.g., from flow initialization) are properly attached to the conversation trace.
- Parameters:
data – The frame push event data.
- start_conversation_tracing(conversation_id: str | None = None)[source]
Start a new conversation span.
- Parameters:
conversation_id – Optional custom ID for the conversation. If None, a UUID will be generated.
- end_conversation_tracing()[source]
End the current conversation span and ensure the last turn is closed.