feat(storage/otelcache): expose cache stats via OpenTelemetry#93
Merged
Conversation
Add a new storage/otelcache package that bridges storage.CacheStat to OTel observable instruments. Register accepts any value satisfying Observable (Stat() storage.CacheStat) so cache implementations stay free of OTel imports; file.Cache satisfies it directly. Also fix file.Cache.Stat() to populate Entries from the underlying LRU (the field was always zero before). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
jpugliesi
approved these changes
May 18, 2026
4 tasks
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.
Summary
storage/otelcachepackage:Register(provider, observable, attrs...)wiresStat() storage.CacheStatinto OTel observable instruments — gauges for size/limit/entries, counters for hits/misses/evictions. Cache implementations stay free of OTel imports.Observableis a one-method interface (Stat() storage.CacheStat);file.Cachesatisfies it directly with no shims.file.Cache.Stat()to populateEntriesfrom the underlying LRU (it was always zero before).Why this shape
Implementing
go.opentelemetry.io/otel/sdk/metric.Readerwould put the library in the SDK's exporter pipeline — the wrong layer, since the application owns theMeterProvider, Views, and exporter setup. Observable instruments registered against the application'sMeterProviderare the idiomatic pull model; placing them in a separate package that consumesStat()keeps the cache types decoupled from OTel.Usage
Test plan
go test ./storage/otelcache/...go test ./storage/file/...go test ./storage/...go vet ./...storage/filehas no OTel imports (go list -f '{{ join .Imports "\n" }}' ./storage/file | grep otel→ empty)🤖 Generated with Claude Code