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.
For Ruby on Rails application deployed on Kubernetes, you need to install OTel Collector agent in your k8s infra to collect and send traces to SigNoz Cloud. You can find the instructions to install OTel Collector agent here.
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=http://localhost:4318 \
rails server
<service_name>: Name of service. For example,sampleRailsApp
From Windows, there are two ways to send data to SigNoz Cloud.
- Send traces directly to SigNoz Cloud
- Send traces via OTel Collector binary (recommended)
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/initializers/opentelemetry.rb of your Ruby on Rails application.
require 'opentelemetry/sdk'
require 'opentelemetry/exporter/otlp'
require 'opentelemetry/instrumentation/all'
OpenTelemetry::SDK.configure do |c|
c.add_span_processor(
OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
OpenTelemetry::Exporter::OTLP::Exporter.new(
endpoint: 'ingest.<region>.signoz.cloud:443',
headers: { 'signoz-ingestion-key' => '<your-ingestion-key>' }
)
)
)
c.resource = OpenTelemetry::SDK::Resources::Resource.create({
OpenTelemetry::SemanticConventions::Resource::HOST_NAME => '<your-host-name>',
})
c.service_name = '<service_name>' # The name of the application.
c.use_all() # The libraries supported by automatic OpenTelemetry observation.
end
Step 3. Running your Ruby application
Run the application using the below:
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/initializers/opentelemetry.rb of your Ruby on Rails application.
require 'opentelemetry/sdk'
require 'opentelemetry/exporter/otlp'
require 'opentelemetry/instrumentation/all'
OpenTelemetry::SDK.configure do |c|
c.add_span_processor(
OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
OpenTelemetry::Exporter::OTLP::Exporter.new(
endpoint: 'http://localhost:4318'
)
)
)
c.resource = OpenTelemetry::SDK::Resources::Resource.create({
OpenTelemetry::SemanticConventions::Resource::HOST_NAME => '<your-host-name>',
})
c.service_name = '<service_name>' # The name of the application.
c.use_all() # The libraries supported by automatic OpenTelemetry observation.
end
Step 4. Running your Ruby application
Run the application using the below:
rails server
<service_name>is name of your service
In case you have OtelCollector Agent in different VM, replace localhost:4318 with <IP Address of the VM>:4318.
Send Traces to Self-Hosted SigNoz
You can follow these steps to send your traces directly to your Self-Host SigNoz instance.
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=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.
Sample Ruby on Rails application
We have included a sample Ruby on Rails application with README.md at Sample Rails App Github Repo.