Ruby
1. Install
Section titled “1. Install”bundle add opentelemetry-sdk opentelemetry-exporter-otlp opentelemetry-instrumentation-allbundle add opentelemetry-logs-sdk opentelemetry-exporter-otlp-logs opentelemetry-instrumentation-loggerbundle add opentelemetry-metrics-sdk opentelemetry-exporter-otlp-metrics2. Configure
Section titled “2. Configure”Set these where your app runs. Replace YOUR_INGEST_KEY with your key and checkout with your service name.
export OTEL_SERVICE_NAME=checkoutexport OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=productionexport OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.siteqwality.comexport OTEL_EXPORTER_OTLP_HEADERS=Authorization=YOUR_INGEST_KEYexport OTEL_EXPORTER_OTLP_PROTOCOL=http/protobufThen start the SDK once, after your gems load. In Rails, put this in config/initializers/opentelemetry.rb:
OpenTelemetry::SDK.configure(&:use_all)3. Start your app
Section titled “3. Start your app”Start it as usual. Rails, Sinatra, Rack, HTTP clients, ActiveRecord, Redis and Sidekiq are now traced automatically.
4. Send a log
Section titled “4. Send a log”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')5. Record a metric (optional)
Section titled “5. Record a metric (optional)”orders = OpenTelemetry.meter_provider.meter('checkout').create_counter('orders.placed')
orders.add(1)See your data
Section titled “See your data”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.