Monitor Ruby On Rails performance with OpenTelemetry

Ruby on Rails is a web-application framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.

This article explains how you can monitor and optimize Rails performance using OpenTelemetry observability framework.

What is OpenTelemetry?

OpenTelemetryopen in new window is an open-source observability framework for distributed tracingopen in new window (including logs and errors) and OpenTelemetry metricsopen in new window.

Otel allows developers to collect and export telemetry data in a vendor agnostic way. With OpenTelemetry, you can instrument your application once and then add or change vendors without changing the instrumentation, for example, here is a list popular DataDog alternativesopen in new window that support OpenTelemetry.

OpenTelemetry is available for most programming languages and provides interoperability across different languages and environments.

Rails instrumentation

To instrument Ruby on Rails app, you need a corresponding Rails OpenTelemetry instrumentation:

gem install opentelemetry-instrumentation-rails

If you use bundler, add opentelemetry-instrumentation-sinatra to your Gemfile.

Getting started

To get started, call use with the name of the instrumentation:

require 'uptrace'
require 'opentelemetry-instrumentation-rails'

Uptrace.configure_opentelemetry(dsn: '') do |c|
  c.use 'OpenTelemetry::Instrumentation::Rails'
end

Alternatively, you can call use_all to install all available instrumentations:

require 'uptrace'
require 'opentelemetry-instrumentation-rails'

Uptrace.configure_opentelemetry(dsn: '') do |c|
  c.use_all
end

See exampleopen in new window for details.

Instrumenting ActiveRecord

Just like with Rails, you need to install ActiveRecord instrumentation:

gem install opentelemetry-instrumentation-active_record

And call use with the name of the instrumentation:

require 'uptrace'
require 'opentelemetry-instrumentation-active_record'

Uptrace.configure_opentelemetry(dsn: '') do |c|
  c.use 'OpenTelemetry::Instrumentation::ActiveRecord'
end

What is Uptrace?

Uptrace is a source-available APMopen in new window powered by OpenTelemetry and ClickHouse. It allows you to identify and fix bugs in production faster knowing what conditions lead to which errors.

You can get startedopen in new window with Uptrace by downloading a DEB/RPM package or a pre-compiled Go binary.

What's next?

Next, instrumentopen in new window more operations, for example, database queries and network calls. You can also learn about OpenTelemetry Ruby APIopen in new window to create your own instrumentations.

Popular instrumentations:

Last Updated: