Skip to content

Commit b695ba1

Browse files
authored
Deprecate ValueRecorder in favor of Histogram (open-telemetry#728)
The Metric API Spec is now stable and ValueRecorder was replaced with Histogram. * Deprecations - left structs unmarked as clippy threw a fit. * Update all code examples to use Histograms. * Remove InstrumentKind::ValueRecorder since it's not part of the API. ** Otherwise we were left with duplicating code int the SDK which does exactly the same thing. Signed-off-by: Harold Dost <[email protected]>
1 parent aee4249 commit b695ba1

File tree

20 files changed

+219
-71
lines changed

20 files changed

+219
-71
lines changed

examples/basic-otlp-with-selector/src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,16 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
113113
.with_description("A ValueObserver set to 1.0")
114114
.init();
115115

116-
let value_recorder_two = meter.f64_value_recorder("ex.com.two").init();
116+
let histogram_two = meter.f64_histogram("ex.com.two").init();
117117

118-
let another_recorder = meter.f64_value_recorder("ex.com.two").init();
118+
let another_recorder = meter.f64_histogram("ex.com.two").init();
119119
another_recorder.record(5.5, COMMON_ATTRIBUTES.as_ref());
120120

121121
let _baggage =
122122
Context::current_with_baggage(vec![FOO_KEY.string("foo1"), BAR_KEY.string("bar1")])
123123
.attach();
124124

125-
let value_recorder = value_recorder_two.bind(COMMON_ATTRIBUTES.as_ref());
125+
let histogram = histogram_two.bind(COMMON_ATTRIBUTES.as_ref());
126126
tracer.in_span("operation", |cx| {
127127
let span = cx.span();
128128
span.add_event(
@@ -135,7 +135,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
135135
// Note: call-site variables added as context Entries:
136136
&Context::current_with_baggage(vec![ANOTHER_KEY.string("xyz")]),
137137
COMMON_ATTRIBUTES.as_ref(),
138-
vec![value_recorder_two.measurement(2.0)],
138+
vec![histogram_two.measurement(2.0)],
139139
);
140140

141141
tracer.in_span("Sub operation...", |cx| {
@@ -144,7 +144,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
144144

145145
span.add_event("Sub span event".to_string(), vec![]);
146146

147-
value_recorder.record(1.3);
147+
histogram.record(1.3);
148148
});
149149
});
150150

examples/basic-otlp/src/main.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,27 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
7777
.with_description("A ValueObserver set to 1.0")
7878
.init();
7979

80-
let value_recorder_two = meter.f64_value_recorder("ex.com.two").init();
81-
82-
let another_recorder = meter.f64_value_recorder("ex.com.two").init();
83-
another_recorder.record(5.5, COMMON_ATTRIBUTES.as_ref());
80+
let histogram_two = meter.f64_histogram("ex.com.two").init();
81+
82+
// Needed for code coverage reasons.
83+
#[allow(deprecated)]
84+
let a_recorder = meter.f64_value_recorder("ex.recorder.a").init();
85+
a_recorder.record(5.5, COMMON_ATTRIBUTES.as_ref());
86+
#[allow(deprecated)]
87+
let b_recorder = meter.u64_value_recorder("ex.recorder.b").init();
88+
b_recorder.record(5, COMMON_ATTRIBUTES.as_ref());
89+
#[allow(deprecated)]
90+
let c_recorder = meter.i64_value_recorder("ex.recorder.c").init();
91+
c_recorder.record(5, COMMON_ATTRIBUTES.as_ref());
92+
93+
let another_histogram = meter.f64_histogram("ex.com.two").init();
94+
another_histogram.record(5.5, COMMON_ATTRIBUTES.as_ref());
8495

8596
let _baggage =
8697
Context::current_with_baggage(vec![FOO_KEY.string("foo1"), BAR_KEY.string("bar1")])
8798
.attach();
8899

89-
let value_recorder = value_recorder_two.bind(COMMON_ATTRIBUTES.as_ref());
100+
let histogram = histogram_two.bind(COMMON_ATTRIBUTES.as_ref());
90101

91102
tracer.in_span("operation", |cx| {
92103
let span = cx.span();
@@ -100,7 +111,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
100111
// Note: call-site variables added as context Entries:
101112
&Context::current_with_baggage(vec![ANOTHER_KEY.string("xyz")]),
102113
COMMON_ATTRIBUTES.as_ref(),
103-
vec![value_recorder_two.measurement(2.0)],
114+
vec![histogram_two.measurement(2.0)],
104115
);
105116

106117
tracer.in_span("Sub operation...", |cx| {
@@ -109,7 +120,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
109120

110121
span.add_event("Sub span event".to_string(), vec![]);
111122

112-
value_recorder.record(1.3);
123+
histogram.record(1.3);
113124
});
114125
});
115126

