Instrument your Ruby application for Splunk Observability Cloud
Instrument your Ruby application using the OpenTelemetry instrumentation for Ruby and get your data into Splunk Observability Cloud.
You can use the OpenTelemetry Collector to send traces from Ruby applications to Splunk APM.
Prerequisites
Before starting, make sure you’ve installed the following components:
-
Bundler version 2.4 or higher
-
Ruby version 3.0 or higher
Check that you’re using supported libraries and frameworks. For a list of supported libraries, see https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation.
Additionally, you need to install the Splunk Distribution of OpenTelemetry Collector. The following distributions are available:
After installing the Collector, make sure that you have an instance of the Collector running in your environment.
Instrument your application
To instrument your Ruby application, follow these steps:
-
Install the
opentelemetry-sdk
andopentelemetry-instrumentation-all
packages:bundle add opentelemetry-sdk opentelemetry-instrumentation-all
-
In your project directory, create a file called opentelemetry.rb in config/initializers/ with the following code:
require 'opentelemetry/sdk' require 'opentelemetry/instrumentation/all' OpenTelemetry::SDK.configure do |c| c.use_all() # activates all instrumentation end
-
Run the instrumented application.
Send data directly to Splunk Observability Cloud
By default, all data goes to the local instance of the Splunk Distribution of OpenTelemetry Collector.
If you need to send data directly to Splunk Observability Cloud, follow these steps:
-
Install the OpenTelemetry exporter package using the following command:
gem install opentelemetry-exporter-otlp
-
Edit the config/exporters/opentelemetry.rb file to include the OpenTelemetry exporter package.
require 'opentelemetry/sdk' require 'opentelemetry/instrumentation/all' require 'opentelemetry-exporter-otlp' OpenTelemetry::SDK.configure do |c| c.use_all() # activates all instrumentation end
-
Set the endpoint to Splunk Observability Cloud and send data using the grpc protocol. Use the following commands:
export OTEL_EXPORTER_OTLP_ENDPOINT="http://ingest.<realm>.signalfx.com" export OTEL_EXPORTER_OTLP_PROTOCOL="grpc" export OTEL_EXPORTER_OTLP_TRACES_HEADERS="x-sf-token=<access_token>"
Replace
<realm>
with your Splunk Observability Cloud realm and<access-token>
with your Splunk Observability Cloud access token with ingest permissions.To obtain an access token, see Retrieve and manage user API access tokens using Splunk Observability Cloud.
To find your Splunk realm, see the note about realms in Configure SSO integrations for Splunk Observability Cloud.
-
Restart your application.
Learn more
For example configurations, see https://github.com/open-telemetry/opentelemetry-ruby/tree/main/examples.