Monitor your Ruby on Rails App using Signoz + OpenTelemetry

Leunardus Vederis
3 min readNov 25, 2021

--

When we build a Web App using Ruby on Rails. The first time, we see our app is very fast, low-latency, and had fewer errors. As time goes on, the users come and come again. The latency comes to be high, website loading slow, error always coming which will result on decrease your user satisfaction and impact to your business.

To solve the problem, We need to identify Which part of our application needs to be upgraded. Database or Hosting? Which of our Model / View / Controller come to be slow and most accessed by the users? How long on average our response time? Sadly, when we check in our Cloud Service Provider, we only can see CPU, RAM, and Disk Usage.

Application Performance Monitoring (APM) is the answer for our problem We arise before. There are so many APM that already exist till this article was written. There are New Relic, DataDog, Traceview, etc. Now I want to share about Signoz one of the APM apps which just released 8 months ago.

Why Signoz?

Most of the current APM is SaaS and Closed source which results in two problems for us as developer/business owners. First, They might be expensive because the bigger your App the bigger your Expense without any data transparency, and it’s up to them to change the price tag. Second, some of our data might be going to third-party services. Some of business model should handle our data on our server such as security / health. Signoz will answer all of those problems. They are self-hosted, cheap, open-source and only you handle your data. So let’s go dive in.

Preparation

The things that you need:

  • VPS (I use Digital Ocean, 2 GB RAM, 1 vCPU) which only 10$
  • Your RoR App current only support version 6.00, v7.0.0 not yet.

Installation

For Installation you can go to https://signoz.io/docs/deployment/docker/

later you can access in http://#{Your IP HERE}:3000

Ruby on Rails Setup

Add this in your gemfile

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

then run bundle install as usual.

create file config/initializers/opentelemetry.rb and paste this code

for Rails ≥ 7.0.0

require 'opentelemetry/sdk'
require 'opentelemetry/exporter/otlp'
require 'opentelemetry/instrumentation/rails'


OpenTelemetry::SDK.configure do |c|
c.service_name = "Your Service Name here"
c.use_all(
{ 'OpenTelemetry::Instrumentation::ActionView' => { enabled: false } }
)
end

for Rails < 7.0.0

require 'opentelemetry/sdk'
require 'opentelemetry/exporter/otlp'
require 'opentelemetry/instrumentation/rails'


OpenTelemetry::SDK.configure do |c|
c.service_name = "Your Service Name here"
c.use_all
end

Setup your Environment

OTEL_TRACES_EXPORTER: 'otlp'
OTEL_METRICS_EXPORTER: 'none'
OTEL_EXPORTER_OTLP_ENDPOINT: "http://#{Your IP HERE}:55681"

Then run your Rails app. It will show the Monitoring in your Signoz.

Troubleshooting

If not reported to signoz and you want to show in your puma console. Change the Environment File to

OTEL_TRACES_EXPORTER: 'console'
OTEL_LOG_LEVEL: 'debug'
OTEL_METRICS_EXPORTER: 'none'
OTEL_EXPORTER_OTLP_ENDPOINT: "http://#{Your IP HERE}:55681"

Any Questions? Feel free to comment here below.

--

--

Leunardus Vederis

Ruby on Rails Developer at Virtual Spirit Technology, Sdn. Bhd