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 +4 -4
- data/README.md +20 -0
- data/lib/verica/openai_wrapper.rb +1 -1
- data/lib/verica/providers.rb +17 -0
- data/lib/verica/ruby_openai_wrapper.rb +1 -1
- data/lib/verica/version.rb +1 -1
- data/lib/verica.rb +8 -4
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2a4717918614705eb9e9cd8af630733bc40c6e3ba73ae69823acf02b7bb4343b
|
|
4
|
+
data.tar.gz: d026c3e15ca4e5c22e709032118672cd7815945643a16caee3d079679a61fbdd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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',
|
|
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',
|
|
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
|
data/lib/verica/version.rb
CHANGED
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
|
|
60
|
-
# `chat(parameters:)` calls emit traces.
|
|
61
|
-
#
|
|
62
|
-
|
|
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.
|
|
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
|