You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remove the NamedTimer helper and stop recording any durations as
tally timers. Ad-hoc durations now go through NamedDurationHistogram
(default latency buckets), and Op.Complete records its latency as a
histogram named {name}.latency (previously a {name}.latency timer
plus a redundant {name}.latency_histogram).
Migrated call sites: consumer controller/ack-nack latency, mysql
subscriber poll latency/message age, and Op.Complete.
Timers are unsafe in a distributed system: per-host percentiles
cannot be merged, so any aggregation beyond the mean is imprecise.
Bucketed histograms merge exactly across hosts.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: platform/metrics/README.md
+13-11Lines changed: 13 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
# Metrics Utilities (`platform/metrics`)
2
2
3
-
The `metrics` package provides reusable helpers for emitting counters, timers, histograms, and gauges on a `tally.Scope`. It standardizes metric names across controllers and integrates with `platform/errs` for automatic error classification tags.
3
+
The `metrics` package provides reusable helpers for emitting counters, histograms, and gauges on a `tally.Scope`. It standardizes metric names across controllers and integrates with `platform/errs` for automatic error classification tags.
4
4
5
5
## Design
6
6
7
7
**Free functions on `tally.Scope`** — no wrapper types. Existing constructors accept `tally.Scope` and don't need to change.
8
8
9
-
**Operation lifecycle** — `Begin` and `Complete` tie the full metrics lifecycle together. `Begin` captures the start time and emits `{name}.called`; `Complete` emits succeeded/failed counters, a latency timer, and a latency histogram. This prevents mismatched or forgotten metrics calls.
9
+
**Operation lifecycle** — `Begin` and `Complete` tie the full metrics lifecycle together. `Begin` captures the start time and emits `{name}.called`; `Complete` emits succeeded/failed counters and a latency histogram. This prevents mismatched or forgotten metrics calls.
10
10
11
11
**Error-aware tagging** — `ErrorTags` integrates with `platform/errs` to produce `error_origin=user|infra`, `retryable=true|false`, and `dependency=true` tags automatically. `Complete` uses these to tag latency metrics on failure.
12
12
@@ -19,7 +19,7 @@ For any operation with a clear start/end, use `Begin`/`Complete`:
|`op.Complete(err)`|`{name}.succeeded` or `{name}.failed` counter, `{name}.latency`timer, `{name}.latency_histogram`histogram — all tagged with `result=success\|error` and error classification tags on failure |
22
+
|`op.Complete(err)`|`{name}.succeeded` or `{name}.failed` counter, `{name}.latency` histogram — tagged with `result=success\|error` and error classification tags on failure |
Durations are recorded as **histograms**, never timers. In a distributed system every service instance emits its own metrics, and the monitoring backend aggregates them across hosts. Timer percentiles (p50/p99/max) are computed per host and cannot be merged — averaging two hosts' p99 values, or taking the max of their maxes, does not yield the true fleet-wide p99. Only the mean survives cross-host aggregation intact, so every percentile you actually care about becomes imprecise. Bucketed histograms merge exactly: summing per-host bucket counts reconstructs the true global distribution, so percentiles stay accurate at any aggregation level.
81
+
80
82
## Error Tags
81
83
82
84
`ErrorTags` classifies errors using `platform/errs` and returns tags for dimensional filtering:
0 commit comments