Skip to content

Ruby

Terminal window
bundle add opentelemetry-sdk opentelemetry-exporter-otlp opentelemetry-instrumentation-all
bundle add opentelemetry-logs-sdk opentelemetry-exporter-otlp-logs opentelemetry-instrumentation-logger
bundle add opentelemetry-metrics-sdk opentelemetry-exporter-otlp-metrics

Set these where your app runs. Replace YOUR_INGEST_KEY with your key and checkout with your service name.

Terminal window
export OTEL_SERVICE_NAME=checkout
export OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=production
export OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.siteqwality.com
export OTEL_EXPORTER_OTLP_HEADERS=Authorization=YOUR_INGEST_KEY
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf

Then start the SDK once, after your gems load. In Rails, put this in config/initializers/opentelemetry.rb:

OpenTelemetry::SDK.configure(&:use_all)

Start it as usual. Rails, Sinatra, Rack, HTTP clients, ActiveRecord, Redis and Sidekiq are now traced automatically.

Keep using Ruby’s Logger or Rails.logger. Records arrive as logs, linked to the trace of the request that wrote them:

logger = Logger.new($stdout)
logger.info('order placed')
orders = OpenTelemetry.meter_provider.meter('checkout').create_counter('orders.placed')
orders.add(1)

Open Logs, Traces or Metrics. New data usually shows up within a minute, and a page that says it is waiting for data switches to your data on its own.

The code on this page comes from a runnable example that is checked against our ingest rules every month.

Nothing arriving? Check that the key is an ingest key for this account, that your account has early access, and the status codes in Ingest routes and limits.