1 + | /*
|
2 + | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
3 + | * SPDX-License-Identifier: Apache-2.0
|
4 + | */
|
5 + |
|
6 + | //! Metrics are used to gain insight into the operational performance and health of a system in
|
7 + | //! real time.
|
8 + |
|
9 + | use crate::attributes::{Attributes, Context};
|
10 + | use crate::error::ObservabilityError;
|
11 + |
|
12 + | /// Provides named instances of [Meter].
|
13 + | pub trait MeterProvider {
|
14 + | /// Get or create a named [Meter].
|
15 + | fn get_meter(&self, scope: &'static str, attributes: Option<&Attributes>) -> Box<dyn Meter>;
|
16 + |
|
17 + | /// Optional method to flush the metrics pipeline, default is noop
|
18 + | fn flush(&self) -> Result<(), ObservabilityError> {
|
19 + | Ok(())
|
20 + | }
|
21 + |
|
22 + | /// Optional method to shutdown the metrics provider, default is noop
|
23 + | fn shutdown(&self) -> Result<(), ObservabilityError> {
|
24 + | Ok(())
|
25 + | }
|
26 + | }
|
27 + |
|
28 + | /// The entry point to creating instruments. A grouping of related metrics.
|
29 + | pub trait Meter {
|
30 + | /// Create a new Gauge.
|
31 + | #[allow(clippy::type_complexity)]
|
32 + | fn create_gauge(
|
33 + | &self,
|
34 + | name: String,
|
35 + | callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = f64>) + Send + Sync>,
|
36 + | units: Option<String>,
|
37 + | description: Option<String>,
|
38 + | ) -> Box<dyn AsyncMeasurement<Value = f64>>;
|
39 + |
|
40 + | /// Create a new [UpDownCounter].
|
41 + | fn create_up_down_counter(
|
42 + | &self,
|
43 + | name: String,
|
44 + | units: Option<String>,
|
45 + | description: Option<String>,
|
46 + | ) -> Box<dyn UpDownCounter>;
|
47 + |
|
48 + | /// Create a new AsyncUpDownCounter.
|
49 + | #[allow(clippy::type_complexity)]
|
50 + | fn create_async_up_down_counter(
|
51 + | &self,
|
52 + | name: String,
|
53 + | callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = i64>) + Send + Sync>,
|
54 + | units: Option<String>,
|
55 + | description: Option<String>,
|
56 + | ) -> Box<dyn AsyncMeasurement<Value = i64>>;
|
57 + |
|
58 + | /// Create a new [MonotonicCounter].
|
59 + | fn create_monotonic_counter(
|
60 + | &self,
|
61 + | name: String,
|
62 + | units: Option<String>,
|
63 + | description: Option<String>,
|
64 + | ) -> Box<dyn MonotonicCounter>;
|
65 + |
|
66 + | /// Create a new AsyncMonotonicCounter.
|
67 + | #[allow(clippy::type_complexity)]
|
68 + | fn create_async_monotonic_counter(
|
69 + | &self,
|
70 + | name: String,
|
71 + | callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = u64>) + Send + Sync>,
|
72 + | units: Option<String>,
|
73 + | description: Option<String>,
|
74 + | ) -> Box<dyn AsyncMeasurement<Value = u64>>;
|
75 + |
|
76 + | /// Create a new [Histogram].
|
77 + | fn create_histogram(
|
78 + | &self,
|
79 + | name: String,
|
80 + | units: Option<String>,
|
81 + | description: Option<String>,
|
82 + | ) -> Box<dyn Histogram>;
|
83 + | }
|
84 + |
|
85 + | /// Collects a set of events with an event count and sum for all events.
|
86 + | pub trait Histogram {
|
87 + | /// Record a value.
|
88 + | fn record(&self, value: f64, attributes: Option<&Attributes>, context: Option<&dyn Context>);
|
89 + | }
|
90 + |
|
91 + | /// A counter that monotonically increases.
|
92 + | pub trait MonotonicCounter {
|
93 + | /// Increment a counter by a fixed amount.
|
94 + | fn add(&self, value: u64, attributes: Option<&Attributes>, context: Option<&dyn Context>);
|
95 + | }
|
96 + |
|
97 + | /// A counter that can increase or decrease.
|
98 + | pub trait UpDownCounter {
|
99 + | /// Increment or decrement a counter by a fixed amount.
|
100 + | fn add(&self, value: i64, attributes: Option<&Attributes>, context: Option<&dyn Context>);
|
101 + | }
|
102 + |
|
103 + | /// A measurement that can be taken asynchronously.
|
104 + | pub trait AsyncMeasurement {
|
105 + | /// The type recorded by the measurement.
|
106 + | type Value;
|
107 + |
|
108 + | /// Record a value
|
109 + | fn record(
|
110 + | &self,
|
111 + | value: Self::Value,
|
112 + | attributes: Option<&Attributes>,
|
113 + | context: Option<&dyn Context>,
|
114 + | );
|
115 + |
|
116 + | /// Stop recording , unregister callback.
|
117 + | fn stop(&self);
|
118 + | }
|