Send OpenTelemetry from Rails to your Mac
Ruby instruments Rails, the HTTP clients, and the database from one initializer.
Before you start
Section titled “Before you start”- Loggerhead is open.
- You know the effective port. Open Collectors → Loggerhead receiver → Connection and copy the HTTP port. The first workspace uses 4318. See Ports and the effective port.
Step 1: add the gems
Section titled “Step 1: add the gems”gem 'opentelemetry-sdk'gem 'opentelemetry-exporter-otlp'gem 'opentelemetry-instrumentation-all'Then run bundle install.
Step 2: write the initializer
Section titled “Step 2: write the initializer”require 'opentelemetry/sdk'require 'opentelemetry/instrumentation/all'
OpenTelemetry::SDK.configure do |c| c.service_name = 'my-rails-app' c.use_allendStep 3: set the endpoint
Section titled “Step 3: set the endpoint”OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318The Ruby exporter speaks HTTP with protobuf and needs no protocol setting.
Start the server with bin/rails server and open one page.
What arrives
Section titled “What arrives”| Signal | State |
|---|---|
| Traces | Every request, with the controller, the view, and each SQL statement. |
| Metrics | Only what you record yourself. The Ruby metrics SDK is young. |
| Logs | Not from these gems. Send the Rails log through a branch collector. See Docker branch example. |
Tag the environment
Section titled “Tag the environment”OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=stagingSee Workspaces and environments.
Then read it with your agent
Section titled “Then read it with your agent”- Open Traces in Loggerhead and click a request to open its waterfall.
- Connect your coding agent once, and it reads the same data. See Claude Code.