Ruby

TracesMetricsApp LogsCustom LogsProfiling

This guide walks you through setting up Application Performance Monitoring (APM) on a Ruby application. These instructions can also be found on the Installation page in your Middleware Account. View example code here.

Prerequisites

  1. Middleware Agent (MW Agent): To install the MW Agent, see our Installation Guide.
  2. Ruby Version 3.0.0+: Check your Ruby version with ruby --version

Install

Step 1: Add Gems to Your Gemfile

Linux
Windows
Heroku

Install the gems with bundle install

Step 2: Import Tracker

Linux
Windows
Heroku

Add the following initialization code at the beginning of your Ruby application:

Add the following initialization code at the beginning of your Ruby application:

Add the following initialization code at the beginning of your Ruby application:

For example, if you are using Ruby on Rails, you can add the initialization code in config/environment.rb. Your config/environment.rb should look like below:

Step 3: Capture Application Data

Traces

Linux
Windows
Heroku

Heroku buildpack for Middleware auto-configures required environment variables and there is no additional configuration required.

However, if you wish to override default values for the auto-configured environment variables in Ruby execution environment.

For Ruby on Rails, you can override the default values by setting environment variables in config/environment.rb file. This configuration should be before Middleware gem is initialized.

Profiling

Application Profiling is auto-configured upon completion of Step 2.

Continuous Profiling

Continuous profiling captures real-time performance insights from your application to enable rapid identification of resource allocation, bottlenecks, and more. Navigate to the Continuous Profiling section to learn more about using Continuous Profiling with the Ruby APM.

Need assistance or want to learn more about Middleware? Contact our support team in Slack.