Skip to main content

Ruby Instrumentation

This guide explains how to instrument a Ruby application by selecting the appropriate deployment type in Motadata APM for trace ingestion.

Prerequisites

  • The Motadata Agent must be installed and running on the Linux server where the Ruby application is deployed. The otelcol must also be running as part of the Motadata Agent.
    To check the agent status, open a Linux terminal and run:
service motadata status
  • The Motadata Agent version must be 8.2.3 or higher for Host/ VM and 8.2.4 or higher for Docker.

  • The Docker Version must be 20.1 or higher.

  • The application must use CRuby (MRI) ≥ 3.2, JRuby ≥ 10.0.0.0 and TruffleRuby ≥ 23.1.0 are supported on a best-effort basis.

  • Bundler must be installed.

  • Internet connectivity is required when running bundle install to download gems from RubyGems.org.

  • The application must already be working and able to start without errors before instrumentation is added.

  • You may need root/sudo access if you encounter permission issues.

Configuration Steps

Step 1: Register the Application Service in Motadata APM

Go to Menu > Settings > APM > Application Registration. Clicking the Application Registration button, you can register a new application.

From the application registration screen, select the instrumentation type Host/VM or Docker.

Ruby Trace Configuration

FieldDescription
Select AgentSelect the Host/VM where this application is running. You can configure Ruby application service for Linux type agent.
LanguageSelect Ruby from the language icons.
Business ServiceThe Business Service represents a logical grouping of related microservices under a single business application (e.g., order-management).
Service NameProvide a unique and meaningful name (for example, order_service). Service names can contain letters, numbers, dots (.), and underscores (_). Do not use spaces or hyphens.
Service Attributes (Tags)Add key–value tags to your application for better filtering and organizing data in Explorer. Attribute key names must be lowercase.
Add Custom ParametersAllows you to define custom parameters for advanced use cases.

Clicking the Apply Configuration button, the ingestion gets started. Providing these details displays the Setup Command to instrument your Ruby application.

Setup Instructions

Step 2: Configure Ruby Instrumentation on Host/VM

Step 2a: Update Your Gemfile

Add the following line to your application's Gemfile:

gem 'motadata-apm', github: 'motadata2025/motadata-apm-ruby-instrumentation'
note

Ensure the Motadata Agent version 8.2.3 is installed so the gem path above is available on the host.

Then install the gem:

bundle install

Step 2b: Initialize the Agent in Your Application

note

You must require motadata-apm after your frameworks are loaded but before your application logic starts. The placement order matters, if loaded too early, some libraries may not be detected, resulting in incomplete instrumentation.

For Example, if Sinatra or Plain Ruby Applications

Add this to your main app.rb file, after all other require statements:

require 'sinatra'
require 'pg'
require 'motadata-apm'

Step 2c: Start the Application

Use the Startup Command displayed in the APM registration screen to run the setup script for your Ruby application with Motadata APM instrumentation enabled:

/motadata/motadata/instrumentation/agents/ruby/ruby-instrumentation.sh --service <service_name> <ruby_app_startup_command>
note

Replace <service-name> with the service name you have provided and <ruby_app_startup_command> with the command you normally use to start your Ruby application.

Step 3: Verify Trace Collection

Once the application is running, verify the following:

  • Confirm that the service has been registered successfully.
  • On the service registration screen, the Service Trace Collection Status should display "Running."
  • The traces will start appearing in the APM Explorer screen.

Troubleshooting

Problem 1: bundle install fails with a native extension compilation error

Cause The opentelemetry-exporter-otlp gem depends on google-protobuf, which requires native C extensions. If the required OS-level build tools are missing, gem installation fails with an error like:

ERROR: Failed to build gem native extension.

Remedy Install the required system build packages before running bundle install.

Ubuntu / Debian:

sudo apt-get update && sudo apt-get install -y \
build-essential gcc g++ make \
libssl-dev zlib1g-dev libffi-dev

RHEL / CentOS / Amazon Linux:

sudo yum groupinstall -y "Development Tools"
sudo yum install -y openssl-devel zlib-devel libffi-devel

After installing, rerun:

bundle install

Problem 2: bundle install fails or times out behind an HTTP proxy

Cause The server cannot reach RubyGems.org because outbound HTTPS traffic is routed through a proxy. The following hosts on port 443 must be reachable for gem installation to succeed:

HostPortPurpose
rubygems.org443 (HTTPS)Download OpenTelemetry gem packages
index.rubygems.org443 (HTTPS)Gem index lookups

Remedy Set the proxy environment variable and rerun bundle install in the same terminal session:

export https_proxy=http://your-proxy-host:port
bundle install
note

Internet access is only required at install time. Once the gems are installed, the application does not need network access to RubyGems.org at runtime.