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?
OpenTelemetry is an open-source observability framework for distributed tracing (including logs and errors) and OpenTelemetry metrics.
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 alternatives 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 example 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 APM 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 started with Uptrace by downloading a DEB/RPM package or a pre-compiled Go binary.
What's next?
Next, instrument more operations, for example, database queries and network calls. You can also learn about OpenTelemetry Ruby API to create your own instrumentations.
Popular instrumentations: