Monitor Sinatra performance with OpenTelemetry
Sinatra is a lightweight web application framework for Ruby. It is designed to provide a simple and flexible way to build web applications. While Sinatra itself does not have built-in support for OpenTelemetry, you can integrate OpenTelemetry instrumentation into your Sinatra application to collect observability data.
What is OpenTelemetry?
OpenTelemetry is a vendor-neutral standard on how to collect telemetry data for applications and their supporting infrastructures. OpenTelemetry was created by merging OpenCensus and OpenTracing projects.
By using OpenTelemetry, developers gain valuable insight into the performance, behavior and dependencies of their applications, enabling them to optimize and troubleshoot their systems more effectively.
To instrument Sinatra app, you need a corresponding Sinatra OpenTelemetry instrumentation:
gem install opentelemetry-instrumentation-sinatra
If you use bundler, add
opentelemetry-instrumentation-sinatra to your Gemfile.
To get started, call
use with the name of the instrumentation:
require 'uptrace' require 'opentelemetry-instrumentation-sinatra' Uptrace.configure_opentelemetry(dsn: '') do |c| c.use 'OpenTelemetry::Instrumentation::Sinatra end
Alternatively, you can call
use_all to install all available instrumentations:
require 'uptrace' require 'opentelemetry-instrumentation-sinatra' Uptrace.configure_opentelemetry(dsn: '') do |c| c.use_all end
What is Uptrace?
Uptrace is an open source APM for OpenTelemetry that supports distributed tracing, metrics, and logs. You can use it to monitor applications and troubleshoot issues.
Uptrace comes with an intuitive query builder, rich dashboards, alerting rules, notifications, and integrations for most languages and frameworks.
Uptrace can process billions of spans and metrics on a single server and allows you to monitor your applications at 10x lower cost.
Next, you can instrument your Sinatra application code to create spans and record telemetry data. You can use the OpenTelemetry Ruby Tracing API to create spans around specific operations or code blocks you want to track. For example, you can create a span around a specific route or a database query.