Repository navigation
feat(telemetry): Telemetry::gauge, a last value exported on every collection - #193
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Telemetry::gauge(name)returns aGauge;Gauge::record(value, attrs)sets the value exported. Live, it is an OpenTelemetryf64gauge on the same meter ascounterandhistogram; 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
gaugehas a default no-op implementation on the trait, so aTelemetryimplemented outside the crate (a test double, say) keeps compiling.a_telemetry_impl_without_gauge_gets_a_noop_oneproves 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_costnow callsgaugetoo.cargo fmt --all --checkandcargo clippy --all-features -- -D warningspass.Docs:
docs/telemetry.md"Emitting from a handler",skill/references/telemetry.md, CHANGELOG (Unreleased, Added).🤖 Generated with Claude Code