Docs
DocumentationQuery ReferenceAPI Reference
Open Console→→
DocumentationQuery ReferenceAPI Reference

Platform overview

What is Axiom?QuickstartArchitectureFeatures
Fundamentals
Datasets
Edge deployments
Limits
Performance
Optimize usage
Requirements
Semantic conventions
Glossary
Tour
SecurityRoadmap

Send data

Reference architecturesMethods

Understand data

Console
Query
Builder
Editor
Query results
Visualize
Traces
Metrics
Correlations
Save queries
Stream
Dashboard
Create
Elements
Create
Configure
Element types
Gauge
Heatmap
Log stream
Monitor list
Note
Pie chart
Scatter plot
Statistic
Table
Time series
Sections
Configure
Filter
Annotate
Monitor
Overview
View status
Configure
Examples
Monitor types
Anomaly
Match
Threshold
Alerting
Overview
Configure
Notifier types
Custom Webhook
Discord
Email
Microsoft Teams
Opsgenie
PagerDuty
Slack
Manage
Datasets
Overview
Views
Virtual fields
Access
RBAC
Tokens
CLI
Organization
Audit log
Settings
Usage and billing
Profile
Extend
Overview
AWS Lambda
AWS PrivateLink
Cloudflare Workers
Cloudflare Logpush
Convex
Grafana
Hex
Netlify
Supabase
Tailscale
Terraform
Vercel
Intelligence
Overview
Spotlight
AI agents
Overview
MCP Server
Query cost limits
Agent-created orgs
Skills
Overview
Axiom alerting
Build dashboards
Control costs
Query metrics
SRE
Translate SPL to APL
Splunk
Overview
Splunk app
Install and configure
Commands
Examples
Splunk Portal
How it works
Set up standard mode
Set up transparent mode
Observability Cloud
SPL command support
Examples
Monitor and troubleshoot

Use cases

ObservabilityProduct analytics
LLM observability
Overview
Use Axiom AI SDK
Manual instrumentation
GenAI attributes
Redaction policies

Miscellaneous

LLMs
Overview
List of docs pages
Full docs
Query reference
FAQs
Legal
Acceptable use policy
Cookies
Data processing
HIPAA
Partner agreement
Partner program guide
Privacy policy
SLA
Terms of service
Terms of use

Send OpenTelemetry data from a Ruby on Rails app to Axiom

This guide explains how to send OpenTelemetry data from a Ruby on Rails App to Axiom using the Ruby OpenTelemetry SDK.

This guide provides detailed steps on how to configure OpenTelemetry in a Ruby app to send telemetry data to Axiom using the OpenTelemetry Ruby SDK.

Prerequisites

  • Create an Axiom account.
  • Create a dataset in Axiom where you send your data.
  • Create an API token in Axiom with permissions to ingest data to the dataset you have created.
  • Install a Ruby version manager like rbenv and use it to install the latest Ruby version.
  • Install Rails using the gem install rails command.

Set up the Ruby on Rails app

  1. Create a new Rails app using the rails new myapp command.
  2. Go to the app directory with the cd myapp command.
  3. Open the Gemfile and add the following OpenTelemetry packages:
ruby
gem 'opentelemetry-api'
gem 'opentelemetry-sdk'
gem 'opentelemetry-exporter-otlp'
gem 'opentelemetry-instrumentation-rails'
gem 'opentelemetry-instrumentation-http'
gem 'opentelemetry-instrumentation-active_record', require: false
gem 'opentelemetry-instrumentation-all'

Install the dependencies by running bundle install.

Configure the OpenTelemetry exporter

In the initializers folder of your Rails app, create a new file called opentelemetry.rb, and then add the following OpenTelemetry exporter configuration:

ruby
require 'opentelemetry/sdk'
require 'opentelemetry/exporter/otlp'
require 'opentelemetry/instrumentation/all'

OpenTelemetry::SDK.configure do |c|
  c.service_name = 'ruby-traces' # Set your service name

  c.use_all # Or specify individual instrumentation you need

  c.add_span_processor(
    OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
      OpenTelemetry::Exporter::OTLP::Exporter.new(
        endpoint: 'https://AXIOM_DOMAIN/v1/traces',
        headers: {
          'Authorization' => 'Bearer API_TOKEN',
          'X-AXIOM-DATASET' => 'DATASET_NAME'
        }
      )
    )
  )
end
Info

Replace 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 send your data.

Replace AXIOM_DOMAIN with the base domain of your edge deployment. For more information, see Edge deployments.

Run the instrumented app

Run your Ruby on Rails app with OpenTelemetry instrumentation.

In development mode

Start the Rails server using the rails server command. The server will start on the default port (usually 3000), and you can access your app by visiting http://localhost:3000 in your web browser.

As you interact with your app, OpenTelemetry automatically collects telemetry data and sends it to Axiom using the configured OTLP exporter.

In production mode

For production, ensure to precompile assets and run migrations if necessary. Start the server with RAILS_ENV=production bin/rails server. This setup ensures your Ruby app is instrumented to send traces to Axiom, using OpenTelemetry for observability.

Observe the telemetry data in Axiom

