@@ -3,7 +3,7 @@ use std::{any::Any, borrow::Cow, collections::HashSet, hash::Hash, marker, sync:
3
3
use opentelemetry:: {
4
4
metrics:: {
5
5
AsyncInstrument , MetricsError , Result , SyncCounter , SyncGauge , SyncHistogram ,
6
- SyncUpDownCounter , Unit ,
6
+ SyncUpDownCounter ,
7
7
} ,
8
8
Key , KeyValue ,
9
9
} ;
@@ -69,7 +69,7 @@ pub struct Instrument {
69
69
/// The functional group of the instrument.
70
70
pub kind : Option < InstrumentKind > ,
71
71
/// Unit is the unit of measurement recorded by the instrument.
72
- pub unit : Unit ,
72
+ pub unit : Cow < ' static , str > ,
73
73
/// The instrumentation that created the instrument.
74
74
pub scope : Scope ,
75
75
}
@@ -93,8 +93,8 @@ impl Instrument {
93
93
}
94
94
95
95
/// Set the instrument unit.
96
- pub fn unit ( mut self , unit : Unit ) -> Self {
97
- self . unit = unit;
96
+ pub fn unit ( mut self , unit : impl Into < Cow < ' static , str > > ) -> Self {
97
+ self . unit = unit. into ( ) ;
98
98
self
99
99
}
100
100
@@ -109,7 +109,7 @@ impl Instrument {
109
109
self . name == ""
110
110
&& self . description == ""
111
111
&& self . kind . is_none ( )
112
- && self . unit . as_str ( ) == ""
112
+ && self . unit == ""
113
113
&& self . scope == Scope :: default ( )
114
114
}
115
115
@@ -134,7 +134,7 @@ impl Instrument {
134
134
}
135
135
136
136
pub ( crate ) fn matches_unit ( & self , other : & Instrument ) -> bool {
137
- self . unit . as_str ( ) == "" || self . unit == other. unit
137
+ self . unit . is_empty ( ) || self . unit . as_ref ( ) == other. unit . as_ref ( )
138
138
}
139
139
140
140
pub ( crate ) fn matches_scope ( & self , other : & Instrument ) -> bool {
@@ -171,7 +171,7 @@ pub struct Stream {
171
171
/// Describes the purpose of the data.
172
172
pub description : Cow < ' static , str > ,
173
173
/// the unit of measurement recorded.
174
- pub unit : Unit ,
174
+ pub unit : Cow < ' static , str > ,
175
175
/// Aggregation the stream uses for an instrument.
176
176
pub aggregation : Option < Aggregation > ,
177
177
/// An allow-list of attribute keys that will be preserved for the stream.
@@ -201,8 +201,8 @@ impl Stream {
201
201
}
202
202
203
203
/// Set the stream unit.
204
- pub fn unit ( mut self , unit : Unit ) -> Self {
205
- self . unit = unit;
204
+ pub fn unit ( mut self , unit : impl Into < Cow < ' static , str > > ) -> Self {
205
+ self . unit = unit. into ( ) ;
206
206
self
207
207
}
208
208
@@ -233,7 +233,7 @@ pub(crate) struct InstrumentId {
233
233
/// Defines the functional group of the instrument.
234
234
pub ( crate ) kind : InstrumentKind ,
235
235
/// The unit of measurement recorded.
236
- pub ( crate ) unit : Unit ,
236
+ pub ( crate ) unit : Cow < ' static , str > ,
237
237
/// Number is the underlying data type of the instrument.
238
238
pub ( crate ) number : Cow < ' static , str > ,
239
239
}
@@ -306,7 +306,7 @@ pub(crate) struct IdInner {
306
306
/// The functional group of the instrument.
307
307
kind : InstrumentKind ,
308
308
/// The unit of measurement recorded by the instrument.
309
- pub ( crate ) unit : Unit ,
309
+ pub ( crate ) unit : Cow < ' static , str > ,
310
310
/// The instrumentation that created the instrument.
311
311
scope : Scope ,
312
312
}
@@ -337,7 +337,7 @@ impl<T> Observable<T> {
337
337
kind : InstrumentKind ,
338
338
name : Cow < ' static , str > ,
339
339
description : Cow < ' static , str > ,
340
- unit : Unit ,
340
+ unit : Cow < ' static , str > ,
341
341
measures : Vec < Arc < dyn Measure < T > > > ,
342
342
) -> Self {
343
343
Self {
0 commit comments