verica-observability 0.1.1 → 0.1.2

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: 849499723f11e316ccfd5f3a8f6028c7ad5f05a7ce0f3836e5548754058dc3aa
4
- data.tar.gz: 1212149d9f415487b332076c49a5a57b21819a3985798bba9d796f85e5d5c566
3
+ metadata.gz: 2a4717918614705eb9e9cd8af630733bc40c6e3ba73ae69823acf02b7bb4343b
4
+ data.tar.gz: d026c3e15ca4e5c22e709032118672cd7815945643a16caee3d079679a61fbdd
5
5
  SHA512:
6
- metadata.gz: 0ec6c31c9cb14ccb7ba29bac576d90417db64d99b2f19da786a2405b65a604a34369b165b46082264fd8b9b4b264a468f75bf2ee8988f918759b8b56b09d7dfb
7
- data.tar.gz: ec4e4f40b3967327e8f9c126fa2061aeb126367f77cf8ab955a492118ef7a491979103c41bdbc3d87d979f4d7926a145320bf130094f9fd1740b53148720f57c
6
+ metadata.gz: 9f9e443254d7a5e73bbd4cc63b8824c4ffcf620fc60245df34807994bba1f27a9688c0262b0848783f49553d395822474770b2a7f2d3f6ad96eef70ca498fb14
7
+ data.tar.gz: 8df0d98d2b44d2ed10a7b626b7946dd05254c49e69b5459e4c6dcc83da4bd8896ae3c92b28be46dcee128dd6b6593d556b1509646d5944e3060bb8dcd01a643b
data/README.md CHANGED
@@ -45,6 +45,26 @@ Use `wrap_openai` for the official `openai` gem and `wrap_ruby_openai` for
45
45
  `ruby-openai`. The two gems' APIs are not interchangeable, so neither are the
46
46
  wrappers.
47
47
 
48
+ ## Use Gemini or Anthropic (OpenAI-compatible endpoints)
49
+
50
+ Both providers expose OpenAI-compatible endpoints, so the same wrapper traces
51
+ them too. Use `wrap_openai_compatible` (the `ruby-openai` shape) and point the
52
+ client at the provider's endpoint; the provider label is inferred from the model
53
+ name (`gemini-*` → google, `claude-*` → anthropic).
54
+
55
+ ```ruby
56
+ # Gemini
57
+ gemini = OpenAI::Client.new(
58
+ access_token: ENV['GEMINI_API_KEY'],
59
+ uri_base: 'https://generativelanguage.googleapis.com/v1beta/openai/'
60
+ )
61
+ client = Verica.wrap_openai_compatible(gemini)
62
+ client.chat(parameters: { model: 'gemini-2.5-flash', messages: [...] })
63
+ ```
64
+
65
+ `wrap_ruby_openai` is a back-compat alias of `wrap_openai_compatible`; both
66
+ behave identically.
67
+
48
68
  ## Use (RubyLLM)
49
69
 
50
70
  With RubyLLM plus its thoughtbot OpenTelemetry instrumentation, `Verica.init`
@@ -74,7 +74,7 @@ module Verica
74
74
  def annotate(span, params, response)
75
75
  cfg = Verica.config
76
76
  span.set_attribute('gen_ai.operation.name', 'chat')
77
- span.set_attribute('gen_ai.provider.name', 'openai')
77
+ span.set_attribute('gen_ai.provider.name', Verica::Providers.for_model(params[:model]))
78
78
  span.set_attribute('gen_ai.request.model', params[:model].to_s) if params[:model]
79
79
  span.set_attribute('gen_ai.conversation.id', cfg.conversation_id) if cfg&.conversation_id
80
80
 
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Verica
4
+ # Infers Verica's canonical provider from an OpenAI-shaped model name, so a
5
+ # single OpenAI-compatible client (ruby-openai) traces Gemini and Anthropic
6
+ # calls with the right provider label. Default openai (these are OpenAI-shaped
7
+ # clients).
8
+ module Providers
9
+ def self.for_model(model)
10
+ m = model.to_s.downcase
11
+ return 'google' if m.start_with?('gemini')
12
+ return 'anthropic' if m.start_with?('claude')
13
+
14
+ 'openai'
15
+ end
16
+ end
17
+ end
@@ -51,7 +51,7 @@ module Verica
51
51
  streaming = parameters[:stream] || parameters['stream']
52
52
 
53
53
  span.set_attribute('gen_ai.operation.name', 'chat')
54
- span.set_attribute('gen_ai.provider.name', 'openai')
54
+ span.set_attribute('gen_ai.provider.name', Verica::Providers.for_model(model))
55
55
  span.set_attribute('gen_ai.request.model', model.to_s) if model
56
56
  span.set_attribute('gen_ai.conversation.id', cfg.conversation_id) if cfg&.conversation_id
57
57
  span.set_attribute('gen_ai.input.messages', JSON.generate(messages)) if cfg&.capture_content && messages
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Verica
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
data/lib/verica.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'verica/version'
4
4
  require 'verica/config'
5
+ require 'verica/providers'
5
6
  require 'verica/openai_wrapper'
6
7
  require 'verica/ruby_openai_wrapper'
7
8
 
@@ -56,12 +57,15 @@ module Verica
56
57
  OpenAIWrapper.new(client)
57
58
  end
58
59
 
59
- # Wraps the community `ruby-openai` gem (alexrudall) client so its
60
- # `chat(parameters:)` calls emit traces. Its API and Hash responses differ
61
- # from the official gem, so it needs its own wrapper (not interchangeable).
62
- def wrap_ruby_openai(client)
60
+ # Wraps a client that speaks the community `ruby-openai` gem's
61
+ # `chat(parameters:)` API, so its calls emit traces. This is the path for
62
+ # any OpenAI-compatible endpoint: OpenAI itself, plus Gemini and Anthropic
63
+ # via their OpenAI-compatible endpoints (the provider is inferred from the
64
+ # model). Preferred name; `wrap_ruby_openai` is a back-compat alias.
65
+ def wrap_openai_compatible(client)
63
66
  RubyOpenAIWrapper.new(client)
64
67
  end
68
+ alias_method :wrap_ruby_openai, :wrap_openai_compatible
65
69
 
66
70
  def flush
67
71
  OpenTelemetry.tracer_provider.force_flush if @initialized
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verica-observability
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Verica
@@ -48,6 +48,7 @@ files:
48
48
  - lib/verica.rb
49
49
  - lib/verica/config.rb
50
50
  - lib/verica/openai_wrapper.rb
51
+ - lib/verica/providers.rb
51
52
  - lib/verica/ruby_openai_wrapper.rb
52
53
  - lib/verica/version.rb
53
54
  homepage: https://verica.app