Skip to content

Commit c9b9988

Browse files
fix: require ruby_llm >= 1.8.0 via OTel compatible block
Make the requirement explicit via the standard OTel instrumentation pattern: a `compatible` block that returns false when the loaded `ruby_llm` version is below the pin (mirrors what httpx, http, http_client do in opentelemetry-ruby-contrib). When the block returns false, OpenTelemetry::Instrumentation::Base silently skips installing the instrumentation — no raise, no patch application — so apps on older `ruby_llm` continue to function without the OTel traces (and without a hard crash). Note: `gem "rspec-mocks"` test dependency added to use `stub_const`. This is aligned with other instrumentation gems in opentelemetry-ruby-contrib.
1 parent 9a97ca4 commit c9b9988

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

lib/opentelemetry/instrumentation/ruby_llm/instrumentation.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ module OpenTelemetry
44
module Instrumentation
55
module RubyLLM
66
class Instrumentation < OpenTelemetry::Instrumentation::Base
7+
MINIMUM_RUBY_LLM_VERSION = "1.8.0"
8+
79
instrumentation_name "OpenTelemetry::Instrumentation::RubyLLM"
810
instrumentation_version VERSION
911

@@ -13,6 +15,22 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
1315
defined?(::RubyLLM)
1416
end
1517

18+
compatible do
19+
# The embedding patch calls `RubyLLM::Models.resolve` (class-method delegation added in 1.8.0);
20+
# Anything older than 1.8.0 would NoMethodError / NameError at install or first use.
21+
compatible = Gem::Version.new(::RubyLLM::VERSION) >= Gem::Version.new(MINIMUM_RUBY_LLM_VERSION)
22+
23+
unless compatible
24+
OpenTelemetry.logger.warn(
25+
"[OpenTelemetry::Instrumentation::RubyLLM] ruby_llm " \
26+
"#{::RubyLLM::VERSION} is below the required minimum " \
27+
"#{MINIMUM_RUBY_LLM_VERSION}; instrumentation will not be installed."
28+
)
29+
end
30+
31+
compatible
32+
end
33+
1634
install do |_config|
1735
require_relative "patches/chat"
1836
require_relative "patches/embedding"

test/instrumentation_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ def setup
99
end
1010
end
1111

12+
def test_compatible_is_true_for_current_ruby_llm_version
13+
instrumentation = OpenTelemetry::Instrumentation::RubyLLM::Instrumentation.instance
14+
assert_equal true, instrumentation.compatible?
15+
end
16+
17+
def test_minimum_ruby_llm_version_is_pinned_at_1_8_0
18+
assert_equal "1.8.0", OpenTelemetry::Instrumentation::RubyLLM::Instrumentation::MINIMUM_RUBY_LLM_VERSION
19+
end
20+
1221
def test_creates_span_with_attributes
1322
stub_request(:post, "https://api.openai.com/v1/chat/completions")
1423
.to_return(

0 commit comments

Comments
 (0)