opentelemetry-instrumentation-ruby_llm 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e43dc7d2e1f91e06c28aa8237a6393d565605f92635edf69e2948015e5d5c4b
4
- data.tar.gz: b7eb8e02952582e6d8af04f8ee04407ac5e880b9f992ccdd4e6e353e3c060af0
3
+ metadata.gz: dfb17d4d74d31d2a53792683e0d5d070cd25e9160ee3c5018c0a1dbfb5bbeb4b
4
+ data.tar.gz: 91c3b7ac277d43ddf80a6fc49e2228d8005bf40f9321cd10cd5ac2539c96dfc7
5
5
  SHA512:
6
- metadata.gz: b600d97f321e3626ffa9de8785e67762d3f391b60e5d11a5d3f97657cbd4801e8cb7d1dd86e632bc260873732772176371b75a1fe17f6325fc2815fb23dc4b9b
7
- data.tar.gz: 76384730ef9cfe8cfe7f1d5b68109c6cbd4bedb897f18393dc717e0e5089d3ec7cbd81f21f728db4e82bc73ff72f08765b75b97e980ef665d5662ad5321759c5
6
+ metadata.gz: df479838c253aa695c1b36b393b4f7eac31dd041a581df3d04d9f9e9ca1253d026b8582b32d2cdf398e812d53459ef0c012406654342d37a9ae45c45dc68c5e7
7
+ data.tar.gz: 9c18a05253193ce23af8bc0f342cd726778c6daccff7d1010602a63b36f20d07eb13852ea6f01d6e40bf2439236fbf4b495e32e144e701d521aaeec18972f6a4
@@ -5,7 +5,7 @@ module OpenTelemetry
5
5
  module RubyLLM
6
6
  module Patches
7
7
  module Chat
8
- def ask(message, &block)
8
+ def complete(&)
9
9
  provider = @model&.provider || "unknown"
10
10
  model_id = @model&.id || "unknown"
11
11
 
@@ -3,7 +3,7 @@
3
3
  module OpenTelemetry
4
4
  module Instrumentation
5
5
  module RubyLLM
6
- VERSION = "0.2.0"
6
+ VERSION = "0.3.0"
7
7
  end
8
8
  end
9
9
  end
@@ -67,7 +67,7 @@ class InstrumentationTest < Minitest::Test
67
67
  assert_equal OpenTelemetry::Trace::Status::ERROR, span.status.code
68
68
  end
69
69
 
70
- def test_ask_still_works_when_instrumentation_fails
70
+ def test_complete_still_works_when_instrumentation_fails
71
71
  stub_request(:post, "https://api.openai.com/v1/chat/completions")
72
72
  .to_return(
73
73
  status: 200,
@@ -92,6 +92,39 @@ class InstrumentationTest < Minitest::Test
92
92
  assert_equal "Hello!", response.content
93
93
  end
94
94
 
95
+ def test_instruments_complete_called_directly
96
+ stub_request(:post, "https://api.openai.com/v1/chat/completions")
97
+ .to_return(
98
+ status: 200,
99
+ headers: { "Content-Type" => "application/json" },
100
+ body: {
101
+ id: "chatcmpl-123",
102
+ object: "chat.completion",
103
+ model: "gpt-4o-mini",
104
+ choices: [{
105
+ index: 0,
106
+ message: { role: "assistant", content: "Hello, world!" },
107
+ finish_reason: "stop"
108
+ }],
109
+ usage: { prompt_tokens: 10, completion_tokens: 5, total_tokens: 15 }
110
+ }.to_json
111
+ )
112
+
113
+ chat = RubyLLM.chat(model: "gpt-4o-mini")
114
+ chat.add_message(role: :user, content: "Hi")
115
+ chat.complete
116
+
117
+ spans = EXPORTER.finished_spans
118
+ assert_equal 1, spans.length
119
+
120
+ span = spans.first
121
+ assert_equal "chat gpt-4o-mini", span.name
122
+ assert_equal "chat", span.attributes["gen_ai.operation.name"]
123
+ assert_equal "openai", span.attributes["gen_ai.provider.name"]
124
+ assert_equal 10, span.attributes["gen_ai.usage.input_tokens"]
125
+ assert_equal 5, span.attributes["gen_ai.usage.output_tokens"]
126
+ end
127
+
95
128
  def test_creates_span_for_tool_call
96
129
  calculator = Class.new(RubyLLM::Tool) do
97
130
  def self.name = "calculator"
@@ -155,7 +188,7 @@ class InstrumentationTest < Minitest::Test
155
188
  chat_spans = spans.select { |s| s.name.include?("chat ") }
156
189
 
157
190
  assert_equal 1, tool_spans.length
158
- assert_equal 1, chat_spans.length
191
+ assert_equal 2, chat_spans.length
159
192
 
160
193
  tool_span = tool_spans.first
161
194
  assert_equal OpenTelemetry::Trace::SpanKind::INTERNAL, tool_span.kind
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-instrumentation-ruby_llm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clarissa Borges