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.
Prerequisites
Section titled “Prerequisites”- 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.
Install and configure
Section titled “Install and configure”-
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 -
Create
config/initializers/opentelemetry.rband configure the SDK.c.use_allenables 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_allend -
Set the exporter environment variables.
Terminal window export OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.<region>.osuite.io:443export OTEL_EXPORTER_OTLP_HEADERS=x-osuite-ingest-token=<your-ingest-token>export OTEL_SERVICE_NAME=<service-name>export OTEL_RESOURCE_ATTRIBUTES=service.environment=productionOTEL_SERVICE_NAMEandc.service_namein the initializer set the same thing — the explicitc.service_nameabove 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.
Run Rails with instrumentation
Section titled “Run Rails with instrumentation”The initializer loads at boot, so no change to how you start the app is needed:
rails serverVerify in Osuite
Section titled “Verify in Osuite”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.
Troubleshooting
Section titled “Troubleshooting”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:443for 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/osuiteexporter 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.