The project is in a healthy, maintained state
Adds OpenTelemetry tracing to ask-rb LLM operations. Subscribes to ask-instrumentation events and creates spans for chat completions, embeddings, tool calls, and more.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 5.25
~> 13.0

Runtime

 Project Readme

ask-opentelemetry

Gem Version CI

OpenTelemetry tracing for the ask-rb ecosystem. Subscribes to ask-instrumentation events and creates OpenTelemetry spans for chat completions, tool calls, embeddings, and image generation. Backend-agnostic: the exporter is configured with the standard OpenTelemetry SDK, so spans go to any OpenTelemetry-compatible backend (Langfuse, Datadog, Honeycomb, Jaeger, Arize Phoenix, and more).

Installation

gem "ask-opentelemetry"
gem "ask-instrumentation"

Quick Start

require "ask/open_telemetry"

Ask::OpenTelemetry.install

That's it. Every Ask::Instrumentation event is now wrapped in a span. The call is idempotent; subsequent calls are no-ops.

In a Rails app, the Railtie calls Ask::OpenTelemetry.install automatically: no manual setup required.

Spans Created

Event Span
chat.ask, chat.stream.ask llm.chat
tool.ask llm.tool
embedding.ask llm.embedding
image.ask llm.image

Span attributes use the llm.* namespace: llm.provider, llm.model, llm.input_tokens, llm.output_tokens, llm.duration_ms, llm.tool, llm.tool_args, and llm.image.size when present. Any context set via Ask::Instrumentation.with_metadata is forwarded as llm.metadata.* attributes.

Configuration

Ask::OpenTelemetry.install is the entire public API; there is no exporter configuration on the gem itself. Configure the exporter once with the standard OpenTelemetry SDK before calling install:

require "opentelemetry-sdk"
require "opentelemetry-exporter-otlp"

OpenTelemetry::SDK.configure do |c|
  c.service_name = "my-app"
  c.add_span_processor(
    OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
      OpenTelemetry::Exporter::OTLP::Exporter.new(endpoint: "https://otlp.example.com")
    )
  )
end

Ask::OpenTelemetry.install

Full documentation

The full ask-rb documentation lives at https://ask-rb.github.io/ask-docs. https://ask-rb.github.io/ask-docs/production/opentelemetry covers ask-opentelemetry in depth, including per-backend setup examples. API reference: https://ask-rb.github.io/ask-docs/reference/api.

Development

bundle install bundle exec rake test

License

MIT