# Instrumenting Rails with OpenTelemetry

# Prerequisites

  • Ruby 2.6+

# Introduction

In this tutorial we will instrument a basicopen in new window Rails app using OpenTelemetry instrumentation.

# Instrumenting Rails app

  • Step 1. Let's start by downloading the source code:
git clone https://github.com/uptrace/uptrace-ruby.git
cd example/rails
  • Step 2. Install the required dependencies:
bundle install
  • Step 3. Edit main.ru to configure OpenTelemetry to export data to Uptrace:
require 'uptrace'

# copy your project DSN here or use UPTRACE_DSN env var
Uptrace.configure_opentelemetry(dsn: '') do |c|
  c.service_name = 'myservice'
  c.service_version = '1.0.0'
  • Step 4. Edit main.ru to instrument the Rails app:
require 'opentelemetry-instrumentation-rails'

Uptrace.configure_opentelemetry(dsn: '') do |c|
  c.use 'OpenTelemetry::Instrumentation::Rails'
UPTRACE_DSN="https://<token>@api.uptrace.dev/<project_id>" rackup main.ru

The full code is available at GitHubopen in new window.

# What is next?

By now, you should have a Django app with instrumented views. Next, instrumentopen in new window more operations (for example, database queries) or learn about OpenTelemetry API to create your own instrumentations.