No release in over 3 years
Adds OpenTelemetry tracing to RubyLLM chat operations
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

OpenTelemetry RubyLLM Instrumentation

OpenTelemetry instrumentation for RubyLLM.

How do I get started?

Install the gem using:

gem opentelemetry-instrumentation-ruby_llm

Or, if you use bundler, include opentelemetry-instrumentation-ruby_llm in your Gemfile.

Usage

To use the instrumentation, call use with the name of the instrumentation:

OpenTelemetry::SDK.configure do |c|
  c.use 'OpenTelemetry::Instrumentation::RubyLLM'
end

Alternatively, you can also call use_all to install all the available instrumentation.

OpenTelemetry::SDK.configure do |c|
  c.use_all
end

Configuration

Content capture

By default, message content is not captured. To enable it:

OpenTelemetry::SDK.configure do |c|
  c.use 'OpenTelemetry::Instrumentation::RubyLLM', capture_content: true
end

Or set the environment variable:

export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true

When 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.

What's traced?

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.

License

Copyright (c) Clarissa Borges and thoughtbot, inc.

This gem is free software and may be redistributed under the terms specified in the LICENSE file.

About thoughtbot

thoughtbot

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.