pub trait SamplingPolicy:
Send
+ Sync
+ Debug {
// Required method
fn should_sample(&self, kind: &str, correlator: &str) -> bool;
}Expand description
Decide whether to emit a given event based on its kind discriminant and a stable correlator string.
Implementations should be deterministic: invoking
SamplingPolicy::should_sample twice with the same arguments must
return the same result. This guarantee is what lets TelemetryHook
keep paired events (tool.invoked ↔ tool.completed) coherent — the
hook passes the same correlator on both sides of the pair, so the
policy decision is symmetric.
Required Methods§
Sourcefn should_sample(&self, kind: &str, correlator: &str) -> bool
fn should_sample(&self, kind: &str, correlator: &str) -> bool
Return true if the event with the given kind discriminant
(e.g. "tool.invoked", "prompt.completed") and per-emission
correlator should be emitted.
The correlator is producer-supplied and intended to be the
most natural pairing key for the event family — for tool.*
the internal call id, for prompt.* the conversation id, etc.
Policies that ignore it (e.g. AlwaysSample) are free to do
so; policies that hash it (e.g. RatePolicy) get
deterministic, paired-event-safe sampling for free.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".