Where do you want to collect your Ruby logs from?
Collect logs from your Rails application, including your Sidekiq jobs. This integration also supports Structured Events in Rails 8.1 or higher for rich, queryable event logging.
Install Better Stack Rails Gem:
Set up Better Stack Rails Gem in config/application.rb:
Set config.logtail.enabled = false in the environment file, for example development.rb. Rails then logs to its log file as usual and nothing is sent to Better Stack. Needs logtail-rails 0.2.15 or newer.
Use Rails logger as usual:
You should see your logs in Better Stack Logs → Live tail.
Check out the Ruby on Rails dashboard.
Rails version 5.0 or higher is required.
Ruby version 2.5 or higher is required.
Collect logs from any Rack-based framework such as Sinatra, Hanami, Padrino, or Roda.
Install Better Stack Rack Gem:
Set up Better Stack Rack Gem in your config.ru:
Use the instantiated logger instance to send logs to Better Stack:
You should see your logs in Better Stack Logs → Live tail.
Rack version 1.2 or higher is required.
Ruby version 2.3 or higher is required.
Collect logs from your Ruby code.
Install Better Stack Gem:
Set up Better Stack Ruby client:
Use Ruby logger as usual:
You should see your logs in Better Stack → Live tail.
Ruby version 2.3.0 or higher is required.
Bullet detects N+1 queries, unused eager loading, and missing counter caches in your Rails app. We'll log each detection as a structured event, tagged with the file and line that triggered it.
Add the Bullet gem:
Enable Bullet in config/environments/production.rb and register a notifier that emits one structured event per detection through Rails.logger:
BetterStackBulletNotifier is a regular UniformNotifier — the same library Bullet uses for its other output channels. It runs alongside any Bullet notifiers you already have enabled (alert, console, the in-browser footer) without affecting them.
Trigger an N+1 in your app. Open Live tail and you'll see one structured event per detection:
Trace every request and Sidekiq job in your Rails app. We turn the traces into request and job metrics automatically.
Add the OpenTelemetry gems:
Set up tracing in config/initializers/opentelemetry.rb. This initializer covers requests, database queries, and both enqueueing and processing jobs.
Send a few requests to your app and run any job. Within a couple of minutes, the data will become visible in the Tracing for Rails dashboard and in the Sidekiq section of the Ruby on Rails dashboard
queue_time is how long each request waited, in seconds, between your proxy accepting it and Rails starting to work on it. Request durations don't include this wait, so queue_time is the metric that shows requests piling up when all your workers are busy. Chart it in any dashboard.
We compute it from your traces. It needs the proxy in front of your app to set the X-Request-Start header:
proxy_set_header line, next to the other proxy_set_header lines that apply to your app:X-Request-Start to the time they received the request, as a Unix timestamp in seconds, milliseconds, or microseconds.Without the header, queue_time stays empty.
Its eBPF traces don't include request queueing, so queue_time stays empty for them. Use the OpenTelemetry setup above to measure it.
Please let us know at hello@betterstack.com.
We're happy to help! 🙏
You can take a look at example projects on GitHub:
Interested in learning more about log levels in Rails?
Check out our Intro guide to Ruby on Rails logging.
Add custom data to multiple log lines using with block:
In Rails, Devise, any other Warden-based authentication, and Clearance users are added automatically. With other authentication, return the user from the Rack environment:
The hash is logged as context.user on every line of the request, including the Started and Completed lines, which a with_context block in a controller can't reach. For other per-request context, use a Rack middleware inserted before Logtail::Integrations::Rack::HTTPEvents. See the example project.
The Authorization, Proxy-Authorization, Cookie and Set-Cookie headers are logged as [FILTERED] out of the box, starting with logtail-rack 0.2.7.
Starting with logtail-rack 0.2.9, secrets in query strings and in Referer and Location URLs are logged as [FILTERED] too. This covers every query parameter whose name contains passw, secret, token, _key, crypt, salt, certificate, otp, ssn, cvv or cvc. In Rails, logtail-rails 0.3.0 and newer filter these URLs with your app's filter_parameters instead.
In Rails or Rack, you can filter more headers and sensitive parameters:
To log every header or query parameter unfiltered, set http_header_filters or query_string_filters to an empty array.
You can prevent logger from sending certain logs to Better Stack:
See Logtail::LogEntry for available attributes of the block parameter.
Starting with Rails 8.1, you can use the new Structured Events system to send structured data to Better Stack. The logtail-rails gem automatically subscribes to these events and logs them as structured log entries in case you've used Logtail::Logger.create_default_logger to initialize.
This is particularly useful for tracking key business events or application-specific actions with rich, queryable data, without having to format them into a log message.
When you use Rails.event.notify, the logtail-rails gem captures the event name, payload, context, tags, and source location, and sends it all as a structured log to Better Stack.
If you're using OpenTelemetry instrumentation for PostgreSQL (pg gem), by default it sanitizes SQL queries in traces, replacing values with ?. This is done to prevent leaking sensitive data.
However, seeing the full query with values can be very helpful for debugging. You can configure the instrumentation to include the raw SQL statement.
This allows you to see the exact queries being run in your application traces, providing more context for performance analysis and troubleshooting.
To disable query sanitization for the pg instrumentation, set the db_statement option to :include in the use_all call of your OpenTelemetry initializer. This is typically done in config/initializers/opentelemetry.rb for a Rails application.
Including raw SQL queries in your traces might expose sensitive information like user IDs, e-mails, or other PII. Ensure you have other measures in place to protect this data or that you are comfortable with this information appearing in your traces.
We use cookies to authenticate users, improve the product user experience, and for personalized ads. Learn more.