Manual Instrumentation
Warning: Use the manual instrumentation method only if there is no
framework support.
-
Add the following packages to the existing Gemfile.
gem 'opentelemetry-sdk' gem 'opentelemetry-exporter-otlp'
-
Add the following lines to create spans manually.For example, you can create spans to instrument a Ruby script or an unsupported framework.
require 'opentelemetry/sdk' require 'opentelemetry/exporter/otlp' OpenTelemetry::SDK.configure def hello_world tracer_provider = OpenTelemetry.tracer_provider tracer = tracer_provider.tracer('hello world') tracer.in_span("hello_world", kind: :server) do |span| puts "Hello all" # Do something... expensive/simple task that you want to instrument end tracer_provider.shutdown end hello_world
-
Set up the
OTEL_EXPORTER_OTLP_ENDPOINT
environment variable on which the OpenTelemetry Collector listens to:export OTEL_EXPORTER_OTLP_ENDPOINT=http://0.0.0.0:4318
Note:0.0.0.0
is the OpenTelemetry collector HOST and4318
is the OpenTelemetry Collector PORT. For more information about available exporters, see Ruby Exporter. -
Install the newly added Gems to Gemfile.
bundle install
- Start the Ruby application.