Docs » Supported integrations in Splunk Observability Cloud » Instrument back-end applications to send spans to Splunk APM » Instrument Ruby applications for Splunk Observability Cloud (OpenTelemetry) » Instrument your Ruby application for Splunk Observability Cloud

Instrument your Ruby application for Splunk Observability Cloud πŸ”—

You can use the OpenTelemetry Collector to send traces from Ruby applications to Splunk APM.

Prerequisities πŸ”—

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:

  1. Install the opentelemetry-sdk and opentelemetry-instrumentation-all packages:

    bundle add opentelemetry-sdk opentelemetry-instrumentation-all
    
  2. 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
    
  3. 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:

  1. Install the OpenTelemetry exporter package using the following command:

    gem install opentelemetry-exporter-otlp
    
  2. 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
    
  3. 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 Note about realms.

  4. Restart your application.

Learn more πŸ”—

For example configurations, see https://github.com/open-telemetry/opentelemetry-ruby/tree/main/examples.