Performance Monitoring
Track response times, slow queries, and application performance.
ActiveRabbit's performance monitoring helps you identify bottlenecks, slow queries, and optimize your Rails application's response times.
Enabling Performance Monitoring
# config/initializers/activerabbit.rb
ActiveRabbit.configure do |config|
config.api_key = ENV['ACTIVERABBIT_API_KEY']
# Enable performance monitoring
config.performance_monitoring = true
# Sample rate for performance data (0.0 to 1.0)
# Start with 0.1 (10%) and adjust based on traffic
config.performance_sample_rate = 0.1
endAutomatic Instrumentation
When enabled, ActiveRabbit automatically tracks:
- Controller actions - Total request time and breakdown
- Database queries - Query time, count, and N+1 detection
- View rendering - Template and partial render times
- External HTTP calls - API response times
- Cache operations - Redis/Memcached hit rates and latency
Transaction Tracking
Each HTTP request is tracked as a "transaction" with timing breakdown:
# Transactions are automatically created for each request
# Example breakdown:
#
# GET /orders/123
# Total: 245ms
# ├─ Controller: 15ms
# ├─ Database: 180ms
# │ ├─ SELECT orders... 25ms
# │ ├─ SELECT line_items... 45ms (N+1 detected!)
# │ └─ SELECT products... 110ms
# ├─ View: 35ms
# └─ Redis: 15msCustom Spans
Track custom operations within your code:
# Manual span creation
def process_order(order)
ActiveRabbit.with_span('process_order') do |span|
span.set_tag('order_id', order.id)
# Nested spans
ActiveRabbit.with_span('validate_inventory') do
check_inventory(order.line_items)
end
ActiveRabbit.with_span('charge_payment') do
charge_customer(order)
end
ActiveRabbit.with_span('send_confirmation') do
OrderMailer.confirmation(order).deliver_later
end
end
endSlow Query Detection
ActiveRabbit.configure do |config|
# Threshold in milliseconds
config.slow_query_threshold = 100
# Get alerted for queries over threshold
# These appear in the dashboard with full query and explain plan
endN+1 Query Detection
ActiveRabbit.configure do |config|
# Enable N+1 detection
config.detect_n_plus_one = true
# Minimum duplicate queries to trigger detection
config.n_plus_one_threshold = 3
end
# When N+1 is detected, ActiveRabbit captures:
# - The repeated query pattern
# - Stack trace showing where it originates
# - Suggested fix (e.g., add includes/preload)Web Vitals
For frontend performance, add the JavaScript snippet to track Core Web Vitals:
<!-- Add to your layout head -->
<script src="https://cdn.activerabbit.ai/vitals.js"
data-api-key="<%= ENV['ACTIVERABBIT_API_KEY'] %>"
async></script>This tracks:
- LCP - Largest Contentful Paint
- FID - First Input Delay
- CLS - Cumulative Layout Shift
- TTFB - Time to First Byte
Apdex Score
ActiveRabbit calculates an Apdex score for your application:
ActiveRabbit.configure do |config|
# Satisfied threshold (requests faster than this are "satisfied")
config.apdex_satisfied = 500 # 500ms
# Tolerating threshold (requests between satisfied and this are "tolerating")
config.apdex_tolerating = 2000 # 2000ms
# Requests slower than tolerating threshold are "frustrated"
end
# Apdex = (Satisfied + Tolerating/2) / Total
# Score ranges from 0 (worst) to 1 (best)Performance Alerts
Configure alerts for performance degradation:
# In the ActiveRabbit dashboard, create alerts for:
#
# - P95 latency > 1000ms
# - Apdex score < 0.85
# - Error rate > 1%
# - N+1 queries detected
# - Slow query threshold exceededBackground Jobs
# Job performance is automatically tracked
class HeavyProcessingJob < ApplicationJob
def perform(data)
# Job duration and memory usage tracked automatically
process_data(data)
end
end
# You can add custom metrics
class ImportJob < ApplicationJob
def perform(file_path)
ActiveRabbit.with_span('import_job') do |span|
records = import_records(file_path)
span.set_data('records_imported', records.count)
end
end
endDatabase Query Analysis
# ActiveRabbit captures and analyzes:
#
# - Query duration
# - Rows examined vs returned
# - Index usage (EXPLAIN output)
# - Query frequency and patterns
#
# For MySQL/PostgreSQL, it can suggest indexes:
#
# Suggested index for frequent slow query:
# CREATE INDEX index_orders_on_user_id_and_status
# ON orders(user_id, status);Memory Profiling
ActiveRabbit.configure do |config|
# Track object allocations
config.track_allocations = true
# Memory growth threshold (MB) to flag
config.memory_growth_threshold = 50
end
# Dashboard shows:
# - Memory usage over time
# - Object allocation hotspots
# - Potential memory leaks⚡ Performance Tips
- Start with 10% sampling and increase if you need more data
- Focus on P95 latency rather than averages
- Fix N+1 queries first - they're usually quick wins
- Use custom spans to identify business-critical bottlenecks