From d6632c3eaf0e69fc5311c38abcedd51559b518d5 Mon Sep 17 00:00:00 2001 From: Diego Ongaro Date: Thu, 13 Nov 2025 21:07:42 -0800 Subject: [PATCH 1/2] feat: Add description getter to `metrics::Instrument` in SDK This change is in conflict with : > 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 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. --- opentelemetry-sdk/src/metrics/instrument.rs | 25 ++++++++++++--------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/opentelemetry-sdk/src/metrics/instrument.rs b/opentelemetry-sdk/src/metrics/instrument.rs index 0ddead600b..24ba31ae30 100644 --- a/opentelemetry-sdk/src/metrics/instrument.rs +++ b/opentelemetry-sdk/src/metrics/instrument.rs @@ -32,12 +32,10 @@ pub enum InstrumentKind { /// A group of instruments that record increasing and decreasing values in an /// asynchronous callback. ObservableUpDownCounter, - - /// a group of instruments that record current value synchronously with + /// A group of instruments that record current value synchronously with /// the code path they are measuring. Gauge, - /// - /// a group of instruments that record current values in an asynchronous callback. + /// A group of instruments that record current values in an asynchronous callback. ObservableGauge, } @@ -97,33 +95,38 @@ impl InstrumentKind { pub struct Instrument { /// The human-readable identifier of the instrument. pub(crate) name: Cow<'static, str>, - /// describes the purpose of the instrument. + /// Describes the purpose of the instrument. pub(crate) description: Cow<'static, str>, /// The functional group of the instrument. pub(crate) kind: InstrumentKind, - /// Unit is the unit of measurement recorded by the instrument. + /// The unit of measurement recorded by the instrument. pub(crate) unit: Cow<'static, str>, - /// The instrumentation that created the instrument. + /// Information about the library that created the instrument. pub(crate) scope: InstrumentationScope, } impl Instrument { - /// Instrument name. + /// The human-readable identifier of the instrument. pub fn name(&self) -> &str { self.name.as_ref() } - /// Instrument kind. + /// Describes the purpose of the instrument. + pub fn descripton(&self) -> &str { + self.description.as_ref() + } + + /// The functional group of the instrument. pub fn kind(&self) -> InstrumentKind { self.kind } - /// Instrument unit. + /// The unit of measurement recorded by the instrument. pub fn unit(&self) -> &str { self.unit.as_ref() } - /// Instrument scope. + /// Information about the library that created the instrument. pub fn scope(&self) -> &InstrumentationScope { &self.scope } From 971db88657d404afa4fce4fbe2a80e227efea3df Mon Sep 17 00:00:00 2001 From: Diego Ongaro Date: Fri, 14 Nov 2025 13:53:52 -0800 Subject: [PATCH 2/2] Fix typo --- opentelemetry-sdk/src/metrics/instrument.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-sdk/src/metrics/instrument.rs b/opentelemetry-sdk/src/metrics/instrument.rs index 24ba31ae30..eea6acc362 100644 --- a/opentelemetry-sdk/src/metrics/instrument.rs +++ b/opentelemetry-sdk/src/metrics/instrument.rs @@ -112,7 +112,7 @@ impl Instrument { } /// Describes the purpose of the instrument. - pub fn descripton(&self) -> &str { + pub fn description(&self) -> &str { self.description.as_ref() }