Product How it works Features Security What is bugstack? SDKs JavaScript SDK Python SDK Go SDK Ruby SDK Docs Pricing Blog Book a demo
Log In Get started

Ruby SDK reference

Reference for the bugstack gem: setup for Rails, Sinatra and plain Ruby, what it reports, the capture API and troubleshooting.

Installation

$ bundle add bugstack --version '~> 1.0'

Rails

One initializer loads the Rails integration, initializes bugstack, and places its middleware inside Rails' own error pages. The gem's automatic placement sits outside it, where a production Rails app has already turned the exception into an error page, so nothing would be reported.

ruby
# config/initializers/bugstack.rb
require "bugstack/integrations/rails"

Bugstack.init(
  api_key: ENV["BUGSTACK_API_KEY"],
  endpoint: ENV.fetch("BUGSTACK_ENDPOINT", "https://dashboard.bugstack.ai/api/ingest/sdk")
)

# Inside Rails' own error pages, so bugstack sees the error before they answer it:
Rails.application.config.middleware.insert_after(
  ActionDispatch::DebugExceptions,
  Bugstack::Integrations::RackMiddleware
)

Sinatra

ruby
require "bugstack"
require "bugstack/integrations/sinatra"

Bugstack.init(
  api_key: ENV["BUGSTACK_API_KEY"],
  endpoint: ENV.fetch("BUGSTACK_ENDPOINT", "https://dashboard.bugstack.ai/api/ingest/sdk")
)

class App < Sinatra::Base
  register Bugstack::Integrations::Sinatra
  # ... your routes
end

Plain Ruby

ruby
require "bugstack"

Bugstack.init(
  api_key: ENV["BUGSTACK_API_KEY"],
  endpoint: ENV.fetch("BUGSTACK_ENDPOINT", "https://dashboard.bugstack.ai/api/ingest/sdk")
)

begin
  process_job(job)
rescue => e
  Bugstack.capture_exception(e, metadata: { job: job.id })
  raise
end

What the SDK reports

An exception that passes through Bugstack::Integrations::RackMiddleware (Rails or any Rack app), an error in a Sinatra app with the extension registered, and anything you pass to Bugstack.capture_exception. Sidekiq, ActiveJob and Rails.error are not hooked: report job errors with capture_exception.

Each report carries the exception class, message and backtrace, the file and method it came from, the route and method of the request, the Ruby version, framework and SDK version, and any metadata you pass. Query parameters, headers and request bodies are not sent. Reports go out from a background thread, with up to three attempts.

Capture API

  • Bugstack.capture_exception(exception, request: nil, metadata: nil): report an exception. Returns true if it was accepted.
  • Bugstack.client: the current client, or nil before init.
  • Bugstack.shutdown: stop the client.

Configuration

Every option, with its type and default, is in the installation guide. The ones you are most likely to set: api_key, endpoint, environment, enabled, ignored_errors and before_send.

After an error is reported

Specialist agents work out the cause and write the change. It arrives as a pull request your own CI runs on. What happens next depends on the autonomy level you set for the repository: new repositories start on Review, where you merge. Before Autopilot merges a crash fix, bugstack replays the failing request: it must fail before the fix and pass after; without that proof the pull request waits for you. Connecting the repository also starts repository scanning.

Common Rails errors

Error patterns that come up often in production Rails applications. Each link opens a step-by-step fix guide:

Troubleshooting

No events in bugstack? Check that the API key is set when the process starts, and that endpoint is set to https://dashboard.bugstack.ai/api/ingest/sdk: the published SDK does not default to it yet. Turn on debug to see each send.

Events but no fix pull request? The bugstack GitHub App must be installed on the repository, and the files in the stack trace must be in that repository.

Too many duplicates? Each SDK sends the same error at most once every five minutes, and bugstack folds repeats within 24 hours into the same piece of work, so you get one pull request per problem.

Rails errors not reported? The middleware must sit inside Rails' error pages, after ActionDispatch::DebugExceptions (see Rails above). Check with bin/rails middleware.

Data and privacy

The gem sends the exception, its backtrace, the file and method, the route and method, and runtime details. It does not send query parameters, headers or request bodies, and it does not redact the exception message or backtrace: use before_send to change or drop an event before it is sent. See privacy and data handling.

Versioning and compatibility

The bugstack gem follows semver. It needs Ruby 3.0 or later and has no runtime dependencies.

Get started

Sign up with GitHub and start Pro, or book a demo and we set it up with you. Get started.

← Back to Documentation