examples/basic/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
7070
.with_description("A ValueObserver set to 1.0")
7171
.init();
7272

73-
let value_recorder_two = meter.f64_value_recorder("ex.com.two").init();
73+
let histogram_two = meter.f64_histogram("ex.com.two").init();
7474

7575
let _baggage =
7676
Context::current_with_baggage(vec![FOO_KEY.string("foo1"), BAR_KEY.string("bar1")])
7777
.attach();
7878

79-
let value_recorder = value_recorder_two.bind(COMMON_ATTRIBUTES.as_ref());
79+
let histogram = histogram_two.bind(COMMON_ATTRIBUTES.as_ref());
8080

8181
tracer.in_span("operation", |cx| {
8282
let span = cx.span();
@@ -90,7 +90,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
9090
// Note: call-site variables added as context Entries:
9191
&Context::current_with_baggage(vec![ANOTHER_KEY.string("xyz")]),
9292
COMMON_ATTRIBUTES.as_ref(),
93-
vec![value_recorder_two.measurement(2.0)],
93+
vec![histogram_two.measurement(2.0)],
9494
);
9595

9696
tracer.in_span("Sub operation...", |cx| {
@@ -99,7 +99,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
9999

100100
span.add_event("Sub span event".to_string(), vec![]);
101101

102-
value_recorder.record(1.3);
102+
histogram.record(1.3);
103103
});
104104
});
105105

examples/dynatrace/src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,16 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
140140
.with_description("A ValueObserver set to 1.0")
141141
.init();
142142

143-
let value_recorder_two = meter.f64_value_recorder("ex.com.two").init();
143+
let histogram_two = meter.f64_histogram("ex.com.two").init();
144144

145-
let another_recorder = meter.f64_value_recorder("ex.com.two").init();
145+
let another_recorder = meter.f64_histogram("ex.com.two").init();
146146
another_recorder.record(5.5, COMMON_ATTRIBUTES.as_ref());
147147

148148
let _baggage =
149149
Context::current_with_baggage(vec![FOO_KEY.string("foo1"), BAR_KEY.string("bar1")])
150150
.attach();
151151

152-
let value_recorder = value_recorder_two.bind(COMMON_ATTRIBUTES.as_ref());
152+
let histogram = histogram_two.bind(COMMON_ATTRIBUTES.as_ref());
153153

154154
tracer.in_span("operation", |cx| {
155155
let span = cx.span();
@@ -163,7 +163,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
163163
// Note: call-site variables added as context Entries:
164164
&Context::current_with_baggage(vec![ANOTHER_KEY.string("xyz")]),
165165
COMMON_ATTRIBUTES.as_ref(),
166-
vec![value_recorder_two.measurement(2.0)],
166+
vec![histogram_two.measurement(2.0)],
167167
);
168168

169169
tracer.in_span("Sub operation...", |cx| {
@@ -172,7 +172,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
172172

173173
span.add_event("Sub span event".to_string(), vec![]);
174174

175-
value_recorder.record(1.3);
175+
histogram.record(1.3);
176176
});
177177
});
178178

