Ruby

The Ruby SDK targets Ruby 2.7+ and uses only the standard librarynet/http, json, securerandom. It installs an at_exit hook so a fatal exception that terminates the process is captured before exit.

Building a web app? Don't stop at init() — see Rails & Sinatra below. On Rails it's automatic; on Rack it's one line.

Install

$ gem install tinymonrb

Or in your Gemfile:

gem 'tinymonrb', '~> 0.4'

Tinymon.init

Initialise once, as early as possible. In Rails, config/initializers/tinymon.rb is the right place.

require 'tinymonrb'

Tinymon.init(
  dsn:         ENV.fetch('TINYMON_DSN'),
  environment: 'production',
  release:     ENV['RELEASE'], # e.g. git short SHA, set at deploy
  sample_rate: 1.0,
)

Keyword arguments

ArgumentTypeDescription
dsn:StringRequired. Your project DSN.
endpoint:StringOverride the ingest URL. Defaults to https://console.tinymon.dev/api/ingest.
environment:StringFree-form tag — production, staging.
release:StringVersion string for your app.
sample_rate:Float0 to 1. Default 1.0.
before_send:ProcMutate or drop events. Return nil to drop.

Capturing exceptions

begin
  risky_thing
rescue => e
  Tinymon.capture_exception(e)
end

# Or a plain message:
Tinymon.capture_message('cron job took 28 seconds', level: 'warning')

Delivery & flush()

Events are sent immediately on a background thread — no batching delay. Failed sends are queued and retried with backoff; successful ones never queue. An at_exit hook drains pending events on shutdown.

In a long-running server (Rails, Sidekiq loop) you never need to do anything. In a short-lived process — a Lambda handler, a rake task, a per-job one-shot — call flush() before it exits:

begin
  run_job
rescue => e
  Tinymon.capture_exception(e)
  Tinymon.flush(2.0) # seconds; never blocks forever
  raise
end
Rule of thumb. Long-running server → skip flush(). Serverless / script → call it once before exit. Recipes & mechanics: Delivery & flush() and Transport internals.

User & tag context

Tinymon.set_user(id: current_user.id)
Tinymon.set_tag('plan', current_user.plan)
Tinymon.set_tag('tenant_id', tenant.id.to_s)
Tinymon.add_breadcrumb(
  timestamp: Time.now.to_f,
  category:  'sql',
  message:   'SELECT * FROM users WHERE id = 42',
  level:     'info',
)

Rails & Sinatra

Rails

Nothing to wire up. The gem ships a Railtie that auto-inserts Tinymon::Rack into your middleware stack. Just create config/initializers/tinymon.rb with the Tinymon.init call and you're done:

# config/initializers/tinymon.rb
require 'tinymonrb'
Tinymon.init(dsn: ENV.fetch('TINYMON_DSN'))

Not on Rails but using Rack (Hanami, Roda, raw Rack)? Add the middleware in one line:

use Tinymon::Rack

Sinatra

error do
  Tinymon.capture_exception(env['sinatra.error'])
end

Sidekiq

Add a server middleware that wraps the job invocation in begin/rescue:

Sidekiq.configure_server do |config|
  config.server_middleware do |chain|
    chain.add(Class.new do
      def call(_w, _job, _q)
        yield
      rescue => e
        Tinymon.capture_exception(e); raise
      end
    end)
  end
end