Skip to main content

proxima_primitives/pipe/
labeled.rs

1use alloc::sync::Arc;
2use bytes::Bytes;
3
4use crate::pipe::request::{Request, Response};
5use crate::pipe::telemetry_surface::{Labels, NoopTelemetry, TelemetryHandle};
6
7/// Telemetry sink + base labels for a payload (HTTP: the request context).
8///
9/// Implement this on any input type to make `Retry` and `RateLimit` emit
10/// telemetry. HTTP implements it on `Request` and `Response`.
11pub trait Labeled {
12    fn telemetry(&self) -> TelemetryHandle;
13    fn labels(&self) -> Labels;
14}
15
16impl Labeled for Request<Bytes> {
17    fn telemetry(&self) -> TelemetryHandle {
18        self.context.telemetry.clone()
19    }
20
21    fn labels(&self) -> Labels {
22        self.context.metric_labels(&[])
23    }
24}
25
26impl Labeled for Response<Bytes> {
27    fn telemetry(&self) -> TelemetryHandle {
28        Arc::new(NoopTelemetry)
29    }
30
31    fn labels(&self) -> Labels {
32        Labels::empty()
33    }
34}