1
- use std:: { any:: Any , borrow:: Cow , collections:: HashSet , hash:: Hash , marker , sync:: Arc } ;
1
+ use std:: { any:: Any , borrow:: Cow , collections:: HashSet , hash:: Hash , sync:: Arc } ;
2
2
3
3
use opentelemetry:: {
4
- metrics:: {
5
- AsyncInstrument , MetricsError , Result , SyncCounter , SyncGauge , SyncHistogram ,
6
- SyncUpDownCounter ,
7
- } ,
4
+ metrics:: { AsyncInstrument , SyncCounter , SyncGauge , SyncHistogram , SyncUpDownCounter } ,
8
5
Key , KeyValue ,
9
6
} ;
10
7
@@ -13,8 +10,6 @@ use crate::{
13
10
metrics:: { aggregation:: Aggregation , internal:: Measure } ,
14
11
} ;
15
12
16
- pub ( crate ) const EMPTY_MEASURE_MSG : & str = "no aggregators for observable instrument" ;
17
-
18
13
/// The identifier of a group of instruments that all perform the same function.
19
14
#[ derive( Clone , Copy , Debug , Hash , PartialEq , Eq ) ]
20
15
pub enum InstrumentKind {
@@ -289,89 +284,14 @@ impl<T: Copy + 'static> SyncHistogram<T> for ResolvedMeasures<T> {
289
284
}
290
285
}
291
286
292
- /// A comparable unique identifier of an observable.
293
- #[ derive( Clone , Debug ) ]
294
- pub ( crate ) struct ObservableId < T > {
295
- pub ( crate ) inner : IdInner ,
296
- _marker : marker:: PhantomData < T > ,
297
- }
298
-
299
- #[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
300
- pub ( crate ) struct IdInner {
301
- /// The human-readable identifier of the instrument.
302
- pub ( crate ) name : Cow < ' static , str > ,
303
- /// describes the purpose of the instrument.
304
- pub ( crate ) description : Cow < ' static , str > ,
305
- /// The functional group of the instrument.
306
- kind : InstrumentKind ,
307
- /// The unit of measurement recorded by the instrument.
308
- pub ( crate ) unit : Cow < ' static , str > ,
309
- /// The instrumentation that created the instrument.
310
- scope : Scope ,
311
- }
312
-
313
- impl < T > Hash for ObservableId < T > {
314
- fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
315
- self . inner . hash ( state)
316
- }
317
- }
318
-
319
- impl < T > PartialEq for ObservableId < T > {
320
- fn eq ( & self , other : & Self ) -> bool {
321
- self . inner == other. inner
322
- }
323
- }
324
-
325
- impl < T > Eq for ObservableId < T > { }
326
-
327
287
#[ derive( Clone ) ]
328
288
pub ( crate ) struct Observable < T > {
329
- pub ( crate ) id : ObservableId < T > ,
330
289
measures : Vec < Arc < dyn Measure < T > > > ,
331
290
}
332
291
333
292
impl < T > Observable < T > {
334
- pub ( crate ) fn new (
335
- scope : Scope ,
336
- kind : InstrumentKind ,
337
- name : Cow < ' static , str > ,
338
- description : Cow < ' static , str > ,
339
- unit : Cow < ' static , str > ,
340
- measures : Vec < Arc < dyn Measure < T > > > ,
341
- ) -> Self {
342
- Self {
343
- id : ObservableId {
344
- inner : IdInner {
345
- name,
346
- description,
347
- kind,
348
- unit,
349
- scope,
350
- } ,
351
- _marker : marker:: PhantomData ,
352
- } ,
353
- measures,
354
- }
355
- }
356
-
357
- /// Returns `Err` if the observable should not be registered, and `Ok` if it
358
- /// should.
359
- ///
360
- /// An error is returned if this observable is effectively a no-op because it does not have
361
- /// any aggregators. Also, an error is returned if scope defines a Meter other
362
- /// than the observable it was created by.
363
- pub ( crate ) fn registerable ( & self , scope : & Scope ) -> Result < ( ) > {
364
- if self . measures . is_empty ( ) {
365
- return Err ( MetricsError :: Other ( EMPTY_MEASURE_MSG . into ( ) ) ) ;
366
- }
367
- if & self . id . inner . scope != scope {
368
- return Err ( MetricsError :: Other ( format ! (
369
- "invalid registration: observable {} from Meter {:?}, registered with Meter {}" ,
370
- self . id. inner. name, self . id. inner. scope, scope. name,
371
- ) ) ) ;
372
- }
373
-
374
- Ok ( ( ) )
293
+ pub ( crate ) fn new ( measures : Vec < Arc < dyn Measure < T > > > ) -> Self {
294
+ Self { measures }
375
295
}
376
296
}
377
297
0 commit comments