Introduction
The Lescopr gem integrates with Roda through the standard Rack middleware stack.
Roda is a routing-tree web toolkit built on Rack, so Lescopr::Integrations::Rack::Middleware plugs in natively and captures all unhandled exceptions at the Rack boundary.
lescopr is available on RubyGems.org and works with Roda 3.0+.
Requirements
Before installing the Lescopr gem, make sure your environment meets the following requirements:
- Ruby >= 2.7
- Roda >= 3.0
- A valid
LESCOPR_SDK_KEYandLESCOPR_API_KEY(available from your Lescopr dashboard) - Bundler (recommended)
Installation
Add the lescopr gem to your Gemfile:
Then run Bundler:
Or install it directly:
gem 'lescopr'bundle installgem install lescoprConfiguration
Initialise the SDK in your config.ru before the app is run, then add the middleware to the stack:
Set your keys via environment variables:
Available options:
sdk_key— Your Lescopr SDK key (required)api_key— Your Lescopr API key (required)environment— The current environment (default:ENV['RACK_ENV'])
require 'lescopr'
Lescopr.init!(
sdk_key: ENV['LESCOPR_SDK_KEY'],
api_key: ENV['LESCOPR_API_KEY'],
environment: ENV['RACK_ENV']
)
use Lescopr::Integrations::Rack::Middleware
run MyApp.freeze.appLESCOPR_SDK_KEY=lsk_xxxx
LESCOPR_API_KEY=lak_xxxx
RACK_ENV=productionUsage
Once the middleware is mounted in config.ru, all unhandled exceptions are captured automatically.
You can also log custom events manually from anywhere in your routing tree:
The background daemon flushes batched logs to the Lescopr API every 5 seconds — with zero blocking impact on your request handling.
class App < Roda
route do |r|
r.root do
Lescopr.log(:info, 'Root visited')
'Hello from Roda!'
end
end
endAdvanced
Roda plugin
For tighter integration you can wrap the SDK call inside a Roda plugin, giving you access to lescopr_log as a route helper throughout your routing tree.
Environment variables
LESCOPR_SDK_KEY— SDK key (overrides.lescopr.json)LESCOPR_API_KEY— API keyLESCOPR_ENVIRONMENT—developmentorproductionLESCOPR_DEBUG=true— Enables verbose output to.lescopr.log
class Roda
module RodaPlugins
module LescoprLogger
module InstanceMethods
def lescopr_log(level, message, data = {})
Lescopr.log(level, message, data)
end
end
end
register_plugin(:lescopr_logger, LescoprLogger)
end
end