Overview

SentryMetrics extends FrameProcessorMetrics to provide performance monitoring integration with Sentry. It tracks Time to First Byte (TTFB) and processing duration metrics for frame processors.

Installation

To use Sentry metrics, install the Sentry SDK:

pip install --upgrade 'sentry-sdk[flask]'

Configuration

Sentry must be initialized in your application before metrics will be collected:

import sentry_sdk

sentry_sdk.init(
    dsn="your-sentry-dsn",
    traces_sample_rate=1.0,
)

Metrics Collection

TTFB Metrics

Time to First Byte metrics track how long it takes to receive the first response:

start_ttfb_metrics
method

Starts a TTFB span in Sentry

stop_ttfb_metrics
method

Stops the current TTFB span

Processing Metrics

Processing metrics track the total duration of frame processing:

start_processing_metrics
method

Starts a processing span in Sentry

stop_processing_metrics
method

Stops the current processing span

Usage Example

from pipecat.processors.metrics.sentry_metrics import SentryMetrics

class MyProcessor(BaseProcessor):
    def __init__(self):
        super().__init__()
        self._metrics = SentryMetrics()

    async def process_frame(self, frame: Frame):
        await self._metrics.start_processing_metrics()
        # Process frame
        await self._metrics.stop_processing_metrics()

Span Information

Each span includes:

  • Operation type (ttfb or processing)
  • Description with processor name
  • Start timestamp
  • End timestamp
  • Unique span ID

Fallback Behavior

If Sentry is not available (not installed or not initialized):

  • Warning logs are generated
  • Metric methods execute without error
  • No data is sent to Sentry

Notes

  • Requires Sentry SDK to be installed and initialized
  • Thread-safe metric collection
  • Automatic span management
  • Supports selective TTFB reporting
  • Integrates with Sentry’s performance monitoring
  • Provides detailed timing information
  • Maintains timing data even when Sentry is unavailable