1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//! Allows endpoints to subscribe to connection-level and endpoint-level events

use cfg_if::cfg_if;
pub use s2n_quic_core::{
    endpoint::Location,
    event::{
        api as events,
        api::{ConnectionInfo, ConnectionMeta},
        supervisor, Event, Meta, Subscriber, Timestamp,
    },
    query,
};

/// Provides event handling support for an endpoint
pub trait Provider {
    type Subscriber: 'static + Subscriber;
    type Error: 'static + core::fmt::Display + Send + Sync;

    fn start(self) -> Result<Self::Subscriber, Self::Error>;
}

/// Provides an implementation to disable all events
pub mod disabled;

/// This module contains event integration with [`tracing`](https://docs.rs/tracing)
#[cfg(any(feature = "provider-event-tracing", test))]
pub mod tracing;

/// Provides an implementation to emit perf metrics to the console
#[cfg(feature = "provider-event-console-perf")]
pub mod console_perf;

cfg_if! {
    if #[cfg(any(feature = "provider-event-tracing", test))] {
        pub use self::tracing as default;
    } else {
        // Events are disabled by default.
        pub use self::disabled as default;
    }
}

pub use default::Provider as Default;

impl<S> Provider for S
where
    S: 'static + Subscriber,
{
    type Subscriber = S;
    type Error = core::convert::Infallible;

    fn start(self) -> Result<S, Self::Error> {
        Ok(self)
    }
}

impl_provider_utils!();