Ruby on Rails OpenTelemetry Instrumentation

This document contains instructions on how to set up OpenTelemetry instrumentation in your Ruby on Rails applications and view your application traces in SigNoz.

Send Traces to SigNoz Cloud

Based on your application environment, you can choose the setup below to send traces to SigNoz Cloud.

From VMs, there are two ways to send data to SigNoz Cloud.

Send traces directly to SigNoz Cloud

Step 1. Install dependencies

Install dependencies related to OpenTelemetry SDK and exporter using gem.

gem install opentelemetry-sdk
gem install opentelemetry-exporter-otlp
gem install opentelemetry-instrumentation-all

Include the required packages into your gemfile.

gem 'opentelemetry-sdk'
gem 'opentelemetry-exporter-otlp'
gem 'opentelemetry-instrumentation-all'

Run the bundle install command:

bundle install

Step 2. Initialize the OpenTelemetry SDK

Initialize the otel sdk by adding below lines to config/environment.rb of your Ruby on Rails application.

require 'opentelemetry/sdk'
require_relative 'application'

OpenTelemetry::SDK.configure do |c|
  c.use_all
end

Rails.application.initialize!

Step 3. Running your Ruby application

Run the application using the below:

OTEL_EXPORTER=otlp \
OTEL_SERVICE_NAME=<service_name> \
OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.<region>.signoz.cloud:443 \
OTEL_EXPORTER_OTLP_HEADERS=signoz-ingestion-key=<your-ingestion-key> \
rails server
  • Set the <region> to match your SigNoz Cloud region
  • Replace <your-ingestion-key> with your SigNoz ingestion key.
  • <service_name> is name of your service

Send traces via OTel Collector binary

Step 1. Install OTel Collector binary

OTel Collector binary helps to collect logs, hostmetrics, resource and infra attributes.

You can find instructions to install OTel Collector binary here in your VM.

Step 2. Install dependencies

Install dependencies related to OpenTelemetry SDK and exporter using gem.

gem install opentelemetry-sdk
gem install opentelemetry-exporter-otlp
gem install opentelemetry-instrumentation-all

Include the required packages into your gemfile.

gem 'opentelemetry-sdk'
gem 'opentelemetry-exporter-otlp'
gem 'opentelemetry-instrumentation-all'

Run the bundle install command:

bundle install

Step 3. Initialize the OpenTelemetry SDK

Initialize the otel sdk by adding below lines to config/environment.rb of your Ruby on Rails application.

require 'opentelemetry/sdk'
require_relative 'application'

OpenTelemetry::SDK.configure do |c|
  c.use_all
end

Rails.application.initialize!

Step 4. Running your Ruby application

Run the application using the below:

OTEL_EXPORTER=otlp \
OTEL_SERVICE_NAME=<service_name> \
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 \
rails server
  • <service_name> : Name of service. For example, sampleRailsApp

In case you have OtelCollector Agent in different VM, replace localhost:4318 with <IP Address of the VM>:4318.

Tutorials

Here's a tutorial with step by step guide on how to install SigNoz and start monitoring a sample Ruby on Rails app.

Sample Ruby on Rails application

We have included a sample Ruby on Rails application with README.md at Sample Rails App Github Repo.

Feel free to use this repo to test out OpenTelemetry instrumentation and how to send telemetry data to SigNoz.

Was this page helpful?