> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pipecat.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Sentry Metrics

> Performance monitoring integration with Sentry for Pipecat frame processors

## 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, enabling real-time performance monitoring and error tracking for your Pipecat applications.

<CardGroup cols={2}>
  <Card title="Sentry Metrics API Reference" icon="code" href="https://reference-server.pipecat.ai/en/latest/api/pipecat.processors.metrics.sentry.html">
    Pipecat's API methods for Sentry metrics integration
  </Card>

  <Card title="Example Implementation" icon="play" href="https://github.com/pipecat-ai/pipecat/blob/main/examples/observability/observability-sentry-metrics.py">
    Browse examples using Sentry metrics
  </Card>

  <Card title="Sentry Documentation" icon="book" href="https://docs.sentry.io/platforms/python/">
    Official Sentry Python SDK documentation
  </Card>

  <Card title="Sentry Platform" icon="chart-line" href="https://sentry.io/">
    Access performance monitoring and error tracking
  </Card>
</CardGroup>

## Installation

To use Sentry analytics services, install the required dependencies:

```bash theme={null}
uv add "pipecat-ai[sentry]"
```

## Prerequisites

### Sentry Account Setup

Before using Sentry metrics services, you need:

1. **Sentry Account**: Sign up at [Sentry Platform](https://sentry.io/)
2. **Project Setup**: Create a project and obtain your DSN
3. **SDK Initialization**: Configure Sentry SDK in your application
4. **Metrics Configuration**: Set up performance monitoring and error tracking

### Required Configuration

* **Sentry DSN**: Your project's Data Source Name for authentication
* **Traces Sample Rate**: Configure performance monitoring sampling
* **SDK Initialization**: Initialize Sentry before using metrics

### Key Features

* **Performance Monitoring**: Track TTFB and processing duration metrics
* **Error Tracking**: Automatic error capture and reporting
* **Frame Processor Metrics**: Monitor individual processor performance
* **Real-time Analytics**: Live performance data and alerting

## Configuration

`SentryMetrics` takes no constructor parameters. It automatically detects whether the Sentry SDK has been initialized and logs a warning if it has not.

<Note>
  You must initialize the Sentry SDK in your application before creating
  `SentryMetrics`. The metrics collector checks `sentry_sdk.is_initialized()` at
  construction time.
</Note>

## Usage

### Basic Setup

```python theme={null}
import sentry_sdk
from pipecat.processors.metrics.sentry import SentryMetrics

# Initialize Sentry SDK first
sentry_sdk.init(
    dsn=os.getenv("SENTRY_DSN"),
    traces_sample_rate=1.0,
)

# Create metrics and assign to a service
sentry = SentryMetrics()
tts = SomeTTSService(
    metrics=sentry,
)
```

### With Multiple Services

```python theme={null}
sentry_tts = SentryMetrics()
sentry_llm = SentryMetrics()

tts = SomeTTSService(metrics=sentry_tts)
llm = SomeLLMService(metrics=sentry_llm)
```

## Notes

* **SDK initialization required**: Sentry metrics are silently disabled if `sentry_sdk.init()` has not been called. A warning is logged in this case.
* **Transaction types**: The service creates two types of Sentry transactions: `ttfb` for time-to-first-byte tracking and `processing` for frame processing duration.
* **Background processing**: Transactions are completed in a background task to avoid blocking the pipeline.
* **Graceful shutdown**: On cleanup, the service flushes all pending transactions to Sentry with a 5-second timeout.
* **Observer integration**: Metrics tracked by `SentryMetrics` are emitted as `MetricsFrame` objects downstream, enabling integration with pipeline observers like `UserBotLatencyObserver` and `MetricsLogObserver`.
