Error Tracking
Capture, organize, and resolve errors in your Rails application.
ActiveRabbit automatically captures unhandled exceptions in your Rails application. This guide covers manual error reporting and advanced tracking features.
Automatic Error Capture
Once installed, ActiveRabbit automatically captures:
- Unhandled exceptions in controllers
- Background job failures (Sidekiq, Resque, etc.)
- Rake task errors
- Console exceptions
No additional code is required for basic error tracking.
Manual Error Capture
Capturing Exceptions
begin
risky_operation
rescue => e
# Capture and re-raise
ActiveRabbit.capture_exception(e)
raise
end
# Or capture without re-raising
begin
risky_operation
rescue => e
ActiveRabbit.capture_exception(e)
# Handle gracefully
endCapturing Messages
# Send a message without an exception
ActiveRabbit.capture_message("Something unexpected happened")
# With severity level
ActiveRabbit.capture_message("User limit exceeded", level: :warning)
# Available levels: :debug, :info, :warning, :error, :fatalAdding Context
User Context
# Set user context globally (in a before_action)
class ApplicationController < ActionController::Base
before_action :set_activerabbit_context
private
def set_activerabbit_context
if current_user
ActiveRabbit.set_user(
id: current_user.id,
email: current_user.email,
name: current_user.name,
plan: current_user.subscription&.plan
)
end
end
endCustom Tags
# Add tags to categorize errors
ActiveRabbit.set_tags(
feature: 'checkout',
experiment: 'new_flow_v2'
)
# Tags are included with all subsequent errors in the requestExtra Data
# Add arbitrary extra data
ActiveRabbit.set_extra(
order_id: @order.id,
cart_items: @cart.items.count,
total_amount: @order.total
)
# Or when capturing
ActiveRabbit.capture_exception(e, extra: {
attempted_action: 'process_payment',
payment_method: 'stripe'
})Breadcrumbs
# Record breadcrumbs to track user flow
ActiveRabbit.add_breadcrumb(
category: 'navigation',
message: 'User visited checkout page',
data: { cart_items: 3 }
)
ActiveRabbit.add_breadcrumb(
category: 'user',
message: 'Applied discount code',
data: { code: 'SAVE20' }
)
# Breadcrumbs are automatically included when an error is capturedScoped Context
# Use scopes for temporary context
ActiveRabbit.with_scope(tags: { operation: 'bulk_import' }) do
users.each do |user_data|
ActiveRabbit.with_scope(extra: { user_email: user_data[:email] }) do
import_user(user_data)
end
end
endError Grouping
ActiveRabbit automatically groups similar errors together. You can customize grouping with fingerprints:
# Custom fingerprint for grouping
ActiveRabbit.capture_exception(e, fingerprint: ['payment-error', merchant_id])
# Errors with the same fingerprint array are grouped togetherIgnoring Errors
Globally Ignored Exceptions
# In your initializer
ActiveRabbit.configure do |config|
config.ignored_exceptions = [
ActiveRecord::RecordNotFound,
ActionController::RoutingError,
ActionController::InvalidAuthenticityToken
]
endConditional Ignoring
ActiveRabbit.configure do |config|
config.ignore_if do |event|
# Ignore errors from bots
event.request&.user_agent&.match?(/bot|crawler|spider/i) ||
# Ignore specific error messages
event.exception.message.include?('timeout') ||
# Ignore errors from specific IPs
event.request&.ip == '127.0.0.1'
end
endSource Maps & Code Context
ActiveRabbit automatically captures source code context around the error. For production environments, upload source maps for better stack traces:
# Upload source maps during deployment
activerabbit releases upload \
--release $(git rev-parse HEAD) \
--path ./appIntegration with Background Jobs
Sidekiq
# Automatically integrated, but you can add custom context
class ImportJob
include Sidekiq::Job
def perform(user_id)
ActiveRabbit.with_scope(
tags: { job: 'ImportJob' },
extra: { user_id: user_id }
) do
# Job logic here
end
end
endActiveJob
# Errors are automatically captured with job metadata
class ProcessOrderJob < ApplicationJob
queue_as :default
def perform(order_id)
order = Order.find(order_id)
ActiveRabbit.set_extra(order_total: order.total)
process_order(order)
end
end🎯 Best Practices
- Always set user context for authenticated requests
- Use breadcrumbs to track user flow leading to errors
- Add relevant business context (order IDs, feature flags, etc.)
- Use custom fingerprints for errors that should be grouped differently