Skip to content

Commit d6632c3

Browse files
feat: Add description getter to metrics::Instrument in SDK
This change is in conflict with <#2985>: > Instrument currently allows users to select an instrument based on > description, which is not allowed in the spec. Only name, kind, unit, scope > should be exposed. The spec at <https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#instrument-selection-criteria> says: > The SDK MAY accept additional criteria. So it seems like the description MAY be exposed. This commit also updates docs based on the field definitions, which seem more descriptive, and cleans up some others.
1 parent 95af815 commit d6632c3

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

opentelemetry-sdk/src/metrics/instrument.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@ pub enum InstrumentKind {
3232
/// A group of instruments that record increasing and decreasing values in an
3333
/// asynchronous callback.
3434
ObservableUpDownCounter,
35-
36-
/// a group of instruments that record current value synchronously with
35+
/// A group of instruments that record current value synchronously with
3736
/// the code path they are measuring.
3837
Gauge,
39-
///
40-
/// a group of instruments that record current values in an asynchronous callback.
38+
/// A group of instruments that record current values in an asynchronous callback.
4139
ObservableGauge,
4240
}
4341

@@ -97,33 +95,38 @@ impl InstrumentKind {
9795
pub struct Instrument {
9896
/// The human-readable identifier of the instrument.
9997
pub(crate) name: Cow<'static, str>,
100-
/// describes the purpose of the instrument.
98+
/// Describes the purpose of the instrument.
10199
pub(crate) description: Cow<'static, str>,
102100
/// The functional group of the instrument.
103101
pub(crate) kind: InstrumentKind,
104-
/// Unit is the unit of measurement recorded by the instrument.
102+
/// The unit of measurement recorded by the instrument.
105103
pub(crate) unit: Cow<'static, str>,
106-
/// The instrumentation that created the instrument.
104+
/// Information about the library that created the instrument.
107105
pub(crate) scope: InstrumentationScope,
108106
}
109107

110108
impl Instrument {
111-
/// Instrument name.
109+
/// The human-readable identifier of the instrument.
112110
pub fn name(&self) -> &str {
113111
self.name.as_ref()
114112
}
115113

116-
/// Instrument kind.
114+
/// Describes the purpose of the instrument.
115+
pub fn descripton(&self) -> &str {
116+
self.description.as_ref()
117+
}
118+
119+
/// The functional group of the instrument.
117120
pub fn kind(&self) -> InstrumentKind {
118121
self.kind
119122
}
120123

121-
/// Instrument unit.
124+
/// The unit of measurement recorded by the instrument.
122125
pub fn unit(&self) -> &str {
123126
self.unit.as_ref()
124127
}
125128

126-
/// Instrument scope.
129+
/// Information about the library that created the instrument.
127130
pub fn scope(&self) -> &InstrumentationScope {
128131
&self.scope
129132
}

0 commit comments

Comments
 (0)