Skip to main content
This guide will help you instrument your Ruby on Rails application(s) with OpenTelemetry and send traces to Checkly. Although this guide is for Ruby on Rails, the steps are largely the same as instrumenting any Ruby application with OpenTelemetry. This guide assumes you have a basic understanding of Ruby on Rails and already have a working Rails application.

Step 1: Install the OpenTelemetry packages

Go to the root of your Rails app and add the basic OpenTelemetry SDK, OTLP exporter and instrumentation gems to your Gemfile:
Terminal
This should add the following lines:
Gemfile

Step 2: Initialize the instrumentation

As per the Ruby on Rails convention, we add an instrumentation.rb file to the config/initializers directory.
config/initializers/instrumentation.rb
Notice the ChecklySampler configuration. This is a custom, head-based sampler that will only sample spans that are generated by Checkly by inspecting the trace state. This way you only pay for the egress traffic generated by Checkly and not for any other traffic. Also note that the use_all() method will automatically install all available instrumentation libraries.

Step 3: Start your app with the instrumentation

Toggle on Import Traces and grab your OTel API key in the OTel API keys section of the Traces page in the Checkly app and take a note of the endpoint for the region you want to use. Checkly OTEL API keys Now, export your API key in your shell by setting the OTEL_EXPORTER_OTLP_HEADERS environment variable.
Terminal
Next, export the endpoint for the region you want to use and give your service a name.
Terminal
Then, explicitly set the protocol to use for the OTLP exporter.
Terminal
We are using the standard OpenTelemetry environment variables here to configure the OTLP exporter. You can now restart your Rails app with the instrumentation enabled.
Terminal

Debugging and troubleshooting

If you run into any issues, you can also output any traces to the console as follows:
Terminal
Similarly, you can set the OTEL_LOG_LEVEL environment variable to DEBUG to get more detailed logs.
Terminal

Further reading