Roda — Lescopr SDK

Integrate the Lescopr SDK into your Roda application for automatic exception capture and real-time monitoring, from installation to configuration.

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_KEY and LESCOPR_API_KEY (available from your Lescopr dashboard)
  • Bundler (recommended)

Installation

Add the lescopr gem to your Gemfile:

Then run Bundler:

Or install it directly:

Gemfile
ruby
gem 'lescopr'
Terminal
bash
bundle install
Terminal
bash
gem install lescopr

Configuration

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'])
config.ru
ruby
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.app
.env
bash
LESCOPR_SDK_KEY=lsk_xxxx
LESCOPR_API_KEY=lak_xxxx
RACK_ENV=production

Usage

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.

app.rb
ruby
class App < Roda
  route do |r|
    r.root do
      Lescopr.log(:info, 'Root visited')
      'Hello from Roda!'
    end
  end
end

Advanced

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 key
  • LESCOPR_ENVIRONMENT — development or production
  • LESCOPR_DEBUG=true — Enables verbose output to .lescopr.log
lib/roda/plugins/lescopr_logger.rb
ruby
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