OpenTelemetry Instrumentation for Ruby

Install OpenTelemetry Ruby Automatic Instrumentation and instrument your Ruby application using the provided packages.

Add OpenTelemetry packages to your gem file:

gem 'opentelemetry-sdk'
gem 'opentelemetry-exporter-otlp'
gem 'opentelemetry-instrumentation-all'

Enable the instrumentation libraries that match up to libraries you’re using in your app:

# config/initializers/opentelemetry.rb
require 'opentelemetry/sdk'
require 'opentelemetry/exporter/otlp'
require 'opentelemetry/instrumentation/all'
OpenTelemetry::SDK.configure do |c|
  c.service_name = '<YOUR_SERVICE_NAME>'
  c.use_all() # enables all instrumentation!
end

Ensure that all spans are sent:

# Properly shut down the tracer
OpenTelemetry.tracer_provider.shutdown

Record code exception (optional):

require "opentelemetry/sdk"

current_span = OpenTelemetry::Trace.current_span

begin
  1/0 # something that obviously fails
rescue Exception => e
  current_span.status = OpenTelemetry::Trace::Status.error("error message here!")
  current_span.record_exception(e)
  raise e
ensure
  current_span.finish
  OpenTelemetry.tracer_provider.shutdown
end

Run your application with instrumentation:

export OTEL_EXPORTER_OTLP_ENDPOINT="https://ga-otlp.lumigo-tracer-edge.golumigo.com"
export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
export OTEL_EXPORTER_OTLP_HEADERS="authorization=LumigoToken <YOUR LUMIGO TOKEN>"
export OTEL_SERVICE_NAME=<YOUR_SERVICE_NAME> # OPTIONAL

Replace <token> with your Lumigo token, which is available in Settings -> Tracing -> Manual tracing, see the Lumigo Tokens documentation.