feat(telemetry): wire metrics plugins to generation_batch_* hooks#1254
Conversation
Fixes generative-computing#1182. PR generative-computing#1181 introduced generation_batch_{pre_call,post_call,error} hooks for the raw path; the tracing plugin subscribed but the metrics plugins did not, so generate_from_raw calls produced zero metrics. Token, latency, error, and cost metrics plugins now subscribe to the matching generation_batch_* hook in addition to their existing per-MOT hook. Per-MOT handlers are unchanged. The stale note in docs/docs/observability/metrics.md is removed. Assisted-by: Claude Code Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
cdf973a to
1479a5b
Compare
|
CostMetricsPlugin (lines 144–187) Current implementation: 🐛 BUG IDENTIFIED (line 179): When gen.provider is None, this passes None to compute_cost, but:
This means compute_cost receives None while record_cost receives "unknown" — inconsistent, and compute_cost may fail if it expects a string. Fix needed: PR's batch handler (lines 257–289) repeats this bug: |
planetf1
left a comment
There was a problem hiding this comment.
Thanks for the clean fix — wiring all four plugins symmetrically with the tracing plugin is exactly right, and the test coverage is thorough. Two small notes below.
|
The unit tests call the handlers directly, bypassing hook dispatch — the thing this PR is actually wiring. The |
Adds an integration test that drives generate_from_raw against a nonexistent model and asserts the error counter is recorded, covering the dispatch path through the generation_batch_error hook. Also fixes the existing error test to honor OLLAMA_HOST instead of hardcoding localhost:11434, matching the rest of the file. Assisted-by: Claude Code Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
done in a03e99e
@akihikokuroda this is intentional, |
7e23948
Issue
Fixes #1182
Description
PR #1181 introduced
generation_batch_{pre_call,post_call,error}hooks forthe raw path; the tracing plugin subscribed but the metrics plugins did
not, so
generate_from_rawcalls produced zero metrics. This wires thefour affected metrics plugins to the corresponding batch hooks so that
token, latency, cost, and error metrics are recorded for raw-path
generations the same as for the chat path.
Source-side changes (
mellea/telemetry/metrics_plugins.py):TokenMetricsPluginnow also subscribes togeneration_batch_post_calland reads
payload.usage.LatencyMetricsPluginnow also subscribes togeneration_batch_post_calland records duration from
payload.latency_ms. The batch path isnon-streaming, so TTFB does not apply.
ErrorMetricsPluginnow also subscribes togeneration_batch_errorandclassifies the exception from
payload.exception.CostMetricsPluginnow also subscribes togeneration_batch_post_calland computes cost from
payload.usage/payload.model/payload.provider.The per-MOT handlers are unchanged. Class docstrings updated to reflect
the additional hook subscription.
Doc: removed the now-stale note in
docs/docs/observability/metrics.mdclaiminggenerate_from_rawdoes notrecord token metrics.
Test-side changes:
test/telemetry/test_metrics_plugins.py: 13 new unit tests mirroring theexisting per-MOT coverage for token, latency, cost, and error batch
handlers (success, missing fields, fallback to
"unknown", cache tokenforwarding for cost, unknown-model skip).
test/telemetry/test_metrics_backend.py: one e2e test that drives a realOllama backend through
generate_from_rawand asserts token and latencymetrics are recorded.
Testing
Attribution