Community Blog
Get the latest updates on the Splunk Community, including member experiences, product education, events, and more!

Get Started With the Splunk Distribution of OpenTelemetry Ruby

tsloughter
Splunk Employee
Splunk Employee

This blog post is part of an ongoing series on OpenTelemetry.

The Splunk Distribution of OpenTelemetry Ruby has recently hit version 1.0. The distribution provides a Ruby gem for reporting distributed traces to Splunk APM using the Ruby OpenTelemetry SDK.

The distribution comes with the following defaults:

If you're currently using the SignalFx Tracing Library for Node and want to migrate to the Splunk Distribution of OpenTelemetry Node, see Migrate from the SignalFx Tracing Library for Ruby.

The instrumentation works with Ruby version 2.7 and higher. Supported libraries are listed here.

Install and Configure the Distribution

Install the gem by adding it to your project's Gemfile:

 

 

gem "splunk-otel", "~> 1.0"

 

 

You can also use bundle:

 

 

bundle add splunk-otel --version "~> 1.0"

 

 

Then, configure the OpenTelemetry SDK using the Splunk::Otel module from splunk/otel:

 

 

require "splunk/otel"

…

Splunk::Otel.configure

 

 

Send Data Directly to Splunk Observability Cloud

To send traces directly to Splunk Observability Cloud, you need to:

  1. Set SPLUNK_REALM to your Splunk APM realm (for example, us0).
  2. Set the SPLUNK_ACCESS_TOKEN to your Splunk Observability Cloud access token.

These environment variables configure the OpenTelemetry Ruby exporter to send traces to https://ingest<.<realm>.signalfx.com/v2/trace/otlp using the given access token for authorization.

Automatically Instrument an Application

You can instrument many Ruby libraries without code changes. 

Include the gem opentelemetry-instrumentation-all in your Gemfile:

 

 

gem "opentelemetry-instrumentation-all", "~> 0.28"

 

 

This instruments any supported library in your project. Check the dependencies of opentelemetry-instrumentation-all to see what libraries are supported.

To enable the autoinstrumentations, pass auto_instrument:true to the configure method of Splunk::Otel. For example:

 

 

require "splunk/otel"


Splunk::Otel.configure(auto_instrument: true)

 

 

Correlate Traces and Logs

The Splunk Distribution includes a function, format_correlation that injects the current trace context into your logs using the standard Ruby logging formatter.: For example:

 

 

require "splunk/otel"

logger.formatter = proc do |severity, datetime, progname, msg|  
  "#{Splunk::Otel::Logging.format_correlation} : #{msg}\n"
end

 

 

The trace context allows you to correlate traces with log events in Observability Cloud.

Where to go Next

More details on how to instrument your Ruby application can be found in the Splunk documentation and on the OpenTelemetry website in the Ruby documentation.

Troubleshooting

For troubleshooting issues with the Splunk Distribution of OpenTelemetry Ruby, see Troubleshooting.

What Does This Mean for Splunk Customers?

Splunk is a contributor to OpenTelemetry and is committed to accelerating the adoption of the project. For more information about Splunk and OpenTelemetry, you can check out our latest OpenTelemetry blog posts.

— Tristan Sloughter, Senior Software Engineer

Get Updates on the Splunk Community!

Investigate Security and Threat Detection with VirusTotal and Splunk Integration

As security threats and their complexities surge, security analysts deal with increased challenges and ...

Observability Highlights | January 2023 Newsletter

 January 2023New Product Releases Splunk Network Explorer for Infrastructure MonitoringSplunk unveils Network ...

Security Highlights | January 2023 Newsletter

January 2023 Splunk Security Essentials (SSE) 3.7.0 ReleaseThe free Splunk Security Essentials (SSE) 3.7.0 app ...