Instrumenting Rails with OpenTelemetry

Prerequisites

  • Ruby 2.6+

Instrumenting Rails app

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'
end
  • 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'
end
UPTRACE_DSN="https://<token>@api.uptrace.dev/<project_id>" rackup main.ru

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.