Skip to content

perf: Add performance monitoring and metrics collection #531

@manavgup

Description

@manavgup

Problem

No visibility into performance issues:

  • Can't track query counts per request
  • No alerting on performance degradation
  • Difficult to diagnose bottlenecks

Root Cause

  • No performance monitoring infrastructure
  • No metrics collection
  • No dashboards or alerts

Proposed Solution

  1. Create monitoring/metrics.py with PerformanceMonitor class
  2. Add decorators to track database queries, LLM calls, token usage
  3. Log performance summary per request
  4. Set up alerts for threshold violations

Expected Impact

  • Visibility into performance metrics
  • Proactive issue detection
  • Data-driven optimization decisions

Files to Create

  • backend/monitoring/metrics.py
  • backend/monitoring/alerts.py

Files to Modify

  • Database query execution points (add tracking decorator)
  • LLM provider calls (add token tracking)
  • Main request handlers (add summary logging)

Acceptance Criteria

  • PerformanceMonitor class implemented
  • Metrics tracked: db_query_count, llm_token_count, execution_time
  • Alerts trigger on thresholds (> 20 queries, > 5s execution)
  • Metrics logged per request
  • Dashboard-ready format (JSON structured logs)

Priority

Medium - Phase 3 Advanced Optimization

Related Issues

Part of overall performance optimization initiative

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestperformancePerformance optimizationpriority:mediumMedium priority - nice to have

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions