Debian Codegraph @

crt/s2n/bindings/rust/standard/s2n-tls-metrics-subscriber/src/lib.rs

raw symbols SCIP
1 // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 // SPDX-License-Identifier: Apache-2.0
3
4 mod bounded_set;
5 mod compatibility;
6 pub(crate) mod counter;
7 pub mod detector;
8 #[cfg(feature = "fuzzing")]
9 pub mod parsing;
10 #[cfg(not(feature = "fuzzing"))]
11 mod parsing;
12 mod record;
13 pub mod subscriber;
14 pub mod telemetry_sink;
15 #[cfg(test)]
16 mod test_utils;
17
18 pub use detector::SyntheticTrafficDetector;
19 pub use subscriber::AggregatedMetricsSubscriber;
20 pub use telemetry_sink::TelemetrySink;
21
22 /// Identifies the source of a metric record by service and resource.
23 #[derive(Debug, Clone, PartialEq, Eq, Default)]
24 pub struct Attribution {
25 /// The service or application name (e.g. "my-tls-service")
26 pub service: String,
27 /// The resource producing metrics (e.g. an ARN or listener name)
28 pub resource: String,
29 /// Distinguishes telemetry from multiple components within the same
30 /// application.
31 pub component: String,
32 }
33
34 impl Attribution {
35 pub(crate) fn into_schema(self) -> s2n_tls_metrics_schema::attribution::Attribution {
36 s2n_tls_metrics_schema::attribution::Attribution {
37 service: self.service,
38 resource: self.resource,
39 component: self.component,
40 }
41 }
42 }
43
44 /// Opaque metric record produced by [`AggregatedMetricsSubscriber`].
45 ///
46 /// This type implements `serde::Serialize` and `metrique_writer::Entry` so
47 /// that [`TelemetrySink`] implementations can serialize it in any format
48 /// without depending on the internal schema types.
49 ///
50 /// For field-level inspection, consumers should depend on
51 /// `s2n-tls-metrics-schema` directly and deserialize from the serialized
52 /// bytes. That crate carries no stability guarantees.
53 #[derive(Debug, Clone)]
54 pub struct MetricRecord(s2n_tls_metrics_schema::record::MetricRecord);
55
56 impl MetricRecord {
57 pub(crate) fn new(inner: s2n_tls_metrics_schema::record::MetricRecord) -> Self {
58 Self(inner)
59 }
60
61 #[cfg(test)]
62 pub(crate) fn as_schema(&self) -> &s2n_tls_metrics_schema::record::MetricRecord {
63 &self.0
64 }
65 }
66
67 impl serde::Serialize for MetricRecord {
68 fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
69 self.0.serialize(serializer)
70 }
71 }
72
73 impl metrique_writer::Entry for MetricRecord {
74 fn write<'a>(&'a self, writer: &mut impl metrique_writer::EntryWriter<'a>) {
75 self.0.write(writer)
76 }
77 }