errsight-ruby
Ruby/Rails client for ErrSight error tracking. Captures exceptions and log entries and ships them to the ErrSight API in a background thread.
Requirements
- Ruby >= 3.0
- Rails 6+ (optional — also works in plain Ruby)
Installation
Add to your Gemfile:
gem "errsight"
Then run:
bundle install
Configuration
Rails
Create an initializer at config/initializers/errsight.rb:
Errsight.configure do |config|
config.api_key = ENV["ERRSIGHT_API_KEY"] # required
config.environment = Rails.env # default: ENV["ERRSIGHT_ENV"] || "production"
end
That is all you need. The Railtie handles the rest automatically:
- Attaches to
Rails.loggerso every log line is forwarded to ErrSight. - Subscribes to
process_action.action_controllernotifications to capture unhandled exceptions with request context (controller, action, path, params, current user). - Calls
Errsight.client.shutdown!on process exit to drain the queue.
Plain Ruby
require "errsight"
Errsight.configure do |config|
config.api_key = ENV["ERRSIGHT_API_KEY"]
config.environment = "production"
end
Environment variables
| Variable | Default | Description |
|---|---|---|
ERRSIGHT_API_KEY |
— | Your project API key (required) |
ERRSIGHT_ENV |
"production" |
Environment tag attached to events |
ERRSIGHT_HOST |
"https://errsight.com" |
Override the API host |
All configuration options
Errsight.configure do |config|
config.api_key = ENV["ERRSIGHT_API_KEY"]
config.environment = "production"
config.min_level = :warning # :debug | :info | :warning | :error | :fatal
config.host = "https://errsight.com"
config.timeout = 5 # HTTP timeout in seconds
config.batch_size = 10 # events per HTTP request
config.flush_interval = 2 # background flush cadence in seconds
config.max_queue_size = 1_000 # drop events when queue exceeds this
config.attach_to_rails_logger = true # broadcast Rails.logger to ErrSight
end
Usage
Capture an exception
begin
do_something_risky
rescue => e
Errsight.capture_exception(e, metadata: { user_id: current_user.id })
end
Log a message directly
Errsight.log(level: :error, message: "Payment gateway timeout", metadata: { order_id: 42 })
Use as a Logger sink
logger = Errsight::Logger.new # standalone — forwards to API only
logger = Errsight::Logger.new($stdout) # tee — writes to $stdout AND the API
logger.warn "Cache miss"
logger.error "Unprocessable entity"
Rails — automatic exception capture
In a Rails app the Railtie automatically captures every unhandled exception raised during a controller action and attaches request metadata:
controller, action, path, HTTP method, filtered params, duration, user id/email (Devise/Warden)
No additional code is required.
How it works
Events are pushed onto an in-memory queue and flushed to the API in batches by a background thread every flush_interval seconds (default: 2 s). A flush also triggers immediately when the queue reaches batch_size. On process exit the queue is drained synchronously before the process terminates.
The HTTP transport uses Net::HTTP with no extra dependencies beyond concurrent-ruby for thread-safe queue operations.