Sinatra
Send traces to Last9 from a Sinatra app using OpenTelemetry
Sinatra is a lightweight web application framework written in Ruby. This comprehensive guide will help you instrument your Sinatra application with OpenTelemetry and smoothly send the traces to a Last9 cluster. You can also check out the example application on GitHub↗.
Pre-requisites
- You’ve a Sinatra application.
- You have signed up for Last9, created a cluster, and obtained the following OTLP credentials from the Integrations page:
endpoint
auth_header
Install OpenTelemetry packages
To install the required packages, add the following lines to your Gemfile:
Then, run the following command to install the packages:
Set the environment variables
Create a .env
file in the root directory of your application and add the following environment variables:
Note: Replace
<BASIC_AUTH_HEADER>
with the URL encoded value of the basic auth header obtained from the Integrations page.
In app.rb
, add the following code to load the environment variables:
Instrument your application
Create a new file instrumentation.rb
and add the following code:
This code snippet configures the OpenTelemetry SDK to use the OTLP exporter and enables all instrumentation.
We will require this file in app.rb
to instrument the application.
In app.rb
, require the instrumentation.rb
file:
Run the application
Run the Sinatra application using the following command:
Visualize the traces
After running the Sinatra app, you can visualize the traces in the Last9’s APM dashboard.
Troubleshooting
Please get in touch with us on Discord or Email if you have any questions.