---
title: "Send OpenTelemetry from Rails to your Mac"
description: "Add the OpenTelemetry gems, write one initializer, and read the traces of your Rails app in one window."
source: "https://getloggerhead.com/docs/send-telemetry/rails/"
---

# Send OpenTelemetry from Rails to your Mac

> Add the OpenTelemetry gems, write one initializer, and read the traces of your Rails app in one window.

Ruby instruments Rails, the HTTP clients, and the database from one initializer.

## 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](/docs/getting-started/ports-and-the-effective-port/).

## Step 1: add the gems

```ruby title="Gemfile"
gem 'opentelemetry-sdk'
gem 'opentelemetry-exporter-otlp'
gem 'opentelemetry-instrumentation-all'
```

Then run `bundle install`.

## Step 2: write the initializer

```ruby title="config/initializers/opentelemetry.rb"
require 'opentelemetry/sdk'
require 'opentelemetry/instrumentation/all'

OpenTelemetry::SDK.configure do |c|
  c.service_name = 'my-rails-app'
  c.use_all
end
```

## Step 3: set the endpoint

```bash title=".env"
OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318
```

The Ruby exporter speaks HTTP with protobuf and needs no protocol setting.

Start the server with `bin/rails server` and open one page.

## 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](/docs/collectors/docker-branch-example/). |

## Tag the environment

```bash
OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=staging
```

See [Workspaces and environments](/docs/getting-started/workspaces-and-environments/).

## Then read it with your agent

1. Open **Traces** in Loggerhead and click a request to open its waterfall.
2. Connect your coding agent once, and it reads the same data. See [Claude Code](/docs/connect-your-ai-tool/claude-code/).
