OpenTelemetry for Ruby on Rails
OpenTelemetry for Ruby instruments Rails and the gems around it (Action Pack, Active Record, Active Job, Sidekiq, Net::HTTP, Faraday, Redis, pg and more) from one initializer.
What you get
- Every request as a trace, with its database calls and outgoing HTTP calls, in Traces.
- Requests matched to your business flows by service and route on our side, so you see "checkout is failing at place order" rather than a list of endpoints.
- Exceptions grouped into Issues, slow and N+1 database queries on each database's page, and deploys found from
service.version. - Alerts, incidents and the on-call agent, which reads these traces when something breaks.
Set it up
1. Add the gems
bundle add opentelemetry-sdk opentelemetry-exporter-otlp opentelemetry-instrumentation-all
2. Add an initializer
# config/initializers/opentelemetry.rb
require "opentelemetry/sdk"
require "opentelemetry/exporter/otlp"
require "opentelemetry/instrumentation/all"
OpenTelemetry::SDK.configure { |c| c.use_all }
It has to run after Rails is loaded, which an initializer does. Configured before the framework is required, it instruments nothing.
3. Point it at Flowhawk
First create an ingest key: in the app, open Settings > API keys and pick Services. In the examples below, KEY stands for that key. Keep it out of your repository, like any other secret.
OTEL_SERVICE_NAME=orders
OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.flowhawk.dev
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer%20KEY
OTEL_RESOURCE_ATTRIBUTES=deployment.environment=production,service.version=1.4.2
The space in the header is written %20. Set service.version to your release, so a deploy shows as a change next to the flows it made better or worse.
Check it arrived
Open Setup in the app. It lists each service that sent data in the last 15 minutes. If yours isn't there, Help and troubleshooting says why telemetry can be refused (a wrong key, an empty balance) and how to see it.
Common questions
Is there a Flowhawk SDK for Ruby?
It isn't on RubyGems yet. Plain OpenTelemetry as above works today: Flowhawk matches your requests to flows by service and route on our side.
My app runs on Heroku. What about logs?
Add a Heroku log drain. Router lines then show every request's status next to your traces.