opentelemetry_spanprocessor_any/metrics/
sync_instrument.rs1use crate::{
2 metrics::{sdk_api, Number},
3 KeyValue,
4};
5use std::marker;
6use std::sync::Arc;
7
8#[derive(Debug)]
12pub struct Measurement {
13 number: Number,
14 instrument: Arc<dyn sdk_api::SyncInstrumentCore>,
15}
16
17impl Measurement {
18 pub(crate) fn new(number: Number, instrument: Arc<dyn sdk_api::SyncInstrumentCore>) -> Self {
20 Measurement { number, instrument }
21 }
22
23 pub fn number(&self) -> &Number {
25 &self.number
26 }
27
28 pub fn into_number(self) -> Number {
30 self.number
31 }
32
33 pub fn instrument(&self) -> &Arc<dyn sdk_api::SyncInstrumentCore> {
35 &self.instrument
36 }
37}
38
39#[derive(Clone, Debug)]
41pub(crate) struct SyncInstrument<T> {
42 instrument: Arc<dyn sdk_api::SyncInstrumentCore>,
43 _marker: marker::PhantomData<T>,
44}
45
46impl<T> SyncInstrument<T> {
47 pub(crate) fn new(instrument: Arc<dyn sdk_api::SyncInstrumentCore>) -> Self {
49 SyncInstrument {
50 instrument,
51 _marker: marker::PhantomData,
52 }
53 }
54
55 pub(crate) fn bind(&self, attributes: &[KeyValue]) -> SyncBoundInstrument<T> {
57 let bound_instrument = self.instrument.bind(attributes);
58 SyncBoundInstrument {
59 bound_instrument,
60 _marker: marker::PhantomData,
61 }
62 }
63
64 pub(crate) fn direct_record(&self, number: Number, attributes: &[KeyValue]) {
66 self.instrument.record_one(number, attributes)
67 }
68
69 pub(crate) fn instrument(&self) -> &Arc<dyn sdk_api::SyncInstrumentCore> {
71 &self.instrument
72 }
73}
74
75#[derive(Clone, Debug)]
77pub(crate) struct SyncBoundInstrument<T> {
78 bound_instrument: Arc<dyn sdk_api::SyncBoundInstrumentCore>,
79 _marker: marker::PhantomData<T>,
80}
81
82impl<T> SyncBoundInstrument<T> {
83 pub(crate) fn direct_record(&self, number: Number) {
85 self.bound_instrument.record_one(number)
86 }
87}