As you interact with your app, traces are collected and exported to Axiom, allowing you to monitor, analyze, and gain insights into your app’s performance and behavior.

  1. In your Axiom account and click the Datasets or Stream tab.

  2. Select your dataset from the list.

  3. From the list of fields, click the trace_id to view your spans.

Dynamic OpenTelemetry Traces dashboard

This data can then be further viewed and analyzed in Axiom’s dashboard, offering a deeper understanding of your app’s performance and behavior.

  1. In your Axiom account, select Dashboards, and click the traces dashboard named after your dataset.

  2. View the dashboard which displays your total traces, incoming spans, average span duration, errors, slowest operations, and top 10 span errors across services.

Send data from an existing Ruby app

Manual instrumentation

Manual instrumentation allows users to define and manage telemetry data collection points within their Ruby apps, providing granular control over what is traced.

  1. Initialize Tracer. Use the OpenTelemetry API to obtain a tracer from the global tracer provider. This tracer will be used to start and manage spans.
ruby
tracer = OpenTelemetry.tracer_provider.tracer('my-tracer')
  1. Manually start a span at the beginning of the block of code you want to trace and ensure to end it when your operations complete. This is useful for gathering detailed data about specific operations.
ruby
span = tracer.start_span('operation_name')
begin
  # Perform operation
rescue => e
  span.record_exception(e)
  span.status = OpenTelemetry::Trace::Status.error("Operation failed")
ensure
  span.finish
end
  1. Enhance spans with custom attributes to provide additional context about the traced operations, helping in debugging and monitoring performance.
ruby
span.set_attribute("user_id", user.id)
span.add_event("query_executed", attributes: { "query" => sql_query })

Automatic instrumentation

Automatic instrumentation in Ruby uses OpenTelemetry’s libraries to automatically generate telemetry data for common operations, such as HTTP requests and database queries.

  1. Set up the OpenTelemetry SDK with the necessary instrumentation libraries in your Ruby app. This typically involves modifying the Gemfile and an initializer to set up the SDK and auto-instrumentation.
ruby
# In config/initializers/opentelemetry.rb
OpenTelemetry::SDK.configure do |c|
  c.service_name = 'ruby-traces'
  c.use_all  # Automatically use all available instrumentation
end
  1. Ensure your Gemfile includes gems for the automatic instrumentation of the frameworks and libraries your app uses.
ruby
gem 'opentelemetry-instrumentation-rails'
gem 'opentelemetry-instrumentation-http'
gem 'opentelemetry-instrumentation-active_record'

After setting up, no additional manual changes are required for basic telemetry data collection. The instrumentation libraries handle the creation and management of telemetry data automatically.

Reference

List of OpenTelemetry trace fields

Field CategoryField NameDescription
General Trace Information
_rowIdUnique identifier for each row in the trace data.
_sysTimeSystem timestamp when the trace data was recorded.
_timeTimestamp when the actual event being traced occurred.
trace_idUnique identifier for the entire trace.
span_idUnique identifier for the span within the trace.
parent_span_idUnique identifier for the parent span within the trace.
HTTP Attributes
attributes.http.methodHTTP method used for the request.
attributes.http.status_codeHTTP status code returned in response.
attributes.http.targetSpecific target of the HTTP request.
attributes.http.schemeProtocol scheme (HTTP/HTTPS).
User Agent
attributes.http.user_agentUser agent string, providing client software and OS.
Custom Attributes
attributes.custom["http.host"]Host information where the HTTP request was sent.
attributes.custom.identifierPath to a file or identifier in the trace context.
attributes.custom.layoutLayout used in the rendering process of a view or template.
Resource Process Attributes
resource.process.commandCommand line string used to start the process.
resource.process.pidProcess ID.
resource.process.runtime.descriptionDescription of the runtime environment.
resource.process.runtime.nameName of the runtime environment.
resource.process.runtime.versionVersion of the runtime environment.
Operational Details
durationTime taken for the operation.
kindType of span (for example, server, client, internal).
nameName of the span, often a high-level title for the operation.
Code Attributes
attributes.code.functionFunction or method being executed.
attributes.code.namespaceNamespace or module that includes the function.
Scope Attributes
scope.nameName of the scope for the operation.
scope.versionVersion of the scope.
Service Attributes
service.nameName of the service generating the trace.
service.versionVersion of the service generating the trace.
service.instance.idUnique identifier for the instance of the service.
Telemetry SDK Attributes
telemetry.sdk.languageLanguage of the telemetry SDK, for example, ruby.
telemetry.sdk.nameName of the telemetry SDK, for example, opentelemetry.
telemetry.sdk.versionVersion of the telemetry SDK, for example, 1.4.1.

List of imported libraries

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 app 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 apps. It integrates with various aspects of a Rails app, 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 app.

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 app.

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 app, such as HTTP requests, database queries, and external libraries. This gem simplifies the setup process and ensures comprehensive tracing coverage for your Ruby app.

Was this page helpful?
Suggest edits on GitHub
On this page
Set up the Ruby on Rails appConfigure the OpenTelemetry exporterRun the instrumented appIn development modeIn production modeObserve the telemetry data in AxiomDynamic OpenTelemetry Traces dashboardSend data from an existing Ruby appManual instrumentationAutomatic instrumentationReferenceList of OpenTelemetry trace fieldsList of imported libraries