Ruby Logo

Monitoring & Observability

Instrument code with TracePoint, ActiveSupport::Notifications, metrics, and tracing to understand production behavior.

Home Ruby Monitoring & Observability

Monitoring & Observability

Observability goes beyond logs: combine metrics, traces, and events to answer “what is happening?” without redeploying code. Ruby offers hooks like ActiveSupport::Notifications, TracePoint, and third-party agents that integrate with Datadog, Honeycomb, or OpenTelemetry.

Three pillars of observability

Metrics

Quantitative measures (request latency, Sidekiq queue depth). Send via StatsD, Prometheus exporters, or OpenTelemetry metrics APIs.

Logs

High-cardinality, structured events (see Logging topic) that support full-text search and incident forensics.

Traces

End-to-end request timelines across services. Capture spans in controllers, jobs, and external HTTP clients.

Instrument with Notifications

ActiveSupport::Notifications.subscribe('rubydev.lesson.published') do |name, start, finish, id, payload| duration = (finish - start) * 1000 Rails.logger.info(name: name, duration:, lesson_id: payload[:lesson_id]) StatsD.timing('lesson.publish', duration, tags: %W[lesson:\#{payload[:lesson_id]}]) end def publish_lesson(lesson) ActiveSupport::Notifications.instrument('rubydev.lesson.published', lesson_id: lesson.id) do LessonPublisher.new.call(lesson) end end

Wrap critical flows (`LessonPublisher`, AI responses, Sidekiq jobs) so dashboards can chart latency and throughput without extra code.

Low-level instrumentation

TracePoint.trace(:call) do |tp| next unless tp.defined_class.to_s.start_with?('RubyTopics::') Rails.logger.debug(event: 'trace', method: tp.method_id, path: tp.path) end # Use rbtrace for production-safe sampling without halting the process

Combine TracePoint with sampling to avoid performance degradation. For performance analysis, pair with `stackprof` or `flamegraph` to visualise call stacks.

Monitoring checklist

  1. Alert on failing Sidekiq jobs, queue latency, and AI response times; route incidents to Slack with PagerDuty escalation.
  2. Dashboards should correlate metrics (error rate, request latency) with deploy markers to spot regressions quickly.
  3. After incidents, add postmortem action items—instrument the missing signals or tighten alert thresholds.

Quick Navigation

Related Topics

Video Tutorial

Watch and learn monitoring & observability

Pro Tip: After reading through the content above, watch this video to reinforce your understanding and see the concepts in action!