Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Sentry instrumentation for performance and error tracking #1

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

cyrilS-dev
Copy link
Owner

This Pull Request introduces Sentry integration for performance tracking and error monitoring.

Key changes:

  1. FrameProcessor:
  • Add conditional Sentry import and initialization check
  • Implement custom instrumentation with Sentry spans in FrameProcessorMetrics to measure TTFB (Time To First Byte) and processing time when Sentry is available
  • Maintain existing metrics functionality with MetricsFrame regardless of Sentry availability
  1. DeepgramSTTService:

    1. Enable general metrics generation:

      • Implement can_generate_metrics method, returning True when VAD is enabled
      • This allows metrics to be collected and used by both Sentry and the metrics system in frame_processor.py
    2. Integrate Sentry-compatible performance tracking:

      • Add start_ttfb_metrics and start_processing_metrics calls in the VAD speech detection handler
      • Implement stop_ttfb_metrics call when receiving transcripts
      • Add stop_processing_metrics for final transcripts
    3. Enhance VAD support for metrics:

      • Add vad_enabled property to check VAD event availability
      • Implement VAD-based speech detection handler for precise metric timing

These changes allow for comprehensive performance monitoring and analysis using Sentry, providing valuable insights into STT, LLM and TTS services. The integration is designed to be non-intrusive, maintaining existing functionality while adding custom performance instrumentation.

Testing:

To validate the Sentry integration, the following steps were taken:

  1. Sentry initialization was added to examples/simple-chatbot/demo.py:
sentry_sdk.init(
dsn="SENTRY_DSN",
integrations=[AsyncioIntegration()],
disabled_integrations=[HttpxIntegration()],
traces_sample_rate=1.0,
enable_tracing=True,
)
  1. A Sentry transaction was created to encompass the main execution of the chatbot:
with sentry_sdk.start_transaction(op="pipecat", name="Pipecat"):
      await runner.run(task)
  1. The vad_events parameter in the DeepgramSTTService configuration was set to True

  2. The chatbot was run with this configuration, and the results were observed in the Sentry dashboard.

  3. A screenshot of the Sentry performance monitoring results, demonstrating successful tracking of STT, LLM, and TTS services performance metrics :

sentry

These tests confirm that Sentry is correctly integrated and capable of monitoring both performance and errors across the pipeline components.

Notes:

It's crucial to initialize Sentry as early as possible in the application, and before from pipecat.pipeline.pipeline import Pipeline :

  • To capture any potential errors that may occur during the imports
  • To ensure that sentry_sdk.is_initialized() returns the correct state when called in frame_processor.py.

Future Improvements:

  1. Usage Metrics in Sentry Spans:
    I plan to enhance the Sentry integration by adding "usage_metrics" to Sentry spans as tags.
    This improvement will provide more detailed and contextual information about resource usage within each service, allowing for better analysis and optimization of our pipeline components.

  2. Review TTS Processing Time Measurement:
    I need to review and potentially refine the way we measure processing time for the Text-to-Speech (TTS) service.

cyrilS-dev and others added 13 commits September 17, 2024 21:57
This update add optional Sentry integration for performance tracking and error monitoring.

Key changes include:

- Add conditional Sentry import and initialization check
- Implement Sentry spans in FrameProcessorMetrics to measure TTFB (Time To First Byte) and processing time when Sentry is available
- Maintain existing metrics functionality with MetricsFrame regardless of Sentry availability
This commit enhances the DeepgramSTTService class to enable metrics generation for use with Sentry.

Key changes include:

1. Enable general metrics generation:
   - Implement `can_generate_metrics` method, returning True when VAD is enabled
   - This allows metrics to be collected and used by both Sentry and the metrics system in frame_processor.py

2. Integrate Sentry-compatible performance tracking:
   - Add start_ttfb_metrics and start_processing_metrics calls in the VAD speech detection handler
   - Implement stop_ttfb_metrics call when receiving transcripts
   - Add stop_processing_metrics for final transcripts

3. Enhance VAD support for metrics:
   - Add `vad_enabled` property to check VAD event availability
   - Implement VAD-based speech detection handler for precise metric timing

These changes enable detailed performance tracking via both Sentry and the general metrics system when VAD is active. This allows for better monitoring and analysis of the speech-to-text process, providing valuable insights through Sentry and any other metrics consumers in the pipeline.
- Modified the __init__ method to accept a metrics parameter that is either FrameProcessorMetrics or one of its subclasses
- Updated the metrics initialization to create an instance with the processor's name
- Moved all FrameProcessorMetrics-related logic to a new processors\metrics\base.py file
1. Created a new metrics module in processors/metrics/

2. Implemented FrameProcessorMetrics base class in base.py:

3. Implemented SentryMetrics class in sentry.py:
   - Inherits from FrameProcessorMetrics
   - Integrates with Sentry SDK for advanced metrics tracking
   - Implements Sentry-specific span creation and management for TTFB and processing metrics
   - Handles cases where Sentry is not available or initialized
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant