Ruby

Embed
Preview of the card
<a href="https://forumulate.com/p/watchtower/docs/instrumentation-ruby"><img src="https://forumulate.com/api/public/orgs/watchtower/spaces/docs/pages/45beaa76-e4fb-4c7c-a91e-b4cf7c8206f3/social-card.svg?v=3e7ae33eec8b" alt="Ruby" width="600" height="315"></a>

<!-- status: ga language: ruby -->

Ruby: near-zero-code instrumentation

Ruby has no agent that attaches without a code change; the standard route is the opentelemetry-instrumentation-all gem, enabled by one initializer line (Rails: config/initializers/opentelemetry.rb). Everything else, the endpoint, the key and the service name, comes from the standard OTEL_* variables.

  1. Create a project, then an ingestion key (wti_...) with the ingest:traces scope. The key is shown once.

  2. Point the SDK at the gateway and pass the key in the x-watchtower-key header:

export OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.example.com
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_HEADERS=x-watchtower-key=wti_YOUR_KEY
export OTEL_SERVICE_NAME=my-service
  1. Add the gems (opentelemetry-sdk, opentelemetry-exporter-otlp, opentelemetry-instrumentation-all) and the initializer:

require "opentelemetry/sdk"
require "opentelemetry/exporter/otlp"
require "opentelemetry/instrumentation/all"

OpenTelemetry::SDK.configure do |c|
  c.use_all # Rails, Rack, Sidekiq, Net::HTTP, PG, Redis, ...
end
  1. Send one request to the service, then open the project's onboarding screen: it turns green when the first span arrives.

Updated