This guide explains how to send OpenTelemetry data from a Ruby on Rails App to Axiom using the Ruby OpenTelemetry SDK.
rbenv
and use it to install the latest Ruby version.gem install rails
command.rails new myapp
command.cd myapp
command.Gemfile
and add the following OpenTelemetry packages:bundle install
.
initializers
folder of your Rails app, create a new file called opentelemetry.rb
, and then add the following OpenTelemetry exporter configuration:
API_TOKEN
with the Axiom API token you have generated. For added security, store the API token in an environment variable.Replace DATASET_NAME
with the name of the Axiom dataset where you want to send data.Replace AXIOM_DOMAIN
with api.axiom.co
if your organization uses the US region, and with api.eu.axiom.co
if your organization uses the EU region. For more information, see Regions.rails server
command. The server will start on the default port (usually 3000), and you can access your application by visiting http://localhost:3000
in your web browser.
As you interact with your application, OpenTelemetry automatically collects telemetry data and sends it to Axiom using the configured OTLP exporter.
RAILS_ENV=production bin/rails server
. This setup ensures your Ruby application is instrumented to send traces to Axiom, using OpenTelemetry for observability.
Field Category | Field Name | Description |
---|---|---|
General Trace Information | ||
_rowId | Unique identifier for each row in the trace data. | |
_sysTime | System timestamp when the trace data was recorded. | |
_time | Timestamp when the actual event being traced occurred. | |
trace_id | Unique identifier for the entire trace. | |
span_id | Unique identifier for the span within the trace. | |
parent_span_id | Unique identifier for the parent span within the trace. | |
HTTP Attributes | ||
attributes.http.method | HTTP method used for the request. | |
attributes.http.status_code | HTTP status code returned in response. | |
attributes.http.target | Specific target of the HTTP request. | |
attributes.http.scheme | Protocol scheme (HTTP/HTTPS). | |
User Agent | ||
attributes.http.user_agent | User agent string, providing client software and OS. | |
Custom Attributes | ||
attributes.custom[“http.host”] | Host information where the HTTP request was sent. | |
attributes.custom.identifier | Path to a file or identifier in the trace context. | |
attributes.custom.layout | Layout used in the rendering process of a view or template. | |
Resource Process Attributes | ||
resource.process.command | Command line string used to start the process. | |
resource.process.pid | Process ID. | |
resource.process.runtime.description | Description of the runtime environment. | |
resource.process.runtime.name | Name of the runtime environment. | |
resource.process.runtime.version | Version of the runtime environment. | |
Operational Details | ||
duration | Time taken for the operation. | |
kind | Type of span (e.g., server, client, internal). | |
name | Name of the span, often a high-level title for the operation. | |
Code Attributes | ||
attributes.code.function | Function or method being executed. | |
attributes.code.namespace | Namespace or module that includes the function. | |
Scope Attributes | ||
scope.name | Name of the scope for the operation. | |
scope.version | Version of the scope. | |
Service Attributes | ||
service.name | Name of the service generating the trace. | |
service.version | Version of the service generating the trace. | |
service.instance.id | Unique identifier for the instance of the service. | |
Telemetry SDK Attributes | ||
telemetry.sdk.language | Language of the telemetry SDK, e.g., ruby. | |
telemetry.sdk.name | Name of the telemetry SDK, e.g., opentelemetry. | |
telemetry.sdk.version | Version of the telemetry SDK, e.g., 1.4.1. |
gem 'opentelemetry-api'
The opentelemetry-api
gem provides the core OpenTelemetry API for Ruby. It defines the basic concepts and interfaces for distributed tracing, such as spans, tracers, and context propagation. This gem is essential for instrumenting your Ruby application with OpenTelemetry.
gem 'opentelemetry-sdk'
The opentelemetry-sdk
gem is the OpenTelemetry SDK for Ruby. It provides the implementation of the OpenTelemetry API, including the tracer provider, span processors, and exporters. This gem is responsible for managing the lifecycle of spans and sending them to the specified backend.
gem 'opentelemetry-exporter-otlp'
The opentelemetry-exporter-otlp
gem is an exporter that sends trace data to a backend that supports the OpenTelemetry Protocol (OTLP), such as Axiom. It formats the trace data according to the OTLP standards and transmits it over HTTP or gRPC, ensuring compatibility and standardization in how telemetry data is sent across different systems and services.
gem 'opentelemetry-instrumentation-rails'
The opentelemetry-instrumentation-rails
gem provides automatic instrumentation for Ruby on Rails applications. It integrates with various aspects of a Rails application, such as controllers, views, and database queries, to capture relevant trace data without requiring manual instrumentation. This gem simplifies the process of adding tracing to your Rails application.
gem 'opentelemetry-instrumentation-http'
The opentelemetry-instrumentation-http
gem provides automatic instrumentation for HTTP requests made using the Net::HTTP
library. It captures trace data for outgoing HTTP requests, including request headers, response status, and timing information. This gem helps in tracing the external dependencies of your application.
gem 'opentelemetry-instrumentation-active_record', require: false
The opentelemetry-instrumentation-active_record
gem provides automatic instrumentation for ActiveRecord, the Object-Relational Mapping (ORM) library used in Ruby on Rails. It captures trace data for database queries, including the SQL statements executed and their duration. This gem helps in identifying performance bottlenecks related to database interactions.
gem 'opentelemetry-instrumentation-all'
The opentelemetry-instrumentation-all
gem is a meta-gem that includes all the available instrumentation libraries for OpenTelemetry in Ruby. It provides a convenient way to install and configure multiple instrumentation libraries at once, covering various aspects of your application, such as HTTP requests, database queries, and external libraries. This gem simplifies the setup process and ensures comprehensive tracing coverage for your Ruby application.