gem install opentelemetry-sdk opentelemetry-exporter-otlp opentelemetry-instrumentation-all
export OTEL_EXPORTER_OTLP_ENDPOINT=https://logfire-us.pydantic.dev
export OTEL_EXPORTER_OTLP_HEADERS='Authorization=your-write-token'
require 'opentelemetry/sdk'
require 'opentelemetry/exporter/otlp'
require 'opentelemetry/instrumentation/all'
OpenTelemetry::SDK.configure do |c|
c.service_name = 'hello-ruby'
# Without use_all you get only the spans you write yourself.
c.use_all
end
tracer = OpenTelemetry.tracer_provider.tracer('hello-ruby')
tracer.in_span('Hello World') do |span|
# your work here
end
# No at_exit hook in the Ruby SDK: flush before the process exits.
OpenTelemetry.tracer_provider.shutdown
There is no Logfire Ruby SDK to adopt: these are the standard OpenTelemetry gems, and Logfire is the OTLP endpoint they export to.
Use the EU endpoint instead if your project is in the EU region. Full details are in the Ruby setup guide.