Ruby SDK observability reference

Overview

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.

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:

ResourceLocation
GitHub repository

@launchdarkly/observability-ruby

Sample applicationExample Rails app
Published gemRubyGems

Prerequisites and dependencies

This reference guide assumes that you are somewhat familiar with the LaunchDarkly Ruby SDK.

The observability plugin is compatible with the Ruby SDK, 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

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:

Gemfile
1gem 'launchdarkly-server-sdk', '>= 8.0'
2gem 'launchdarkly-observability'

Then, install the gems:

Shell
$bundle install

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

Ruby
1require 'launchdarkly-server-sdk'
2require 'launchdarkly_observability'

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 in the Ruby SDK reference guide.

Here’s how to initialize the SDK and plugin:

Initialize, Ruby SDK v8.0+
1plugin = LaunchDarklyObservability::Plugin.new
2
3config = LaunchDarkly::Config.new(plugins: [plugin])
4client = LaunchDarkly::LDClient.new('YOUR_SDK_KEY', config)

Initializing in a Rails application

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

Rails initializer
1require 'launchdarkly-server-sdk'
2require 'launchdarkly_observability'
3
4plugin = LaunchDarklyObservability::Plugin.new(
5 service_name: 'my-rails-app',
6 service_version: '1.0.0'
7)
8
9config = LaunchDarkly::Config.new(plugins: [plugin])
10Rails.configuration.ld_client = LaunchDarkly::LDClient.new(
11 ENV['YOUR_SDK_KEY'],
12 config
13)
14
15at_exit { Rails.configuration.ld_client.close }

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:

Plugin options, Ruby SDK v8.0+
1plugin = LaunchDarklyObservability::Plugin.new(
2 service_name: 'example-service',
3 # we recommend setting service_version to the latest deployed git SHA
4 service_version: 'example-sha'
5)

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.

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:

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.

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 Metrics autogenerated from OpenTelemetry data.