metrics_log_observer

Metrics logging observer for Pipecat.

This module provides an observer that logs metrics frames to the console, allowing developers to monitor performance metrics, token usage, and other statistics in real-time.

class pipecat.observers.loggers.metrics_log_observer.MetricsLogObserver(include_metrics: set[type[MetricsData]] | None = None, **kwargs)[source]

Bases: BaseObserver

Observer to log metrics activity to the console.

Monitors and logs all MetricsFrame instances, including:

  • TTFBMetricsData (Time To First Byte)

  • ProcessingMetricsData (General processing time)

  • LLMUsageMetricsData (Token usage statistics)

  • TTSUsageMetricsData (Text-to-Speech character counts)

  • TurnMetricsData (Turn prediction metrics)

This allows developers to track performance metrics, token usage, and other statistics throughout the pipeline.

Examples

Log all metrics types:

observers = [MetricsLogObserver()]

Log only LLM and TTS metrics:

from pipecat.metrics.metrics import LLMUsageMetricsData, TTSUsageMetricsData
observers = [
    MetricsLogObserver(
        include_metrics={LLMUsageMetricsData, TTSUsageMetricsData}
    )
]
__init__(include_metrics: set[type[MetricsData]] | None = None, **kwargs)[source]

Initialize the metrics log observer.

Parameters:
  • include_metrics – Set of metrics types to include. If specified, only these metrics types will be logged. If None, all metrics are logged.

  • **kwargs – Additional arguments passed to parent class.

async on_push_frame(data: FramePushed)[source]

Handle frame push events and log metrics frames.

Logs MetricsFrame instances with detailed information about the metrics data, formatted appropriately for each metrics type.

Parameters:

data – Frame push event data containing source, frame, and timestamp.