Rails-native observability powered by ActiveSupport::Notifications.
# Gemfile
gem 'brainzlab-rails'
# config/initializers/brainzlab.rb
BrainzLab.configure do |config|
config.secret_key = ENV['BRAINZLAB_SECRET_KEY']
end
# That's it! Auto-starts via RailtieAdd to your Gemfile:
gem 'brainzlab-rails'Then run:
bundle install
rails g brainzlab:installBrainzLab Rails supports true zero-config operation. Just add your secret key:
Option 1: Rails Credentials (Recommended)
EDITOR="code --wait" bin/rails credentials:editAdd:
brainzlab:
secret_key: your_secret_key_hereOption 2: Environment Variables
export BRAINZLAB_SECRET_KEY=your_secret_key_here# config/application.rb
Rails.application.configure do
config.brainzlab_rails.n_plus_one_detection = true
config.brainzlab_rails.slow_query_threshold_ms = 100
config.brainzlab_rails.sample_rate = 1.0
config.brainzlab_rails.ignored_actions = ['HealthController#check']
end# config/initializers/brainzlab.rb
BrainzLab.configure do |config|
# Products (all enabled by default)
config.recall_enabled = true # Logging
config.reflex_enabled = true # Error tracking
config.pulse_enabled = true # APM/Tracing
config.flux_enabled = true # Metrics
# Filtering
config.scrub_fields = %i[password token api_key secret]
# Error exclusions
config.reflex_excluded_exceptions = [
'ActionController::RoutingError',
'ActiveRecord::RecordNotFound'
]
end| Component | Events | Description |
|---|---|---|
| Action Controller | 12 events | Requests, redirects, filters, CSRF, caching |
| Action View | 4 events | Template rendering, partials, collections |
| Active Record | 5 events | SQL queries, transactions, connections |
| Active Job | 8 events | Enqueue, perform, retry, discard, exceptions |
| Action Cable | 5 events | WebSocket connections, subscriptions, broadcasts |
| Action Mailer | 3 events | Email delivery, generation |
| Active Storage | 12 events | Uploads, downloads, transformations |
| Cache | 15 events | Reads, writes, deletes, expiration |
| Total | 64+ events | Automatically instrumented |
Each Rails event is automatically routed to appropriate products:
| Product | Event Types |
|---|---|
| Pulse | APM spans for all performance-critical events |
| Recall | Structured logs for requests, jobs, emails |
| Reflex | Breadcrumbs and error context |
| Flux | Metrics (counters, histograms, timing) |
N+1 Query Detection
# Detected automatically!
User.all.each { |user| user.posts.count }
# => Warning: N+1 query detected for Post (called 100 times)Slow Query Analyzer
config.brainzlab_rails.slow_query_threshold_ms = 100Cache Efficiency Tracking
BrainzLab::Rails.subscriber.event_router.collectors[:cache].hit_rate
# => 85.2<head>
<%= brainzlab_js_tag %>
</head>The gem automatically instruments all Rails events. No manual API calls required.
┌─────────────────────────────────────────────────────────────────┐
│ BRAINZLAB-RAILS GEM │
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ ActiveSupport::Notifications │ │
│ │ (monotonic_subscribe for accurate timing) │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ Event Router │ │
│ │ Routes events to appropriate products │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌─────────────────────┼─────────────────────┐ │
│ ▼ ▼ ▼ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │Collectors│ │Collectors│ │Analyzers │ │
│ │ AC, AV │ │ AR, AJ │ │ N+1, │ │
│ │ Cable │ │ Mailer │ │SlowQuery │ │
│ └──────────┘ └──────────┘ └──────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ BrainzLab SDK │ │
│ │ Pulse • Recall • Reflex • Flux │ │
│ └──────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
Full documentation: docs.brainzlab.ai/rails
For self-hosted installations, configure the SDK endpoints:
BrainzLab.configure do |config|
config.secret_key = ENV['BRAINZLAB_SECRET_KEY']
config.recall_url = 'https://recall.your-domain.com'
config.reflex_url = 'https://reflex.your-domain.com'
config.pulse_url = 'https://pulse.your-domain.com'
endSee CONTRIBUTING.md for development setup.
bundle install
bundle exec rspec
gem build brainzlab-rails.gemspec- Ruby >= 3.1.0
- Rails >= 7.0
- brainzlab gem >= 0.1.6
OSAaSy License - see LICENSE for details.