Introduction
The Lescopr gem integrates seamlessly with Ruby on Rails to provide automatic exception capture and real-time monitoring.
Once configured, every unhandled exception in your application is automatically reported to your Lescopr dashboard — including context such as the request, user, backtrace, and environment.
lescopr is available on RubyGems.org and is compatible with Rails 6.0+.
Requirements
Before installing the Lescopr gem, make sure your environment meets the following requirements:
- Ruby >= 2.7
- Rails >= 6.0
- A valid
LESCOPR_SDK_KEY(available from your Lescopr dashboard) - Bundler (recommended)
Installation
Add the lescopr gem to your Gemfile:
Then run Bundler to install the dependency:
Alternatively, you can install the gem directly from RubyGems:
Once installed, run the Lescopr installer to generate the initializer:
gem 'lescopr'bundle installbundle exec rails generate lescopr:installConfiguration
Edit the generated initializer file config/initializers/lescopr.rb to provide your SDK and API keys:
You can also restrict reporting to specific environments:
Available options:
sdk_key— Your Lescopr SDK key (required)api_key— Your Lescopr API key (required)environment— The current environment (production,staging,development)enabled_environments— Array of environments where reporting is active (default:['production', 'staging'])report_rescued_exceptions— Also report exceptions caught withrescue(default:false)logger— Custom logger instance (default:Rails.logger)
Lescopr.configure do |config|
config.app_key = ENV['LESCOPR_APP_KEY']
config.environment = Rails.env
endLescopr.configure do |config|
config.app_key = ENV['LESCOPR_APP_KEY']
config.environment = Rails.env
config.enabled_environments = %w[production staging]
endUsage
Once configured, Lescopr automatically captures all unhandled exceptions in your Rails application.
You can also manually report an exception anywhere in your code:
You can attach custom context (user, metadata) to improve traceability:
Context is thread-safe and is cleared automatically after each request.
begin
# risky operation
rescue => e
Lescopr.report(e)
raise
endbefore_action :set_lescopr_context
def set_lescopr_context
Lescopr.set_context(
user: { id: current_user&.id, email: current_user&.email }
)
endAdvanced
Filtering exceptions
You can ignore specific exception types that you do not want to report:
Breadcrumbs (user action trail)
Lescopr supports breadcrumbs to track user actions before an error:
Sidekiq integration
The lescopr gem automatically integrates with Sidekiq if it is present. Background job errors are captured with their job context.
Lescopr.configure do |config|
config.app_key = ENV['LESCOPR_APP_KEY']
config.ignored_exceptions = %w[
ActiveRecord::RecordNotFound
ActionController::RoutingError
]
endLescopr.add_breadcrumb(
message: 'User clicked checkout',
category: 'ui.click',
level: :info,
data: { order_id: id }
)