> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bronto.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Send Ruby logs and traces to Bronto via OpenTelemetry

> Instrument Ruby and Rails applications with the OpenTelemetry Ruby SDK to send logs and traces to Bronto over OTLP via a local Collector.

This page covers instrumenting a Ruby application with the OpenTelemetry SDK to send **logs and traces** to Bronto over OTLP/HTTP via a local OTel Collector.

<Tip>
  If you don't have a Collector and want to export directly from your application to Bronto, see [Direct export to Bronto](#direct-export-to-bronto) at the bottom of this page.
</Tip>

## Prerequisites

* Ruby 3.0 or later
* Bundler
* A running OTel Collector configured to forward logs and traces to Bronto — see [Connect Open Telemetry to Bronto](/agent-setup/open-telemetry)
* [OpenTelemetry Ruby SDK documentation](https://opentelemetry.io/docs/languages/ruby/)

## Install dependencies

```ruby Gemfile theme={"dark"}
gem 'opentelemetry-api'
gem 'opentelemetry-sdk'
gem 'opentelemetry-logs-api'
gem 'opentelemetry-logs-sdk'
gem 'opentelemetry-exporter-otlp-logs'
```

```bash theme={"dark"}
bundle install
```

| Gem                                | Purpose                      |
| ---------------------------------- | ---------------------------- |
| `opentelemetry-api`                | Core OTel API                |
| `opentelemetry-sdk`                | SDK — resource configuration |
| `opentelemetry-logs-api`           | Logs API                     |
| `opentelemetry-logs-sdk`           | `LoggerProvider`, processors |
| `opentelemetry-exporter-otlp-logs` | OTLP/HTTP log exporter       |

## Configure the log bridge

Set up a `LoggerProvider` with an OTLP exporter and register it as the global logs provider.

```ruby configure_logging.rb theme={"dark"}
require 'opentelemetry/sdk'
require 'opentelemetry/logs/sdk'
require 'opentelemetry-exporter-otlp-logs'

def configure_otel_logging
  resource = OpenTelemetry::SDK::Resources::Resource.create(
    'service.name'           => 'my-service',
    'service.namespace'      => 'my-team',
    'deployment.environment' => 'production'
  )

  exporter = OpenTelemetry::Exporter::OTLP::Logs::LogsExporter.new(
    endpoint: 'http://localhost:4318/v1/logs'
  )

  processor = OpenTelemetry::SDK::Logs::Export::BatchLogRecordProcessor.new(exporter)

  logger_provider = OpenTelemetry::SDK::Logs::LoggerProvider.new(resource: resource)
  logger_provider.add_log_record_processor(processor)

  OpenTelemetry::Logs.logger_provider = logger_provider
end
```

Call `configure_otel_logging` once at application startup, before the first log statement.

## Configure the OTLP exporter

The `OtlpLogs::LogsExporter` in the snippet above connects to the OTel Collector on `localhost:4318`. If your Collector runs on a different host or port, update the `endpoint` accordingly.

## Set resource attributes

Resource attributes are attached to every log record exported from this process. Two attributes drive how Bronto organises incoming logs:

| OTel attribute      | Bronto concept | Description                                  |
| ------------------- | -------------- | -------------------------------------------- |
| `service.name`      | Dataset        | Groups logs from one service                 |
| `service.namespace` | Collection     | Groups related services or a team's services |

These are set via `Resource.create` in the setup above.

## Complete example

```ruby app.rb theme={"dark"}
require_relative 'configure_logging'

configure_otel_logging

# Emit log records through the OTel logs API directly
logger = OpenTelemetry::Logs.logger_provider.logger(name: 'my-service')

logger.on_emit(
  timestamp: Time.now,
  severity_number: OpenTelemetry::Logs::SeverityNumber::INFO,
  severity_text: 'INFO',
  body: 'Application started'
)

logger.on_emit(
  timestamp: Time.now,
  severity_number: OpenTelemetry::Logs::SeverityNumber::WARN,
  severity_text: 'WARN',
  body: 'Low disk space',
  attributes: { 'disk_free_gb' => 2.1 }
)
```

<Note>
  A direct bridge to Ruby's standard `Logger` class is not yet available in the official SDK. The example above emits log records via the OTel Logs API directly. Community bridges for popular frameworks (Rails, Sidekiq) are in development.
</Note>

## Verify delivery

After running your application, check both signals in Bronto:

* **Logs**: open the [Search](https://app.bronto.io/search) page and filter by the dataset name you set in `service.name` — your log records should appear within a few seconds.
* **Traces**: open the Explore Traces page and filter by the same `service.name` — your spans should appear within a few seconds.

If no logs appear, check:

* The OTel Collector is running and reachable at the configured endpoint.
* The Collector's pipeline includes a `logs` pipeline with an `otlp` receiver and the Bronto exporter — see [Connect Open Telemetry to Bronto](/agent-setup/open-telemetry).
* `configure_otel_logging` is called before the first log emission.

## Traces

<Tip>
  Add `opentelemetry-instrumentation-all` to your Gemfile and call `c.use_all` inside `OpenTelemetry::SDK.configure` to auto-instrument Rails, Rack, Active Record, Faraday, Redis, and more with no code changes. See [Ruby instrumentation libraries](https://opentelemetry.io/docs/languages/ruby/libraries/) for the full list.
</Tip>

### Install tracing dependencies

Add the tracing gems to your Gemfile:

```ruby Gemfile theme={"dark"}
gem 'opentelemetry-sdk'
gem 'opentelemetry-exporter-otlp'
```

```bash theme={"dark"}
bundle install
```

### Configure the tracer provider

The `opentelemetry-sdk` gem covers both logs and traces. Configure tracing via `OpenTelemetry::SDK.configure`:

```ruby configure_tracing.rb theme={"dark"}
require 'opentelemetry/sdk'
require 'opentelemetry-exporter-otlp'

OpenTelemetry::SDK.configure do |c|
  c.resource = OpenTelemetry::SDK::Resources::Resource.create(
    'service.name'           => 'my-service',
    'service.namespace'      => 'my-team',
    'deployment.environment' => 'production'
  )
  c.add_span_processor(
    OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
      OpenTelemetry::Exporter::OTLP::Exporter.new(
        endpoint: 'http://localhost:4318/v1/traces'
      )
    )
  )
end
```

### Creating spans

```ruby theme={"dark"}
tracer = OpenTelemetry.tracer_provider.tracer('my-service')

tracer.in_span('process-payment') do |span|
  span.set_attribute('payment.amount', 99.99)
  span.set_attribute('payment.currency', 'USD')
  # your code here
end
```

## GenAI semantic conventions

If your application calls an LLM, OpenTelemetry defines [GenAI semantic conventions](https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/gen-ai/gen-ai-spans.md). Ruby does not yet have first-party instrumentation that emits GenAI-semconv spans, so set the attributes yourself around each LLM call:

<Note>
  This page was verified on **July 17, 2026**. GenAI libraries and semantic conventions are evolving rapidly, so package configuration and emitted attributes can change between releases. Keep your instrumentation current and verify the fields emitted by the version you deploy.
</Note>

```ruby theme={"dark"}
tracer = OpenTelemetry.tracer_provider.tracer('my-service')

tracer.in_span('chat gpt-4o-mini') do |span|
  span.set_attribute('gen_ai.provider.name', 'openai')
  span.set_attribute('gen_ai.request.model', 'gpt-4o-mini')
  span.set_attribute('gen_ai.usage.input_tokens', 33)
  span.set_attribute('gen_ai.usage.output_tokens', 74)
  span.set_attribute('gen_ai.response.finish_reasons', ['stop'])
end
```

<Note>
  Message content (`gen_ai.input.messages` / `gen_ai.output.messages`) is opt-in by convention in languages with auto-instrumentation, off by default. Since you're setting attributes by hand here, apply the same discipline — gate prompt/response content behind your own config flag rather than always sending it.
</Note>

See [LLM Observability](/ai-features/llm-observability) for the full recommended attribute set and how to search and aggregate GenAI fields in Bronto.

## Direct export to Bronto

If you are not using an OTel Collector, export directly to Bronto by replacing the exporter configurations with the Bronto OTLP endpoints and your API key:

```ruby theme={"dark"}
# Logs
log_exporter = OpenTelemetry::Exporter::OTLP::Logs::LogsExporter.new(
  endpoint: 'https://ingestion.eu.bronto.io/v1/logs', # or ingestion.us.bronto.io
  headers: { 'x-bronto-api-key' => '<YOUR_API_KEY>' }
)

# Traces (inside OpenTelemetry::SDK.configure block)
c.add_span_processor(
  OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
    OpenTelemetry::Exporter::OTLP::Exporter.new(
      endpoint: 'https://ingestion.eu.bronto.io/v1/traces', # or ingestion.us.bronto.io
      headers: { 'x-bronto-api-key' => '<YOUR_API_KEY>' }
    )
  )
)
```

| Region | Logs endpoint                            | Traces endpoint                            |
| ------ | ---------------------------------------- | ------------------------------------------ |
| EU     | `https://ingestion.eu.bronto.io/v1/logs` | `https://ingestion.eu.bronto.io/v1/traces` |
| US     | `https://ingestion.us.bronto.io/v1/logs` | `https://ingestion.us.bronto.io/v1/traces` |

See [API Keys](/Account-Management/API-Keys) for how to create a key with ingestion permissions. No other changes to the rest of the setup are required.
