Ruby
Instrument your Ruby app using openTelemetry and export traces to Aspecto's collector.

Install Opentelemetry SDK and instrumentations

1
gem install opentelemetry-sdk
2
gem install opentelemetry-exporter-otlp
3
gem install opentelemetry-instrumentation-all
Copied!

Initialize Opentelemetry

Add a rails initializer file opentelemetry.rb under config/initializers with the content:
1
require 'opentelemetry/sdk'
2
require 'opentelemetry/exporter/otlp'
3
require 'opentelemetry/instrumentation/all'
4
OpenTelemetry::SDK.configure do |c |
5
c.service_name = '#{YOUR_SERVICE_NAME}'
6
c.use_all() # enables all instrumentation!
7
c.add_span_processor(
8
OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
9
OpenTelemetry::Exporter::OTLP::Exporter.new(endpoint: 'https://otelcol.aspecto.io/v1/trace', headers: {
10
'Authorization' => '#{YOUR_ASPECTO_TOKEN}'
11
})
12
)
13
)
14
end
Copied!
You need to substitute the values #{YOUR_SERVICE_NAME} with the name of your service, and #{YOUR_ASPECTO_TOKEN} with a token you can find here​

Custom Attributes

Collect extra data in your app's code via custom key-value attributes. You can later view this data in Aspecto, and search on it.
1
require 'opentelemetry'
2
​
3
# anywhere in your code
4
OpenTelemetry::Trace.current_span.set_attribute('attribute.name', 'attribute value')
Copied!
Attribute name can be any static string, recommended to be namespaced with dot notation (<company>.<scope>.<name>), for example: "my_company.user.id", "my_company.tier", "my_company.features.promotion".
Attribute value can be any string, number, boolean or array of these
Last modified 4mo ago