ruby_llm
ruby_llm ships a first-party OpenTelemetry module that writes GenAI attributes on model, agent and tool spans, and cetra reads them. This page is setup only: it was not run, and every fact comes from the gem’s source and documentation.
Install
Section titled “Install”gem install ruby_llm opentelemetry-sdk opentelemetry-exporter-otlpSet up
Section titled “Set up”The application owns the OpenTelemetry SDK and the exporter; ruby_llm never configures them. The OTLP exporter sends protobuf over HTTP and appends v1/traces itself, so give it the base URL:
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:8080export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer sk-cetra-…"Then enable the module:
require "opentelemetry/sdk"require "opentelemetry/exporter/otlp"require "ruby_llm"
OpenTelemetry::SDK.configure { |c| c.service_name = "my-app" }RubyLLM::OpenTelemetry.enable # or enable(content: true)RubyLLM::OpenTelemetry.disable turns the module off again.
Content is off by default. enable(content: true) writes the system instructions, the input and output messages and the tool arguments and results; there is no environment variable for it. Attachments are described, not sent, and URIs lose their query string.
What you get
Section titled “What you get”- An
llmspan namedchat <model>for each model call, with the provider, the request and response models, the finish reason and the token counts; cetra computes the cost from the built-in prices. - An
agentspan namedinvoke_agent <Agent>for agent runs, with the agent name and the conversation id. - A
toolspan namedexecute_tool <tool>for tool calls, with the tool name and the call id, and with the arguments and the result when content is on. embeddings,generate_content,transcription,rerankand the other operations get their own spans.- Failed calls set
error.typeto the exception’s class and the span status to ERROR.
Limits
Section titled “Limits”- Not captured: written from the library’s source and documentation.
- Content is off by default and enabled in code only (
enable(content: true)); no environment variable switches it. - Do not also enable thoughtbot’s
opentelemetry-instrumentation-ruby_llmgem: it writes its ownchatspans, and both together record every model call twice. - The
ruby_llm-opentelemetrygem is a placeholder release; it is not usable. - This page was written against ruby_llm 2.2.2, opentelemetry-sdk 1.13.1 and opentelemetry-exporter-otlp 0.37.0.
- Send OpenTelemetry: the endpoint and the headers cetra expects.
- Traces: read the trace as a tree and a timeline.
- Cost and tokens: how cost is computed from the token counts.