Requirements: Ruby ≥ 3.0
Installation
Add to yourGemfile:
Gemfile
Quick start
- Rails
- Sinatra / Rack
1
Create an initializer
config/initializers/tracelit.rb
2
You're done
The Railtie picks up the configuration automatically and calls
Tracelit.start! at boot. No further changes needed.Configuration reference
All options can be set in theconfigure block or via environment variables.
Custom resource attributes
Tracing
Manual spans
Tracelit.tracer is an OpenTelemetry::Trace::Tracer and supports the full OpenTelemetry Ruby API.
Nesting spans
Recording errors
Automatic instrumentation
The SDK enables every instrumentation gem bundled inopentelemetry-instrumentation-all:
Additional libraries (Mongo, pg, mysql2, Kafka, etc.) are also instrumented when their gems are present.
Metrics
Automatic metrics
The SDK emits the following metrics out of the box — no configuration required:Sidekiq and ActiveRecord metrics are only installed when those libraries are present. All pollers are fork-safe — they restart automatically inside each Puma cluster worker.
Manual metrics
Log forwarding (Rails)
When Rails is present,Tracelit.start! installs a broadcast target on Rails.logger. Every Rails.logger call is forwarded to the OTel LoggerProvider and exported to the Tracelit logs table via OTLP.
- Original logger output is preserved — nothing changes for your existing log pipeline
- Log records are automatically correlated with the active trace via
trace_idandspan_id
Sampling and error guarantee
Error spans are always exported, even when the parent trace is outside the sample ratio. The SDK uses a custom
ErrorAlwaysOnSampler + ErrorSpanProcessor pair to guarantee this — no configuration required.Disabling in specific environments
Tests
Rails console
By default the SDK initialises duringrails console, printing OTel instrumentation startup lines before your prompt. Suppress this with:
Rails::Console is defined only when the process was started via rails console, so this has no effect on your server or background workers.
Commit SHA tracking
The SDK automatically attaches the current commit SHA asservice.commit_sha on every span, metric, and log. It resolves the SHA from common CI/CD environment variables with no configuration needed:
No action required — if any of the above is set at boot time the SHA is picked up automatically.