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?

OpenTelemetryopen in new window 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.

OpenTelemetry aims to standardize how you collect and send telemetry data to backend platforms: distributed tracingopen in new window, logsopen in new window, and OpenTelemetry metricsopen in new window.

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.

Sinatra instrumentation

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.

Getting started

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 APMopen in new window for OpenTelemetry that supports distributed tracing, metrics, and logs. You can use it to monitor applications and troubleshoot issues.

Uptrace Overview

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.

In just a few minutes, you can try Uptrace by visiting the cloud demoopen in new window (no login required) or running it locally with Dockeropen in new window. The source code is available on GitHubopen in new window.

What's next?

Next, you can instrument your Sinatra application code to create spans and record telemetry data. You can use the OpenTelemetry Ruby Tracing APIopen in new window 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.

Last Updated: 7/25/2024, 12:36:08 PM