Skip to content

Commit c06c04b

Browse files
authored
Remove API for Creating Histograms with signed integers. (#1371)
As per the OTel [specs], the value to be recorded with histogram instrument SHOULD be non-negative. Removing the existing method to record signed integer values. > The value is expected to be non-negative. This API SHOULD be documented in a way to communicate to users that > this value is expected to be non-negative. This API SHOULD NOT validate this value, that is left to implementations > of the API. [specs]: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#histogram
1 parent a2c0dd8 commit c06c04b

File tree

8 files changed

+14
-80
lines changed

8 files changed

+14
-80
lines changed

opentelemetry-prometheus/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
//! .with_description("Counts things")
2828
//! .init();
2929
//! let histogram = meter
30-
//! .i64_histogram("a.histogram")
30+
//! .u64_histogram("a.histogram")
3131
//! .with_description("Records values")
3232
//! .init();
3333
//!

opentelemetry-prometheus/tests/integration_test.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -492,15 +492,15 @@ fn duplicate_metrics() {
492492
name: "no_conflict_two_histograms",
493493
record_metrics: Box::new(|meter_a, meter_b| {
494494
let foo_a = meter_a
495-
.i64_histogram("foo")
495+
.u64_histogram("foo")
496496
.with_unit(Unit::new("By"))
497497
.with_description("meter histogram foo")
498498
.init();
499499

500500
foo_a.record(100, &[KeyValue::new("A", "B")]);
501501

502502
let foo_b = meter_b
503-
.i64_histogram("foo")
503+
.u64_histogram("foo")
504504
.with_unit(Unit::new("By"))
505505
.with_description("meter histogram foo")
506506
.init();
@@ -564,15 +564,15 @@ fn duplicate_metrics() {
564564
name: "conflict_help_two_histograms",
565565
record_metrics: Box::new(|meter_a, meter_b| {
566566
let bar_a = meter_a
567-
.i64_histogram("bar")
567+
.u64_histogram("bar")
568568
.with_unit(Unit::new("By"))
569569
.with_description("meter a bar")
570570
.init();
571571

572572
bar_a.record(100, &[KeyValue::new("A", "B")]);
573573

574574
let bar_b = meter_b
575-
.i64_histogram("bar")
575+
.u64_histogram("bar")
576576
.with_unit(Unit::new("By"))
577577
.with_description("meter b bar")
578578
.init();
@@ -635,15 +635,15 @@ fn duplicate_metrics() {
635635
name: "conflict_unit_two_histograms",
636636
record_metrics: Box::new(|meter_a, meter_b| {
637637
let bar_a = meter_a
638-
.i64_histogram("bar")
638+
.u64_histogram("bar")
639639
.with_unit(Unit::new("By"))
640640
.with_description("meter histogram bar")
641641
.init();
642642

643643
bar_a.record(100, &[KeyValue::new("A", "B")]);
644644

645645
let bar_b = meter_b
646-
.i64_histogram("bar")
646+
.u64_histogram("bar")
647647
.with_unit(Unit::new("ms"))
648648
.with_description("meter histogram bar")
649649
.init();
@@ -692,7 +692,7 @@ fn duplicate_metrics() {
692692
foo_a.add(100, &[KeyValue::new("A", "B")]);
693693

694694
let foo_histogram_a = meter_a
695-
.i64_histogram("foo")
695+
.u64_histogram("foo")
696696
.with_unit(Unit::new("By"))
697697
.with_description("meter histogram foo")
698698
.init();

opentelemetry-sdk/benches/metric.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ fn counters(c: &mut Criterion) {
349349

350350
const MAX_BOUND: usize = 100000;
351351

352-
fn bench_histogram(bound_count: usize) -> (SharedReader, Histogram<i64>) {
352+
fn bench_histogram(bound_count: usize) -> (SharedReader, Histogram<u64>) {
353353
let mut bounds = vec![0; bound_count];
354354
#[allow(clippy::needless_range_loop)]
355355
for i in 0..bounds.len() {
@@ -373,7 +373,7 @@ fn bench_histogram(bound_count: usize) -> (SharedReader, Histogram<i64>) {
373373
}
374374
let mtr = builder.build().meter("test_meter");
375375
let hist = mtr
376-
.i64_histogram(format!("histogram_{}", bound_count))
376+
.u64_histogram(format!("histogram_{}", bound_count))
377377
.init();
378378

379379
(r, hist)
@@ -393,7 +393,7 @@ fn histograms(c: &mut Criterion) {
393393
format!("V,{},{},{}", bound_size, attr_size, i),
394394
))
395395
}
396-
let value: i64 = rng.gen_range(0..MAX_BOUND).try_into().unwrap();
396+
let value: u64 = rng.gen_range(0..MAX_BOUND).try_into().unwrap();
397397
group.bench_function(
398398
format!("Record{}Attrs{}bounds", attr_size, bound_size),
399399
|b| b.iter(|| hist.record(value, &attributes)),
@@ -414,7 +414,7 @@ fn benchmark_collect_histogram(b: &mut Bencher, n: usize) {
414414
.meter("sdk/metric/bench/histogram");
415415

416416
for i in 0..n {
417-
let h = mtr.i64_histogram(format!("fake_data_{i}")).init();
417+
let h = mtr.u64_histogram(format!("fake_data_{i}")).init();
418418
h.record(1, &[]);
419419
}
420420

opentelemetry-sdk/src/metrics/meter.rs

-24
Original file line numberDiff line numberDiff line change
@@ -444,24 +444,6 @@ impl InstrumentProvider for SdkMeter {
444444
.map(|i| Histogram::new(Arc::new(i)))
445445
}
446446

447-
fn i64_histogram(
448-
&self,
449-
name: Cow<'static, str>,
450-
description: Option<Cow<'static, str>>,
451-
unit: Option<Unit>,
452-
) -> Result<Histogram<i64>> {
453-
validate_instrument_config(name.as_ref(), unit.as_ref(), self.validation_policy)?;
454-
let p = InstrumentResolver::new(self, &self.i64_resolver);
455-
456-
p.lookup(
457-
InstrumentKind::Histogram,
458-
name,
459-
description,
460-
unit.unwrap_or_default(),
461-
)
462-
.map(|i| Histogram::new(Arc::new(i)))
463-
}
464-
465447
fn register_callback(
466448
&self,
467449
insts: &[Arc<dyn Any>],
@@ -819,7 +801,6 @@ mod tests {
819801
);
820802
assert(meter.f64_histogram(name.into(), None, None).map(|_| ()));
821803
assert(meter.u64_histogram(name.into(), None, None).map(|_| ()));
822-
assert(meter.i64_histogram(name.into(), None, None).map(|_| ()));
823804
}
824805

825806
// (unit, expected error)
@@ -909,11 +890,6 @@ mod tests {
909890
.u64_histogram("test".into(), None, unit.clone())
910891
.map(|_| ()),
911892
);
912-
assert(
913-
meter
914-
.i64_histogram("test".into(), None, unit.clone())
915-
.map(|_| ()),
916-
);
917893
}
918894
}
919895
}

opentelemetry/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ gains, and avoids `IndexMap` dependency. This affects `body` and `attributes` of
1313

1414
### Removed
1515

16-
Removed `OrderMap` type as there was no requirement to use this over regular
16+
- Removed `OrderMap` type as there was no requirement to use this over regular
1717
`HashMap`.
1818
[#1353](https://github.com/open-telemetry/opentelemetry-rust/pull/1353)
19+
- Remove API for Creating Histograms with signed integers. [#1371](https://github.com/open-telemetry/opentelemetry-rust/pull/1371)
1920

2021
## [v0.21.0](https://github.com/open-telemetry/opentelemetry-rust/compare/v0.20.0...v0.21.0)
2122

opentelemetry/src/metrics/instruments/histogram.rs

-12
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,3 @@ impl TryFrom<InstrumentBuilder<'_, Histogram<u64>>> for Histogram<u64> {
6060
)
6161
}
6262
}
63-
64-
impl TryFrom<InstrumentBuilder<'_, Histogram<i64>>> for Histogram<i64> {
65-
type Error = MetricsError;
66-
67-
fn try_from(builder: InstrumentBuilder<'_, Histogram<i64>>) -> Result<Self, Self::Error> {
68-
builder.meter.instrument_provider.i64_histogram(
69-
builder.name,
70-
builder.description,
71-
builder.unit,
72-
)
73-
}
74-
}

opentelemetry/src/metrics/meter.rs

-21
Original file line numberDiff line numberDiff line change
@@ -241,19 +241,6 @@ pub trait MeterProvider {
241241
/// .as_ref(),
242242
/// );
243243
///
244-
/// // i64 histogram
245-
/// let i64_histogram = meter.i64_histogram("my_i64_histogram").init();
246-
///
247-
/// // Record measurements using the histogram instrument record()
248-
/// i64_histogram.record(
249-
/// 1,
250-
/// [
251-
/// KeyValue::new("mykey1", "myvalue1"),
252-
/// KeyValue::new("mykey2", "myvalue2"),
253-
/// ]
254-
/// .as_ref(),
255-
/// );
256-
///
257244
/// // u64 histogram
258245
/// let u64_histogram = meter.u64_histogram("my_u64_histogram").init();
259246
///
@@ -386,14 +373,6 @@ impl Meter {
386373
InstrumentBuilder::new(self, name.into())
387374
}
388375

389-
/// creates an instrument builder for recording a distribution of values.
390-
pub fn i64_histogram(
391-
&self,
392-
name: impl Into<Cow<'static, str>>,
393-
) -> InstrumentBuilder<'_, Histogram<i64>> {
394-
InstrumentBuilder::new(self, name.into())
395-
}
396-
397376
/// Registers a callback to be called during the collection of a measurement
398377
/// cycle.
399378
///

opentelemetry/src/metrics/mod.rs

-10
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,6 @@ pub trait InstrumentProvider {
238238
Ok(Histogram::new(Arc::new(noop::NoopSyncInstrument::new())))
239239
}
240240

241-
/// creates an instrument for recording a distribution of values.
242-
fn i64_histogram(
243-
&self,
244-
_name: Cow<'static, str>,
245-
_description: Option<Cow<'static, str>>,
246-
_unit: Option<Unit>,
247-
) -> Result<Histogram<i64>> {
248-
Ok(Histogram::new(Arc::new(noop::NoopSyncInstrument::new())))
249-
}
250-
251241
/// Captures the function that will be called during data collection.
252242
///
253243
/// It is only valid to call `observe` within the scope of the passed function.

0 commit comments

Comments
 (0)