feat(cachet): structured telemetry with spans, events, and handler API#460
Draft
schgoo wants to merge 8 commits into
Draft
feat(cachet): structured telemetry with spans, events, and handler API#460schgoo wants to merge 8 commits into
schgoo wants to merge 8 commits into
Conversation
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #460 +/- ##
========================================
- Coverage 100.0% 99.9% -0.1%
========================================
Files 307 306 -1
Lines 23903 24432 +529
========================================
+ Hits 23903 24423 +520
- Misses 0 9 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
Replaces cachet's event-only telemetry with a span + event model that provides per-tier timing, request correlation, and a callback API for consumers to build custom telemetry pipelines.
Motivation
The previous telemetry emitted standalone tracing events with no correlation between tiers. Consumers couldn't distinguish which tier events belonged to which cache operation, and there was no way to subscribe to structured telemetry without parsing tracing fields via the visitor pattern.
Changes
Tracing spans + events
Cachemethod (get,insert,invalidate,clear,get_or_insert, etc.) creates a parent span viaCacheTelemetryCacheWrappertier operation creates a child span, producing a nested trace:cache.get → cache.tierCacheEventHandlercallback APICacheEventHandlertrait withon_tier_eventandon_operation_completecallbacksCacheBuilder::event_handler(handler)CacheTierEventandCacheOperationEventstructs — no tracing visitor boilerplatelogsfeature flagemitRequest correlation
request_id: u64from a process-wide atomic counterWithRequestId<F>future wrapper restores the request ID into a thread-local on everypoll(), surviving task migration across threads/cores (same pattern astracing::Instrument)CacheTierEventandCacheOperationEventcarry therequest_idfor groupingFallback as a flag
cache.fallbackis now a boolean flag on tier events, not a separate event typeRemoved
telemetry/ext.rs(ClockExt,Timed,TimedResult) — replaced byclock.stopwatch()directlyEVENT_FALLBACKandEVENT_REQUEST_MERGEDattribute constantsCacheTelemetryInner— span creation moved intoCacheTelemetrydirectlyNew attributes
FIELD_COALESCED— boolean flag for stampede protectionFIELD_FALLBACK— boolean flag for fallback tier consultationExamples
telemetry_subscriber— shows span + event output withtracing_subscriber::fmttelemetry_accumulator— demonstrates accumulating tier events into a single summary per operation usingCacheEventHandler+DashMap, mirroring a TVS-style consumer patternPerformance
Benchmarked in release mode (MockCache get, single tier):
Telemetry with no active subscriber adds ~10ns overhead. The
WithRequestIdwrapper adds ~300ns on the stampede protection path.