tracing_context

Pipeline-scoped tracing context for OpenTelemetry tracing in Pipecat.

This module provides a per-pipeline tracing context that holds the current conversation and turn span contexts. Each PipelineTask creates its own TracingContext, ensuring concurrent pipelines do not interfere with each other.

class pipecat.utils.tracing.tracing_context.TracingContext[source]

Bases: object

Pipeline-scoped tracing context.

Holds the current conversation and turn span contexts for a single pipeline. Created by PipelineTask, passed to TurnTraceObserver (writer) and services (readers) via StartFrame.

__init__()[source]

Initialize the tracing context with empty state.

set_conversation_context(span_context: SpanContext | None, conversation_id: str | None = None)[source]

Set the current conversation context.

Parameters:
  • span_context – The span context for the current conversation or None to clear it.

  • conversation_id – Optional ID for the conversation.

get_conversation_context() Context | None[source]

Get the OpenTelemetry context for the current conversation.

Returns:

The current conversation context or None if not available.

set_turn_context(span_context: SpanContext | None)[source]

Set the current turn context.

Parameters:

span_context – The span context for the current turn or None to clear it.

get_turn_context() Context | None[source]

Get the OpenTelemetry context for the current turn.

Returns:

The current turn context or None if not available.

property conversation_id: str | None

Get the ID for the current conversation.

Returns:

The current conversation ID or None if not available.

static generate_conversation_id() str[source]

Generate a new conversation ID.

Returns:

A new randomly generated UUID string.