ask-observability 0.1.0 → 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: d0e28b911f472b83c6a7c93bcd632b9fe981fb39aa6a73e43dbeadc287199faa
4
- data.tar.gz: 8480c74048d04b7e9cf83bfe9614d5d927bdb31865f11a5e159db2ba3ccbce26
3
+ metadata.gz: ffbf52d9051f77149044a23bff976f8e1fe9558a9915e4f48f5b2c0fbf6cbe52
4
+ data.tar.gz: ba7ea476ca3526ba574c653563e30d1fdeab6a61865345c54bf21205cd560053
5
5
  SHA512:
6
- metadata.gz: 49f733327ed7c5c5f3c53931919c41bb7234ec2b487f0dae8d85814cfa3eb3416009cc53e2deba9901d6bb00f1991db5e1ececfed726fe02c274628c031ee65e
7
- data.tar.gz: ac2fa10d43298f99c045c3136bc9c524b1f50f1c9251378907d9df69c9b8f4ee9144284faa5afa3bd6e041784f7253bdaba796232f751224901f5c28d6931baa
6
+ metadata.gz: 60276bbf6712ffb8bf5fe68bcbc70fa22ef7f48667ace0e1de3c220b63bf35e7d6879a8b2d5d9dba6e8df1650c081f581b27778faf7807e1a9eb73fc158f40f0
7
+ data.tar.gz: 9b4ac302576e3fca200f30490c536dc854002d64dd20b787d9d556d27168e8022d17bab2415564f4567524c40d0f158ae8781c80eb9b099836f711f20eef58ca
data/CHANGELOG.md CHANGED
@@ -7,6 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.2] - 2026-08-06
11
+
12
+ ### Fixed
13
+
14
+ - **Token metrics read from the nested `usage` payload hash.** ask-agent now
15
+ enriches `chat.ask` events with a shared nested `usage` hash (tokens/cost
16
+ are only known after the LLM call returns, and the instrumenter
17
+ shallow-copies the top-level payload). The subscriber reads
18
+ `payload[:usage]` first and falls back to top-level
19
+ `input_tokens`/`output_tokens` for other emitters, so
20
+ `ask_llm_tokens_total` counts correctly again.
21
+
22
+ ## [0.1.1] - 2026-08-06
23
+
24
+ ### Added
25
+
26
+ - `Ask::Observability.counter` / `Ask::Observability.histogram` — reload-safe
27
+ register-or-resolve accessors on the shared registry. App files that
28
+ register metrics are re-evaluated by Zeitwerk during development reloads,
29
+ which re-registered the same names against a registry that still held them
30
+ and raised `AlreadyRegisteredError` (surfacing as a 500 in the host app);
31
+ the accessors resolve the existing metric instead.
32
+
10
33
  ## [0.1.0] - 2026-08-06
11
34
 
12
35
  ### Added
@@ -51,8 +51,12 @@ module Ask
51
51
  end
52
52
 
53
53
  def record_tokens(metrics, labels, payload)
54
- input = payload[:input_tokens].to_i
55
- output = payload[:output_tokens].to_i
54
+ # Chat events emitted by ask-agent enrich a shared nested +usage+
55
+ # hash after the call returns (tokens/cost are only known then);
56
+ # other emitters pass input/output tokens at the top level.
57
+ usage = payload[:usage] || payload
58
+ input = usage[:input_tokens].to_i
59
+ output = usage[:output_tokens].to_i
56
60
  return if input.zero? && output.zero?
57
61
 
58
62
  metrics.tokens_total.increment(by: input, labels: labels.merge(direction: 'input')) if input.positive?
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ask
4
4
  module Observability
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.2'
6
6
  end
7
7
  end
@@ -65,6 +65,30 @@ module Ask
65
65
 
66
66
  attr_writer :registry
67
67
 
68
+ # Register-or-resolve a counter on the shared registry. Reload-safe:
69
+ # in development, Zeitwerk re-evaluates app files that register
70
+ # metrics, which would re-register the same name against a registry
71
+ # that still holds it and raise AlreadyRegisteredError (surfacing as
72
+ # a 500 in the app). Resolving the existing metric keeps registrations
73
+ # idempotent instead.
74
+ #
75
+ # @param name [Symbol] metric name, e.g. :voice_turns_total
76
+ # @return [Prometheus::Client::Counter]
77
+ def counter(name, **kwargs)
78
+ registry.get(name) || registry.counter(name, **kwargs)
79
+ rescue Prometheus::Client::Registry::AlreadyRegisteredError
80
+ registry.get(name)
81
+ end
82
+
83
+ # Register-or-resolve a histogram (see #counter).
84
+ #
85
+ # @return [Prometheus::Client::Histogram]
86
+ def histogram(name, **kwargs)
87
+ registry.get(name) || registry.histogram(name, **kwargs)
88
+ rescue Prometheus::Client::Registry::AlreadyRegisteredError
89
+ registry.get(name)
90
+ end
91
+
68
92
  # Subscribe to every ask-instrumentation event and start maintaining
69
93
  # Prometheus metrics. Idempotent — subsequent calls are no-ops.
70
94
  def install
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ask-observability
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaka Ruto