feat(metrics): add bound instruments behind experimental feature flag#3421
Open
bryantbiggs wants to merge 8 commits intoopen-telemetry:mainfrom
Open
feat(metrics): add bound instruments behind experimental feature flag#3421bryantbiggs wants to merge 8 commits intoopen-telemetry:mainfrom
bryantbiggs wants to merge 8 commits intoopen-telemetry:mainfrom
Conversation
db9517e to
fb725ae
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3421 +/- ##
=======================================
+ Coverage 83.2% 83.4% +0.1%
=======================================
Files 128 128
Lines 25045 25693 +648
=======================================
+ Hits 20858 21433 +575
- Misses 4187 4260 +73 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
18a6278 to
f8a03dc
Compare
…ace iteration Replace the two-HashMap swap-and-drain pattern in collect_and_reset with in-place iteration using TrackerEntry status tracking. TrackerEntry wraps each aggregator with has_been_updated (AtomicBool) and bound_count (AtomicUsize) fields. collect_and_reset now: - Iterates under a read lock (no write lock in steady state) - Exports only entries updated since last collection - Evicts stale unbound entries under a write lock with TOCTOU re-check A new drain_and_reset method preserves the old map-clearing behavior for Observable/async instruments that need staleness detection. This eliminates O(n) write-lock acquisitions on the hot path per collection cycle when attribute sets are reused (the common case). Splits from open-telemetry#3392. Refs open-telemetry#2328.
Per review feedback, bound_count belongs in the bound instruments PR since it's not used by the delta collection refactor alone.
Remove redundant has_no_attribute_value field from ValueMap — the no_attribute_tracker.has_been_updated flag now serves the same purpose. Rewrite changelog entry to focus on user-facing behavior: cardinality overflow recovery now requires 2 collect cycles.
Add BoundCounter and BoundHistogram types that cache resolved aggregator references for a fixed attribute set. Created via Counter::bind() and Histogram::bind(), bound instruments bypass per-call attribute lookup for significant performance improvements (~28x for counters, ~9x for histograms). Architecture: - TrackerEntry.bound_count tracks live handles, preventing eviction - Direct/Fallback enum handles cardinality overflow gracefully - Unsupported aggregators (ExpoHistogram, LastValue, PrecomputedSum) fall back to unbound path instead of panicking All public API, traits, and internal plumbing are gated behind the experimental_metrics_bound_instruments feature flag. Includes 15 tests covering cumulative/delta temporality, overflow fallback, recovery after eviction, bound+unbound sharing, idle cycles, drop semantics, and empty attributes. Splits from open-telemetry#3392. Refs open-telemetry#1374.
cfg-gated imports must sort before non-gated imports of the same module per rustfmt's stable import ordering rules.
Add bound_count field to TrackerEntry to track live bound instrument handles. Entries with bound_count > 0 are never evicted during delta collection, ensuring bound handles always point to a live tracker. Moved from open-telemetry#3420 per review feedback — bound_count belongs with the bound instruments feature, not the delta collection refactor.
f8a03dc to
08649e8
Compare
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.
Splits from #3392, per maintainer feedback. Depends on #3420 (in-place delta collection). Refs #1374.
Summary
Adds
BoundCounterandBoundHistogramto the public API behind theexperimental_metrics_bound_instrumentsfeature flag. These types cache the resolved aggregator reference for a fixed attribute set, allowing subsequent measurements to bypass per-call sort, dedup, hash, and HashMap lookup entirely.Architecture
TrackerEntry bound_count
bound_count(introduced in #3420) tracks how many liveBoundCounter/BoundHistogramhandles reference an entry. Entries withbound_count > 0are never evicted during delta collection.Cardinality overflow handling
ValueMap::bind()returnsOption<Arc<TrackerEntry>>—Nonewhen at the cardinality limit. Bound handle types use aDirect/Fallbackenum:Measure::call()pathFeature flag
All public API, traits, noop impls, and internal plumbing are gated behind
experimental_metrics_bound_instruments.Benchmark Results
Apple M4 Max, 16 cores (12 performance + 4 efficiency), macOS 15.4:
EC2 Counter Results (from #3392)
EC2 Histogram Results (from #3392)
Test Coverage
15 tests covering:
Test plan