Manual Instrumentation
Warning: Use the manual instrumentation method only if there is no framework support.
- Add the following packages to the existing Gemfile.
CODE
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.PYTHON
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_ENDPOINTenvironment variable on which the OpenTelemetry Collector listens to:CODEexport OTEL_EXPORTER_OTLP_ENDPOINT=http://0.0.0.0:4318Note:0.0.0.0is the OpenTelemetry collector HOST and4318is the OpenTelemetry Collector PORT. For more information about available exporters, see Ruby Exporter. - Install the newly added Gems to Gemfile.
CODE
bundle install - Start the Ruby application.