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 "pipecat-ai[sentry]"
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,
)
Usage Example
import sentry_sdk
from pipecat.services.openai.llm import OpenAILLMService
from pipecat.services.elevenlabs.tts import ElevenLabsTTSService
from pipecat.processors.aggregators.openai_llm_context import OpenAILLMContext
from pipecat.processors.metrics.sentry import SentryMetrics
from pipecat.transports.services.daily import DailyParams, DailyTransport
async def create_metrics_pipeline():
sentry_sdk.init(
dsn="your-sentry-dsn",
traces_sample_rate=1.0,
)
transport = DailyTransport(
room_url,
token,
"Chatbot",
DailyParams(
audio_out_enabled=True,
audio_in_enabled=True,
video_out_enabled=False,
vad_analyzer=SileroVADAnalyzer(),
transcription_enabled=True,
),
)
tts = ElevenLabsTTSService(
api_key=os.getenv("ELEVENLABS_API_KEY"),
metrics = SentryMetrics(),
)
llm = OpenAILLMService(
api_key=os.getenv("OPENAI_API_KEY"), model="gpt-4o"),
metrics = SentryMetrics(),
)
messages = [
{
"role": "system",
"content": "You are Chatbot, a friendly, helpful robot. Your goal is to demonstrate your capabilities in a succinct way. Your output will be converted to audio so don't include special characters in your answers. Respond to what the user said in a creative and helpful way, but keep your responses brief. Start by introducing yourself. Keep all your responses to 12 words or fewer.",
},
]
context = OpenAILLMContext(messages)
context_aggregator = llm.create_context_aggregator(context)
# Use in pipeline
pipeline = Pipeline([
transport.input(),
context_aggregator.user(),
llm,
tts,
transport.output(),
context_aggregator.assistant(),
])
Each transaction includes:
- Operation type (
ttfb
or processing
)
- Description with processor name
- Start timestamp
- End timestamp
- Unique transaction 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 transaction management
- Supports selective TTFB reporting
- Integrates with Sentry’s performance monitoring
- Provides detailed timing information
- Maintains timing data even when Sentry is unavailable