Skip to main content
Logfire for Ruby

Ruby observability with OpenTelemetry

OpenTelemetry-native observability for Rails and any Ruby app, from the team behind Pydantic. Two gems instrument your requests, queries and outbound calls, and you query all of it with SQL. Free for 10 million spans, logs, and metrics a month.

Start free with Ruby As Markdown
Getting started

Configure the SDK

gem install opentelemetry-sdk opentelemetry-exporter-otlp opentelemetry-instrumentation-all
export OTEL_EXPORTER_OTLP_ENDPOINT=https://logfire-us.pydantic.dev
export OTEL_EXPORTER_OTLP_HEADERS='Authorization=your-write-token'
require 'opentelemetry/sdk'
require 'opentelemetry/exporter/otlp'
require 'opentelemetry/instrumentation/all'

OpenTelemetry::SDK.configure do |c|
  c.service_name = 'hello-ruby'
  # Without use_all you get only the spans you write yourself.
  c.use_all
end

tracer = OpenTelemetry.tracer_provider.tracer('hello-ruby')

tracer.in_span('Hello World') do |span|
  # your work here
end

# No at_exit hook in the Ruby SDK: flush before the process exits.
OpenTelemetry.tracer_provider.shutdown

There is no Logfire Ruby SDK to adopt: these are the standard OpenTelemetry gems, and Logfire is the OTLP endpoint they export to. Use the EU endpoint instead if your project is in the EU region. Full details are in the Ruby setup guide.

What you get

One request, one trace

A Logfire trace of a Ruby request: the service's own spans, PG queries and the outbound Net::HTTP call, with an errored request below

What lands in Logfire:

  • your in_span blocks, nested as they ran
  • each ActiveRecord/PG query, timed
  • the outbound Net::HTTP call
  • an error recorded on the span that raised, not just at the top
How it works

Standard OpenTelemetry, hosted backend

Rails and Rack instrumented for you

The OpenTelemetry Ruby contrib gems cover Rails and Rack, along with common database and HTTP libraries such as ActiveRecord, Sidekiq, Net::HTTP, Faraday, Redis, and PostgreSQL. Incoming requests become traces without instrumenting each call site, and your own spans nest inside them.

Blocks, not manual start and finish

tracer.in_span('...') do |span| closes the span even if the block raises, so an exception is recorded on the span rather than the span being lost. The failure case is the one you most want telemetry for, so the safe form is also the idiomatic one.

Standard OTLP, so genuinely no lock-in

Configuration is OTEL_ environment variables against the standard OpenTelemetry Ruby SDK. Your Gemfile contains OpenTelemetry gems and nothing of ours, so repointing at a different backend is a config change rather than a migration.

Traces now, metrics and logs as Ruby's SDKs land

Logfire ingests traces, metrics, and logs in one project, and the setup above sends traces with the stable OpenTelemetry Ruby SDK. Ruby's metrics and logs SDKs are still pre-1.0 — opentelemetry-metrics-sdk and opentelemetry-logs-sdk — and the OTLP logs exporter still ships as experimental, so treat those as available-but-early rather than a finished path. Traces are the part that is production-ready today, and everything you send is queryable with the same SQL.

SQL instead of a query language you have to learn

Query your traces, metrics, and logs with PostgreSQL-compatible SQL. Any question you can express in SQL becomes a dashboard, an alert, or an ad-hoc investigation, and AI assistants are already fluent in it.

Query

Query your telemetry with SQL

select
  attributes->>'http.route' as route,
  count(*) as requests,
  avg(duration) as avg_seconds
from records
where duration > 1
group by route
order by avg_seconds desc;

Your traces, metrics, and logs are queryable with real SQL, no proprietary query language to learn. Any question you can express becomes a dashboard, an alert, or a one-off investigation.

Proof

In production

“You can tell that Pydantic Logfire was built by people who use it.”
Dennis Griffin, VP of Engineering, Sophos Read the case study
Decision guide

Is Logfire right for you?

Choose Logfire if

  • You run Rails or Rack and want request traces without a proprietary agent
  • You want only OpenTelemetry gems in your Gemfile
  • You want to query traces, metrics, and logs with PostgreSQL-compatible SQL
  • You do not want to run Jaeger, Prometheus, and storage yourself
  • You want the option to repoint at another backend without a rewrite

Choose a vendor APM if

  • You want a vendor-maintained Ruby SDK with vendor-specific APIs
  • You are already deeply integrated with a specific APM vendor's ecosystem
  • You need a vendor-only integration or compliance capability Logfire does not offer
FAQ

Common questions

Is there a Logfire SDK for Ruby?

No. Ruby uses the standard OpenTelemetry Ruby SDK, and Logfire is the OTLP backend it exports to, so nothing proprietary enters your Gemfile. First-party Logfire SDKs exist for Python, TypeScript, and Rust.

Does this work with Rails?

Yes. The OpenTelemetry Ruby contrib instrumentation gems cover Rails and Rack, so incoming requests become spans automatically, with ActiveRecord queries and outbound HTTP calls attached as child spans. Your own in_span blocks then nest inside the request span.

Why is nothing arriving in Logfire?

Check that both gems are installed, opentelemetry-sdk and opentelemetry-exporter-otlp, that the endpoint matches your project's data region, and that the Authorization header carries a valid write token. Short-lived scripts also need the exporter to flush before the process exits.

Why use in_span rather than manual start and finish?

The block form closes the span even when the block raises, so an exception is recorded on the span instead of the span being lost entirely. That is exactly the case you most want telemetry for, so the block form is the safer default.

Am I locked in to Logfire?

No. Configuration is standard OTEL_ environment variables against the standard SDK, and your code references OpenTelemetry types only. Repoint the endpoint at another OpenTelemetry-compatible backend, or at your own collector, whenever you want.

Start seeing your Ruby app

Get started with 10 million free spans, logs, and metrics per month. No credit card required.