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:
W3C tracecontext and baggage propagation.
OTLP exporter configured to send spans to a locally running OpenTelemetry Collector over HTTP (default endpoint: localhost:4318).
Unlimited default limits for configuration options to support full-fidelity traces.
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:
Set SPLUNK_REALM to your Splunk APM realm (for example, us0).
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
... View more