|
| 1 | +use opentelemetry::{ |
| 2 | + metrics::{ |
| 3 | + AsyncInstrument, InstrumentProvider, SyncCounter, SyncGauge, SyncHistogram, |
| 4 | + SyncUpDownCounter, |
| 5 | + }, |
| 6 | + KeyValue, |
| 7 | +}; |
| 8 | + |
| 9 | +/// A no-op instance of a `Meter` |
| 10 | +#[derive(Debug, Default)] |
| 11 | +pub(crate) struct NoopMeter { |
| 12 | + _private: (), |
| 13 | +} |
| 14 | + |
| 15 | +impl NoopMeter { |
| 16 | + /// Create a new no-op meter core. |
| 17 | + pub(crate) fn new() -> Self { |
| 18 | + NoopMeter { _private: () } |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +impl InstrumentProvider for NoopMeter {} |
| 23 | + |
| 24 | +/// A no-op sync instrument |
| 25 | +#[derive(Debug, Default)] |
| 26 | +pub(crate) struct NoopSyncInstrument { |
| 27 | + _private: (), |
| 28 | +} |
| 29 | + |
| 30 | +impl NoopSyncInstrument { |
| 31 | + /// Create a new no-op sync instrument |
| 32 | + pub(crate) fn new() -> Self { |
| 33 | + NoopSyncInstrument { _private: () } |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +impl<T> SyncCounter<T> for NoopSyncInstrument { |
| 38 | + fn add(&self, _value: T, _attributes: &[KeyValue]) { |
| 39 | + // Ignored |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +impl<T> SyncUpDownCounter<T> for NoopSyncInstrument { |
| 44 | + fn add(&self, _value: T, _attributes: &[KeyValue]) { |
| 45 | + // Ignored |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +impl<T> SyncHistogram<T> for NoopSyncInstrument { |
| 50 | + fn record(&self, _value: T, _attributes: &[KeyValue]) { |
| 51 | + // Ignored |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +impl<T> SyncGauge<T> for NoopSyncInstrument { |
| 56 | + fn record(&self, _value: T, _attributes: &[KeyValue]) { |
| 57 | + // Ignored |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +/// A no-op async instrument. |
| 62 | +#[derive(Debug, Default)] |
| 63 | +pub(crate) struct NoopAsyncInstrument { |
| 64 | + _private: (), |
| 65 | +} |
| 66 | + |
| 67 | +impl NoopAsyncInstrument { |
| 68 | + /// Create a new no-op async instrument |
| 69 | + pub(crate) fn new() -> Self { |
| 70 | + NoopAsyncInstrument { _private: () } |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +impl<T> AsyncInstrument<T> for NoopAsyncInstrument { |
| 75 | + fn observe(&self, _value: T, _attributes: &[KeyValue]) { |
| 76 | + // Ignored |
| 77 | + } |
| 78 | +} |
0 commit comments