Skip to content

feat(telemetry): Telemetry::gauge, a last value exported on every collection - #193

Merged
aroff merged 1 commit into
mainfrom
feat/telemetry-gauge
Oct 18, 2026
Merged

aroff merged 1 commit into
mainfrom
feat/telemetry-gauge

Conversation

@aroff

@aroff aroff commented Oct 18, 2026

Copy link
Copy Markdown
Owner

What

Telemetry::gauge(name) returns a Gauge; Gauge::record(value, attrs) sets the value exported. Live, it is an OpenTelemetry f64 gauge on the same meter as counter and histogram; off, a no-op.

Why

An app that runs a job once a day wants an alert on "the last good run is older than N hours". With a counter, a process that has not run the job since it started exports no series at all, which reads the same as a process that is not running. A gauge holding "the time of the last good run" is exported again on every collection, so the series stays present between runs, and the alert is time() - last_ok > N.

Compatibility

gauge has a default no-op implementation on the trait, so a Telemetry implemented outside the crate (a test double, say) keeps compiling. a_telemetry_impl_without_gauge_gets_a_noop_one proves it.

Tests

  • live_telemetry_gauge_keeps_its_last_value_between_collections: two values recorded, one exported (the last); a second collection with nothing new recorded exports it again.
  • noop_telemetry_is_zero_cost now calls gauge too.
  • cargo fmt --all --check and cargo clippy --all-features -- -D warnings pass.

Docs: docs/telemetry.md "Emitting from a handler", skill/references/telemetry.md, CHANGELOG (Unreleased, Added).

🤖 Generated with Claude Code

…lection

A counter that has not moved since the process started exports nothing, so an
alert on "the last good run is too old" cannot tell a quiet process from a
missing one. A gauge exports its last value again on every collection, so the
series stays present between rare events.

The trait method has a default no-op implementation: existing Telemetry
implementations, such as test doubles, keep compiling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aroff
aroff enabled auto-merge (squash) October 18, 2026 03:24
@aroff
aroff merged commit fb6b738 into main Oct 18, 2026
6 checks passed
@aroff
aroff deleted the feat/telemetry-gauge branch October 18, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants