Skip to content

Ruby OpenTelemetry instrumentation

Instrument a Ruby on Rails application with OpenTelemetry using the opentelemetry-instrumentation-all gem, which installs instrumentation for Rails, Active Record, Rack, Net::HTTP, and the other libraries in a typical Rails stack. Requests, database queries, and outbound calls are traced with a single initializer.

  • A Ruby on Rails application (the same setup works for Sinatra or any Rack app).
  • Ruby 3.0 or newer.
  • Your Osuite ingest token and region.
  1. Add the SDK, the OTLP exporter, and the all-in-one instrumentation gem to your bundle.

    Terminal window
    bundle add opentelemetry-sdk opentelemetry-exporter-otlp opentelemetry-instrumentation-all
  2. Create config/initializers/opentelemetry.rb and configure the SDK. c.use_all enables every bundled instrumentation library it detects.

    require 'opentelemetry/sdk'
    require 'opentelemetry/exporter/otlp'
    require 'opentelemetry/instrumentation/all'
    OpenTelemetry::SDK.configure do |c|
    c.service_name = '<service-name>'
    c.use_all
    end
  3. Set the exporter environment variables.

    Terminal window
    export OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.<region>.osuite.io:443
    export OTEL_EXPORTER_OTLP_HEADERS=x-osuite-ingest-token=<your-ingest-token>
    export OTEL_SERVICE_NAME=<service-name>
    export OTEL_RESOURCE_ATTRIBUTES=service.environment=production

    OTEL_SERVICE_NAME and c.service_name in the initializer set the same thing — the explicit c.service_name above wins, so keep the two in sync or drop one of them.

    The https:// scheme is required — the OTLP exporter takes a URL and Osuite only accepts OTLP over TLS.

The initializer loads at boot, so no change to how you start the app is needed:

Terminal window
rails server

What you should see

Send a request to any route. The service appears in APM within a minute with a trace per request, showing the controller action, Active Record queries, and outbound HTTP calls as nested spans.

If no traces appear, confirm the initializer ran (Rails logs OpenTelemetry::SDK instrumentation messages at boot) and that the environment variables are set in the process that serves requests. In clustered Puma or Unicorn, move OpenTelemetry::SDK.configure into the post-fork hook as noted above.

No data in Osuite after a few minutes? Work through these checks.

  • Endpoint — confirm the exporter targets exactly ingest.<region>.osuite.io:443 for your region, over TLS.
  • Token — confirm the ingest header carries a valid <your-ingest-token> and has not been rotated.
  • Pipeline — confirm the signal you expect (traces, logs, or metrics) is wired into an active pipeline with the otlp/osuite exporter attached.
  • Export errors — check the application or Collector logs for OTLP export failures (auth, DNS, TLS, connection refused).
  • Network — confirm the host has outbound access to the ingest endpoint on port 443.
  • Timing — allow up to a minute for the first data to appear before assuming a failure.

Still stuck? Ask the Investigation Agent or contact support.