Skip to main content

s2n_quic_dc/
event.rs

1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4#[cfg(any(test, feature = "testing"))]
5use s2n_quic_core::event::snapshot;
6
7pub use s2n_quic_core::event::{Event, IntoEvent, Timestamp};
8
9/// Provides metadata related to an event
10pub trait Meta: core::fmt::Debug {
11    /// A context from which the event is being emitted
12    ///
13    /// An event can occur in the context of an Endpoint or Connection
14    fn subject(&self) -> api::Subject;
15}
16
17impl Meta for api::ConnectionMeta {
18    fn subject(&self) -> api::Subject {
19        builder::Subject::Connection { id: self.id }.into_event()
20    }
21}
22
23impl Meta for api::EndpointMeta {
24    fn subject(&self) -> api::Subject {
25        builder::Subject::Endpoint {}.into_event()
26    }
27}
28
29// The generated code is not currently held to the panic lints; suppress them here at the
30// module level rather than annotating each generated site (which would be lost on regeneration).
31#[allow(
32    clippy::panic,
33    clippy::unwrap_used,
34    clippy::unwrap_in_result,
35    clippy::panic_in_result_fn,
36    reason = "FIXME: generated event code is not yet audited for the panic lints"
37)]
38mod generated;
39pub use generated::*;
40
41pub mod metrics {
42    pub use crate::event::generated::metrics::*;
43    pub use s2n_quic_core::event::metrics::Recorder;
44
45    pub mod aggregate {
46        pub use crate::event::generated::metrics::aggregate::*;
47        pub use s2n_quic_core::event::metrics::aggregate::{
48            info, AsVariant, BoolRecorder, Info, Metric, NominalRecorder, Recorder, Registry, Units,
49        };
50
51        pub mod probe {
52            pub use crate::event::generated::metrics::probe::*;
53            pub use s2n_quic_core::event::metrics::aggregate::probe::dynamic;
54        }
55    }
56}
57
58pub mod disabled {
59    #[derive(Clone, Debug, Default)]
60    pub struct Subscriber(());
61
62    impl super::Subscriber for Subscriber {
63        type ConnectionContext = ();
64
65        #[inline]
66        fn create_connection_context(
67            &self,
68            _meta: &super::api::ConnectionMeta,
69            _info: &super::api::ConnectionInfo,
70        ) -> Self::ConnectionContext {
71        }
72    }
73}