Docs · Ruby & Rails

SDKs

Ruby & Rails

Bugzor works with the open-source sentry-ruby and sentry-rails gems. Tested with sentry-ruby 7.2 on Ruby 3.4 and Rails 8.1.

Rails#

Add the gems:

Gemfile
gem "sentry-ruby"
gem "sentry-rails"
Terminal
bundle install

Create an initializer:

config/initializers/sentry.rb
Sentry.init do |config|
  config.dsn = ENV["SENTRY_DSN"] # https://<public-key>@www.bugzor.com/<project-id>
  config.environment = Rails.env
  config.release = ENV["GIT_SHA"] # or your version number
  config.breadcrumbs_logger = [:active_support_logger, :http_logger]

  # Send the user's IP and the signed-in user (needed for "users affected").
  config.send_default_pii = true
end

That’s all. sentry-rails reports unhandled exceptions from controllers, Active Job and the Rails error reporter (Rails.error.report) automatically, with the request, params and breadcrumbs.

Tell Bugzor who’s affected#

app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
  before_action do
    Sentry.set_user(id: current_user.id, email: current_user.email) if current_user
  end
end

Plain Ruby#

Terminal
gem install sentry-ruby
Ruby
require "sentry-ruby"

Sentry.init do |config|
  config.dsn = "https://<public-key>@www.bugzor.com/<project-id>"
  config.environment = "production"
  config.release = "my-app@1.0.0"
end

begin
  Integer("not a number")
rescue => e
  Sentry.capture_exception(e)
end

Sentry.capture_message("Something worth knowing", level: :warning)

Short scripts: the gem sends from a background thread. It flushes at exit, but if you exit with exit! call Sentry.close first.

Add context#

Ruby
Sentry.with_scope do |scope|
  scope.set_tags(component: "checkout")
  scope.set_context("cart", { items: 3, total_cents: 4599 })
  Sentry.capture_message("Payment provider responded slowly", level: :warning)
end

Sentry.add_breadcrumb(Sentry::Breadcrumb.new(category: "auth", message: "Signed in"))

Drop noise before it’s sent#

Ruby
config.excluded_exceptions += ["ActionController::RoutingError"]
config.before_send = lambda do |event, _hint|
  event.tags[:healthcheck] ? nil : event
end

Dropped events never reach Bugzor and don’t count towards your limits.

Test it#

Terminal
bin/rails runner 'Sentry.capture_message("Hello from Rails"); Sentry.close'

The message appears under Issues within a few seconds. If it doesn’t, set config.debug = true and look for the response code in the log. See troubleshooting.

Something unclear or out of date? Tell us.