bugwatch-ruby

Official Ruby/Rails SDK for BugWatch — open-source error monitoring.

Installation

# Gemfile
gem "bugwatch-ruby"
bundle install

Configuration

# config/initializers/bugwatch.rb
Bugwatch.configure do |c|
  c.api_key               = ENV["BUGWATCH_API_KEY"]
  c.endpoint              = ENV["BUGWATCH_ENDPOINT"]   # e.g. "https://your-app.herokuapp.com"
  c.release_stage         = Rails.env.to_s
  c.notify_release_stages = ["production", "staging"]
  c.ignore_classes        = ["ActionController::RoutingError"]
  c.app_version           = ENV["GIT_REV"]             # optional git SHA
end

User context

# app/controllers/application_controller.rb
before_action :set_bugwatch_user

private

def set_bugwatch_user
  return unless current_user
  Bugwatch.set_user(
    id:    current_user.id,
    email: current_user.email,
    name:  current_user.name
  )
end
Bugwatch.leave_breadcrumb("User clicked checkout", type: "ui", metadata: { cart_id: 42 })

Manual notification

begin
  risky_operation
rescue => e
  Bugwatch.notify(e)
  raise
end

How it works

  1. Bugwatch::Middleware wraps your entire Rack stack.
  2. When an unhandled exception propagates out of a request, the middleware:
    • Captures the exception, full backtrace (with 3 lines of source context per in-app frame), request details, user context, and breadcrumbs.
    • POSTs the payload to your BugWatch instance in a background thread (fire-and-forget, 3s timeout).
    • Re-raises the exception so Rails error handling fires normally.
  3. Thread-local user context and breadcrumbs are cleared automatically after each request by the Rails around_action hook.

What gets sent

Field Description
exception.error_class Exception class name
exception.message Exception message
exception.backtrace Array of frames with file, line, method, in_app, source_context
request.* Method, URL, params (filtered), headers (filtered), IP
app.* Rails env, Ruby version, Rails version, git SHA, hostname
user.* ID, email, name, any custom fields
breadcrumbs Last 50 breadcrumbs with timestamp, type, message, metadata
duration_ms Request duration in milliseconds

Sensitive params (password, token, secret, key, auth, credit, card, cvv, ssn) are automatically filtered from request params and never sent.

Publishing

cd /home/max/bugwatch-ruby
gem build bugwatch-ruby.gemspec
gem signin
gem push bugwatch-ruby-0.1.0.gem