Ruby
The Ruby SDK targets Ruby 2.7+ and uses only the standard library — net/http, json, securerandom. It installs an at_exit hook so a fatal exception that terminates the process is captured before exit.
Install
$ gem install tinymonrb
Or in your Gemfile:
gem 'tinymon', '~> 0.1'
Tinymon.init
Initialise once, as early as possible. In Rails, config/initializers/tinymon.rb is the right place.
require 'tinymon' Tinymon.init( dsn: ENV.fetch('TINYMON_DSN'), environment: 'production', release: '1.0.0', sample_rate: 1.0, )
Keyword arguments
| Argument | Type | Description |
|---|---|---|
| dsn: | String | Required. Your project DSN. |
| endpoint: | String | Override the ingest URL. Defaults to https://console.tinymon.dev/api/ingest. |
| environment: | String | Free-form tag — production, staging. |
| release: | String | Version string for your app. |
| sample_rate: | Float | 0 to 1. Default 1.0. |
| before_send: | Proc | Mutate 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')
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)
Breadcrumbs
Tinymon.add_breadcrumb( timestamp: Time.now.to_f, category: 'sql', message: 'SELECT * FROM users WHERE id = 42', level: 'info', )
Rails & Sinatra
Rails
Create config/initializers/tinymon.rb with the Tinymon.init call. Then add a middleware to capture exceptions in the request cycle:
# app/middleware/tinymon_middleware.rb class TinymonMiddleware def initialize(app); @app = app; end def call(env) @app.call(env) rescue => e Tinymon.capture_exception(e) raise end end # config/application.rb config.middleware.use TinymonMiddleware
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