Ruby
Aspecto's SDK for ruby.

Aspecto::OpenTelemetry

This gem is a distribution of OpenTelemetry pre-configured to use all available instrumentations and export trace data to Aspecto.

Installation

Install the gem using:
1
$ gem install aspecto-opentelemetry
Copied!
Or, if you use bundler, include aspecto-opentelemetry in your Gemfile.

Usage

Rails Applications

Configuration in Code
Add this code to a new file aspecto.rb under config/initializers/:
1
# config/initializers/aspecto.rb
2
require 'aspecto/opentelemetry'
3
​
4
Aspecto::OpenTelemetry::configure do |c|
5
c.service_name = '<YOUR_SERVICE_NAME>'
6
c.aspecto_auth = '<YOUR_ASPECTO_TOKEN>'
7
# c.sampling_ratio = 1.0 # [optional]: defaults to 1.0, use aspecto app to configure remotely
8
end
Copied!
Configuration via Environment Variables
In your Gemfile:
1
gem 'aspecto-opentelemetry', require: 'aspecto/auto_instrument'
Copied!
And set environment variables:
1
OTEL_SERVICE_NAME=<YOUR_SERVICE_NAME>
2
ASPECTO_AUTH=<YOUR_ASPECTO_TOKEN>
3
# ASPECTO_SAMPLING_RATIO=1.0 # [optional]: defaults to 1.0, use aspecto app to configure remotely
Copied!

Ruby Applications

Configuration in Code
Add this code after your require other gems:
1
require 'aspecto/opentelemetry'
2
​
3
Aspecto::OpenTelemetry::configure do |c|
4
c.service_name = '<YOUR_SERVICE_NAME>'
5
c.aspecto_auth = '<YOUR_ASPECTO_TOKEN>'
6
# c.env = '<CURRENT_ENVIRONMENT>' # [optional]: automatically detected for rails and sinatra
7
# c.sampling_ratio = 1.0 # [optional]: defaults to 1.0, use aspecto app to configure remotely
8
end
Copied!
Configuration via Environment Variables
Add this require statement after your require other gems:
1
require 'aspecto/auto_instrument'
Copied!
And set environment variables:
1
OTEL_SERVICE_NAME=<YOUR_SERVICE_NAME>
2
ASPECTO_AUTH=<YOUR_ASPECTO_TOKEN>
3
# ASPECTO_ENV=<CURRENT_ENVIRONMENT> # [optional]: automatically detected for rails and sinatra
4
# ASPECTO_SAMPLING_RATIO=1.0 # [optional]: defaults to 1.0, use aspecto app to configure remotely
Copied!

Shutdown

Call this function when your application shuts down
1
Aspecto::OpenTelemetry::shutdown
Copied!

Configuration

You can set configuration via environment variables or via code. Values set in code takes precedence. The only required config options are aspecto_auth and service_name.

Configuration Options

Option Name
Environment Variable
Type
Default
Description
aspecto_auth
ASPECTO_AUTH
UUID string
-
service_name
OTEL_SERVICE_NAME
string
-
name of the service which is sending telemetry
env
ASPECTO_ENV
string
extracted from rails or sinatra if used
deployment environment: production / staging / development, etc.
log_level
OTEL_LOG_LEVEL
string
ERROR
ERROR / WARN / INFO, etc.
sampling_ratio
ASPECTO_SAMPLING_RATIO
float
1.0
How many of the traces starting in this service should be sampled. set to number in range [0.0, 1.0] where 0.0 is no sampling, and 1.0 is sample all
otel_exporter_otlp_traces_endpoint
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
URL
Url
​
Last modified 5d ago