OpenTelemetry instrumentation for RubyLLM.
Install the gem using:
gem opentelemetry-instrumentation-ruby_llmOr, if you use bundler, include opentelemetry-instrumentation-ruby_llm in your Gemfile.
To use the instrumentation, call use with the name of the instrumentation:
OpenTelemetry::SDK.configure do |c|
c.use 'OpenTelemetry::Instrumentation::RubyLLM'
endAlternatively, you can also call use_all to install all the available instrumentation.
OpenTelemetry::SDK.configure do |c|
c.use_all
endBy default, message content is not captured. To enable it:
OpenTelemetry::SDK.configure do |c|
c.use 'OpenTelemetry::Instrumentation::RubyLLM', capture_content: true
endOr set the environment variable:
export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=trueWhen enabled, the following attributes are added to chat spans:
| Attribute | Description |
|---|---|
gen_ai.system_instructions |
System instructions provided via with_instructions |
gen_ai.input.messages |
Input messages sent to the model |
gen_ai.output.messages |
Final output messages from the model |
Warning
Captured content may include sensitive or personally identifiable information (PII). Use with caution in production environments.
| Feature | Status |
|---|---|
| Chat completions | Supported |
| Tool calls | Supported |
| Error handling | Supported |
| Opt-in input/output content capture | Supported |
Conversation tracking (gen_ai.conversation.id) |
Planned |
| System instructions capture | Planned |
| Custom attributes on traces and spans | Planned |
| Embeddings | Planned |
| Streaming | Planned |
This gem follows the OpenTelemetry GenAI Semantic Conventions.
Copyright (c) Clarissa Borges and thoughtbot, inc.
This gem is free software and may be redistributed under the terms specified in the LICENSE file.
This repo is maintained and funded by thoughtbot, inc. The names and logos for thoughtbot are trademarks of thoughtbot, inc.
We love open source software! See our other projects. We are available for hire.