Observability for Rails at Scale: Beyond rails logs
Your engineering team deserves better when it comes to observability on production environment.
Most Rails teams don’t have an observability problem. They have a log volume problem disguised as one.
You know the scene: an incident fires, someone greps through gigabytes of unstructured text, finds a stack trace interleaved with three other requests, and eventually reconstructs a timeline by hand. The logs were there. The answers weren’t.
At scale, rails logs stop being an operational tool and become an archaeological dig. Observability is the discipline of making production systems interrogable not just verbose. This post covers the four pillars that actually matter for a Rails stack running at scale: structured logging that machines can query, OpenTelemetry tracing that survives process boundaries, metrics that reflect user pain (not just CPU), and an alerting philosophy that respects your on-call engineer’s sanity.
Structured Logging: JSON or Nothing
The first migration any serious Rails deployment needs is from human-readable text logs to machine-parseable structured output. Rails Semantic Logger is the pragmatic choice here, replacing the default logger with async, structured output while collapsing Rails’ multi-line request logs into single JSON events.
The rationale isn’t aesthetic. Text logs span multiple lines (stack traces being the obvious offender), require brittle regex parsing for alerting, and break every time someone tweaks a log message. JSON logs expose fields controller, action, status, duration, trace_id that your log aggregator can index and alert on without parsing gymnastics.
In a containerized environment (Kubernetes, ECS, Heroku), configure Semantic Logger to write JSON to stdout and let the platform handle collection:
config.rails_semantic_logger.appenders do |appenders|
appenders.add(io: $stdout, formatter: :json)
end
The critical integration: inject trace_id into every log line. This single field connects your logs to your traces, letting you jump from a Grafana alert to the exact logs from the affected request. If your logs and traces aren’t correlated, you’re running two separate observability stacks that happen to share a timestamp.
OpenTelemetry: Traces That Cross the Sidekiq Boundary
Rails request tracing is table stakes. The hard part is Sidekiq. A single user action can fan out into a dozen asynchronous jobs, and without propagated trace context, those jobs are black boxes.
OpenTelemetry’s Ruby SDK auto-instruments Rails controllers, ActiveRecord, and Sidekiq, but the default behavior for child jobs often produces separate trace IDs rather than a connected trace. This defeats the purpose: you want one trace ID that follows the request from controller → parent job → child job → grandchild job.
The solution is explicit context propagation. When enqueuing a job, ensure the current trace context is serialized into the job payload. The opentelemetry-instrumentation-sidekiq gem handles much of this, but verify that your middleware chain preserves the traceparent header. A community discussion on the OpenTelemetry Ruby repo highlights the common pitfall: child jobs receive a traceparent with the parent’s trace ID but generate a new trace ID anyway unless the middleware is correctly configured.
For custom spans around business logic, instrument the boundaries that matter:
tracer = OpenTelemetry.tracer_provider.tracer('checkout-service')
tracer.in_span('checkout.process', attributes: {
'order.id' => order.id,
'order.total_cents' => order.total_cents,
'user.tier' => user.tier
}) do |span|
# payment, inventory, notification logic
end
The span attributes become queryable dimensions in your tracing backend. When P95 checkout latency spikes, you can filter by user.tier or order.total_cents to determine whether the regression affects all traffic or a specific segment.
Metrics That Reflect User Pain
CPU utilization is an infrastructure metric. It tells you the machine is working. It doesn’t tell you whether users are waiting.
P95 latency by endpoint is the metric that correlates with user experience. P50 hides the pain if 5% of users wait 3 seconds while the median is 200ms, your average looks fine and your users are miserable. Instrument every controller action with prometheus_exporter or Yabeda, segmented by endpoint. The dashboard should make it trivially easy to answer: “Which endpoints are violating our latency SLO right now?”
Job queue depth is the leading indicator for async backlog. A rising sidekiq_jobs_waiting_count means work is arriving faster than it’s draining. Yabeda Sidekiq plugin exposes this out of the box, along with sidekiq_queue_latency ie. the time between enqueue and execution. Queue latency is often more actionable than queue depth: a deep queue with fast processing is fine; a shallow queue with growing latency means workers are stuck.
For Sidekiq specifically, track:
sidekiq_jobs_waiting_countby queuesidekiq_queue_latencyby queue (seconds since oldest job enqueued)sidekiq_jobs_failed_totalby worker classsidekiq_job_runtimeP95 by worker class
The failure metric segmented by class is where you’ll find the slow-burn problems: a job that fails 2% of the time and retries silently is eating capacity without triggering any threshold you’d notice from aggregate error rates.
Alerting Philosophy: Alert on Symptoms, Debug with Causes
The most important observability decision isn’t which metrics to collect. It’s what deserves an alert.
Microsoft’s guidance on actionable alerts is worth internalizing: an alert should fire only when a real problem exists, human intervention is required, and the recipient can actually do something about it. Everything else is noise that trains your team to ignore the alerts.
Alert on symptoms, not causes. A database CPU spike is a cause. Checkout error rate exceeding 5% is a symptom. The symptom is what users feel, and it’s what should wake someone up. The cause belongs on a dashboard, available for investigation once the symptom fires.
SLO-based alerting beats static thresholds. Instead of “alert if P95 > 500ms,” define an SLO: “99.9% of checkout requests complete in under 1 second.” Alert on the burn rate: how quickly you’re consuming your error budget. A burn rate of 14.4x means you’ll exhaust your monthly budget in about two days; that’s another alert. A burn rate of 2x is a ticket for tomorrow.
For Sidekiq, the SLO might be: “99% of email jobs execute within 5 minutes of enqueue.” Alert when the P99 queue latency breaches that threshold for more than a defined window. This catches worker starvation before users start complaining about missing emails.
Every alert needs a runbook. If the on-call engineer can’t determine within 15 minutes whether the alert is real and what to do about it, the alert is incomplete. Include a dashboard link, a runbook URL, and a clear description of user impact in the alert annotation.
The Feedback Loop
Observability is not a dashboard you build once. It’s a feedback loop: incidents reveal gaps, gaps become instrumentation, instrumentation prevents the next incident from being a mystery.
Start with the three metrics that map to user pain: endpoint P95 latency, error rate by endpoint, and Sidekiq queue latency. Correlate them with trace IDs in logs. Page only on SLO burn. Iterate from there.
The goal isn’t to have the most data. It’s to have the right data, at the moment you need it, with enough context to act. rails logs will always be there for tail -f in development. As I said in the beginning, production always deserves better.