examples/hyper-prometheus/src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use hyper::{
88
};
99
use opentelemetry::{
1010
global,
11-
metrics::{BoundCounter, BoundValueRecorder},
11+
metrics::{BoundCounter, BoundHistogram},
1212
KeyValue,
1313
};
1414
use opentelemetry_prometheus::PrometheusExporter;
@@ -63,8 +63,8 @@ async fn serve_req(
6363
struct AppState {
6464
exporter: PrometheusExporter,
6565
http_counter: BoundCounter<u64>,
66-
http_body_gauge: BoundValueRecorder<u64>,
67-
http_req_histogram: BoundValueRecorder<f64>,
66+
http_body_gauge: BoundHistogram<u64>,
67+
http_req_histogram: BoundHistogram<f64>,
6868
}
6969

7070
#[tokio::main]
@@ -80,12 +80,12 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
8080
.init()
8181
.bind(HANDLER_ALL.as_ref()),
8282
http_body_gauge: meter
83-
.u64_value_recorder("example.http_response_size_bytes")
83+
.u64_histogram("example.http_response_size_bytes")
8484
.with_description("The metrics HTTP response sizes in bytes.")
8585
.init()
8686
.bind(HANDLER_ALL.as_ref()),
8787
http_req_histogram: meter
88-
.f64_value_recorder("example.http_request_duration_seconds")
88+
.f64_histogram("example.http_request_duration_seconds")
8989
.with_description("The HTTP request latencies in seconds.")
9090
.init()
9191
.bind(HANDLER_ALL.as_ref()),

opentelemetry-dynatrace/src/transform/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ mod tests {
11121112
"test_histogram".to_string(),
11131113
"test",
11141114
None,
1115-
InstrumentKind::ValueRecorder,
1115+
InstrumentKind::Histogram,
11161116
NumberKind::I64,
11171117
);
11181118
let bound = [0.1, 0.2, 0.3];

opentelemetry-dynatrace/tests/http_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ mod test {
9898
let recorder = meter.f64_counter("test2").init();
9999
recorder.add(1e10 + 0.123, &[KeyValue::new("foo", "bar")]);
100100

101-
let recorder = meter.i64_value_recorder("test3").init();
101+
let recorder = meter.i64_histogram("test3").init();
102102
recorder.record(-999, &[Key::new("foo").i64(-123)]);
103103

104104
let _ = tick_tx.send(1);

opentelemetry-otlp/src/transform/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ mod tests {
626626
"test".to_string(),
627627
"test",
628628
None,
629-
InstrumentKind::ValueRecorder,
629+
InstrumentKind::Histogram,
630630
NumberKind::I64,
631631
);
632632
let bound = [0.1, 0.2, 0.3];

opentelemetry-prometheus/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
//! .with_description("Counts things")
2323
//! .init();
2424
//! let recorder = meter
25-
//! .i64_value_recorder("a.value_recorder")
25+
//! .i64_histogram("a.histogram")
2626
//! .with_description("Records values")
2727
//! .init();
2828
//!
@@ -40,14 +40,14 @@
4040
//! // # HELP a_counter Counts things
4141
//! // # TYPE a_counter counter
4242
//! // a_counter{R="V",key="value"} 100
43-
//! // # HELP a_value_recorder Records values
44-
//! // # TYPE a_value_recorder histogram
45-
//! // a_value_recorder_bucket{R="V",key="value",le="0.5"} 0
46-
//! // a_value_recorder_bucket{R="V",key="value",le="0.9"} 0
47-
//! // a_value_recorder_bucket{R="V",key="value",le="0.99"} 0
48-
//! // a_value_recorder_bucket{R="V",key="value",le="+Inf"} 1
49-
//! // a_value_recorder_sum{R="V",key="value"} 100
50-
//! // a_value_recorder_count{R="V",key="value"} 1
43+
//! // # HELP a_histogram Records values
44+
//! // # TYPE a_histogram histogram
45+
//! // a_histogram_bucket{R="V",key="value",le="0.5"} 0
46+
//! // a_histogram_bucket{R="V",key="value",le="0.9"} 0
47+
//! // a_histogram_bucket{R="V",key="value",le="0.99"} 0
48+
//! // a_histogram_bucket{R="V",key="value",le="+Inf"} 1
49+
//! // a_histogram_sum{R="V",key="value"} 100
50+
//! // a_histogram_count{R="V",key="value"} 1
5151
//! ```
5252
#![warn(
5353
future_incompatible,

opentelemetry-prometheus/tests/integration_test.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn test_add() {
7272

7373
let up_down_counter = meter.f64_up_down_counter("updowncounter").init();
7474
let counter = meter.f64_counter("counter").init();
75-
let value_recorder = meter.f64_value_recorder("value_recorder").init();
75+
let histogram = meter.f64_histogram("my.histogram").init();
7676

7777
let attributes = vec![KeyValue::new("A", "B"), KeyValue::new("C", "D")];
7878

@@ -92,16 +92,16 @@ fn test_add() {
9292

9393
expected.push(r#"intobserver{A="B",C="D",R="V"} 1"#);
9494

95-
value_recorder.record(-0.6, &attributes);
96-
value_recorder.record(-0.4, &attributes);
97-
value_recorder.record(0.6, &attributes);
98-
value_recorder.record(20.0, &attributes);
95+
histogram.record(-0.6, &attributes);
96+
histogram.record(-0.4, &attributes);
97+
histogram.record(0.6, &attributes);
98+
histogram.record(20.0, &attributes);
9999

100-
expected.push(r#"value_recorder_bucket{A="B",C="D",R="V",le="+Inf"} 4"#);
101-
expected.push(r#"value_recorder_bucket{A="B",C="D",R="V",le="-0.5"} 1"#);
102-
expected.push(r#"value_recorder_bucket{A="B",C="D",R="V",le="1"} 3"#);
103-
expected.push(r#"value_recorder_count{A="B",C="D",R="V"} 4"#);
104-
expected.push(r#"value_recorder_sum{A="B",C="D",R="V"} 19.6"#);
100+
expected.push(r#"my_histogram_bucket{A="B",C="D",R="V",le="+Inf"} 4"#);
101+
expected.push(r#"my_histogram_bucket{A="B",C="D",R="V",le="-0.5"} 1"#);
102+
expected.push(r#"my_histogram_bucket{A="B",C="D",R="V",le="1"} 3"#);
103+
expected.push(r#"my_histogram_count{A="B",C="D",R="V"} 4"#);
104+
expected.push(r#"my_histogram_sum{A="B",C="D",R="V"} 19.6"#);
105105

106106
up_down_counter.add(10.0, &attributes);
107107
up_down_counter.add(-3.2, &attributes);
@@ -122,15 +122,15 @@ fn test_sanitization() {
122122
.init();
123123
let meter = exporter.provider().unwrap().meter("test", None);
124124

125-
let value_recorder = meter.f64_value_recorder("http.server.duration").init();
125+
let histogram = meter.f64_histogram("http.server.duration").init();
126126
let attributes = vec![
127127
KeyValue::new("http.method", "GET"),
128128
KeyValue::new("http.host", "server"),
129129
];
130-
value_recorder.record(-0.6, &attributes);
131-
value_recorder.record(-0.4, &attributes);
132-
value_recorder.record(0.6, &attributes);
133-
value_recorder.record(20.0, &attributes);
130+
histogram.record(-0.6, &attributes);
131+
histogram.record(-0.4, &attributes);
132+
histogram.record(0.6, &attributes);
133+
histogram.record(20.0, &attributes);
134134

135135
let expected = vec![
136136
r#"http_server_duration_bucket{http_host="server",http_method="GET",service_name="Test Service",le="+Inf"} 4"#,

opentelemetry/benches/ddsketch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn ddsketch(data: Vec<f64>) {
2323
"test".to_string(),
2424
"test",
2525
None,
26-
InstrumentKind::ValueRecorder,
26+
InstrumentKind::Histogram,
2727
NumberKind::F64,
2828
);
2929
for f in data {
@@ -44,7 +44,7 @@ fn array(data: Vec<f64>) {
4444
"test".to_string(),
4545
"test",
4646
None,
47-
InstrumentKind::ValueRecorder,
47+
InstrumentKind::Histogram,
4848
NumberKind::F64,
4949
);
5050
for f in data {

0 commit comments

Comments
 (0)