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

# Ruby SDK observability reference

<View title="Developer" />

<View title="Federal docs" />

<View title="EU docs" />

This topic documents how to get started with the LaunchDarkly observability plugin for the Ruby SDK.

The Ruby SDK supports the **observability plugin** for error monitoring, logging, and tracing.

<Note>
  **SDK quick links**

  LaunchDarkly's SDKs are open source. In addition to this reference guide, we provide source, a sample application, and a published gem:

  <table>
    <thead>
      <tr>
        <th>Resource</th>
        <th>Location</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td>GitHub repository</td>

        <td>
          [@launchdarkly/observability-ruby](https://github.com/launchdarkly/observability-sdk/tree/main/sdk/%40launchdarkly/observability-ruby)
        </td>
      </tr>

      <tr>
        <td>Sample application</td>
        <td>[Example Rails app](https://github.com/launchdarkly/observability-sdk/tree/main/e2e/ruby/rails/demo)</td>
      </tr>

      <tr>
        <td>Published gem</td>
        <td>[RubyGems](https://rubygems.org/gems/launchdarkly-observability)</td>
      </tr>
    </tbody>
  </table>
</Note>

## Prerequisites and dependencies

This reference guide assumes that you are somewhat familiar with the LaunchDarkly [Ruby SDK](/docs/sdk/server-side/ruby).

The observability plugin is compatible with the [Ruby SDK](/docs/sdk/server-side/ruby), version 8.0 and later. Using the observability plugin requires Ruby 3.0.0 or higher.

## Getting started

Follow these steps to get started:

* [Install the plugin](#install-the-plugin)
* [Initialize the Ruby SDK client](#initialize-the-client)
* [Configure the plugin options](#configure-the-plugin-options)
* [Explore supported features](#explore-supported-features)
* [Review observability data in LaunchDarkly](#review-observability-data-in-launchdarkly)

## Install the plugin

LaunchDarkly uses a plugin to the Ruby SDK to provide observability.

The first step is to make both the SDK and the observability plugin available as dependencies.

Add these gems to your `Gemfile`:

<CodeGroup>
  ```ruby title="Gemfile" lines wrap theme={null}
    gem 'launchdarkly-server-sdk', '>= 8.0'
    gem 'launchdarkly-observability'
  ```
</CodeGroup>

Then, install the gems:

<CodeGroup>
  ```bash title="Shell" lines wrap theme={null}
    bundle install
  ```
</CodeGroup>

Finally, require the SDK and the plugin in your code:

<CodeGroup>
  ```ruby title="Ruby" lines wrap theme={null}
  require 'launchdarkly-server-sdk'
  require 'launchdarkly_observability'
  ```
</CodeGroup>

## Initialize the client

To initialize the SDK and plugin, you need your LaunchDarkly environment's SDK key. This authorizes your application to connect to a particular environment within LaunchDarkly. To learn more, read [Initialize the client](/docs/sdk/server-side/ruby#initialize-the-client) in the Ruby SDK reference guide.

Here's how to initialize the SDK and plugin:

<CodeGroup>
  ```ruby title="Initialize, Ruby SDK v8.0+" lines wrap theme={null}
  plugin = LaunchDarklyObservability::Plugin.new

  config = LaunchDarkly::Config.new(plugins: [plugin])
  client = LaunchDarkly::LDClient.new('YOUR_SDK_KEY', config)
  ```
</CodeGroup>

### Initializing in a Rails application

For Rails applications, create an initializer at `config/initializers/launchdarkly.rb`:

<CodeGroup>
  ```ruby title="Rails initializer" lines wrap theme={null}
  require 'launchdarkly-server-sdk'
  require 'launchdarkly_observability'

  plugin = LaunchDarklyObservability::Plugin.new(
  service_name: 'my-rails-app',
  service_version: '1.0.0'
  )

  config = LaunchDarkly::Config.new(plugins: [plugin])
  Rails.configuration.ld_client = LaunchDarkly::LDClient.new(
  ENV['YOUR_SDK_KEY'],
  config
  )

  at_exit { Rails.configuration.ld_client.close }
  ```
</CodeGroup>

When Rails is detected, the plugin automatically inserts Rack middleware for request tracing and makes controller helper methods available.

## Configure the plugin options

You can configure options for the observability plugin when you initialize the SDK. The plugin constructor accepts optional keyword arguments for configuration.

Here is an example:

<CodeGroup>
  ```ruby title="Plugin options, Ruby SDK v8.0+" lines wrap theme={null}
  plugin = LaunchDarklyObservability::Plugin.new(
  service_name: 'example-service',
  # we recommend setting service_version to the latest deployed git SHA
  service_version: 'example-sha'
  )
  ```
</CodeGroup>

For more information on plugin options, as well as how they interact with environment variables and existing OpenTelemetry configuration, read [Configuration for server-side observability](/docs/sdk/features/observability-config-server-side#ruby).

## Explore supported features

The observability plugin supports the following features. After the SDK and plugin are initialized, you can access these from within your application:

* [Configuration for server-side observability](/docs/sdk/features/observability-config-server-side#ruby)
* [Errors](/docs/sdk/features/observability-errors)
* [Logs](/docs/sdk/features/observability-logs)
* [Metrics](/docs/sdk/features/observability-metrics)
* [Tracing](/docs/sdk/features/observability-traces)

## Review observability data in LaunchDarkly

After you initialize the SDK and observability plugin, your application automatically starts sending observability data back to LaunchDarkly in the form of custom events. You can review this information in the LaunchDarkly user interface. To learn how, read [Observability](/docs/home/observability).

Specifically, the observability data includes events that LaunchDarkly uses to automatically create the following metrics:

* User HTTP error rate (OpenTelemetry)
* User HTTP 5XX response rate (OpenTelemetry)
* User non-HTTP exception rate (OpenTelemetry)
* Average, P95, and P99 request latency (OpenTelemetry)

To learn more, read [OpenTelemetry autogenerated metrics](/docs/home/metrics/autogen/opentelemetry).
