Skip to content

Commit 07b918d

Browse files
authored
Remove ability to specify observable callback on Meter (#2015)
1 parent 17b99a1 commit 07b918d

File tree

7 files changed

+167
-553
lines changed

7 files changed

+167
-553
lines changed

opentelemetry-sdk/src/metrics/instrument.rs

+4-84
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
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};
22

33
use opentelemetry::{
4-
metrics::{
5-
AsyncInstrument, MetricsError, Result, SyncCounter, SyncGauge, SyncHistogram,
6-
SyncUpDownCounter,
7-
},
4+
metrics::{AsyncInstrument, SyncCounter, SyncGauge, SyncHistogram, SyncUpDownCounter},
85
Key, KeyValue,
96
};
107

@@ -13,8 +10,6 @@ use crate::{
1310
metrics::{aggregation::Aggregation, internal::Measure},
1411
};
1512

16-
pub(crate) const EMPTY_MEASURE_MSG: &str = "no aggregators for observable instrument";
17-
1813
/// The identifier of a group of instruments that all perform the same function.
1914
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
2015
pub enum InstrumentKind {
@@ -289,89 +284,14 @@ impl<T: Copy + 'static> SyncHistogram<T> for ResolvedMeasures<T> {
289284
}
290285
}
291286

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-
327287
#[derive(Clone)]
328288
pub(crate) struct Observable<T> {
329-
pub(crate) id: ObservableId<T>,
330289
measures: Vec<Arc<dyn Measure<T>>>,
331290
}
332291

333292
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 }
375295
}
376296
}
377297

0 commit comments

Comments
 (0)