From c40c650babd0b8d52977b4d7906007d517902f5c Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Tue, 13 Feb 2024 22:32:17 -0800 Subject: [PATCH] UserEvent Metric Exporter release 0.2.2 (#35) --- .../CHANGELOG.md | 2 + opentelemetry-user-events-metrics/Cargo.toml | 2 +- .../examples/basic.rs | 144 +++++++++++++----- 3 files changed, 113 insertions(+), 35 deletions(-) diff --git a/opentelemetry-user-events-metrics/CHANGELOG.md b/opentelemetry-user-events-metrics/CHANGELOG.md index 056086ab..6fd578a0 100644 --- a/opentelemetry-user-events-metrics/CHANGELOG.md +++ b/opentelemetry-user-events-metrics/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +## v0.2.2 + - Fixed a bug which caused Histogram, Gauge metrics to be dropped. [#30](https://github.com/open-telemetry/opentelemetry-rust-contrib/pull/30). diff --git a/opentelemetry-user-events-metrics/Cargo.toml b/opentelemetry-user-events-metrics/Cargo.toml index 196588e8..3746322c 100644 --- a/opentelemetry-user-events-metrics/Cargo.toml +++ b/opentelemetry-user-events-metrics/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "opentelemetry-user-events-metrics" -version = "0.2.1" +version = "0.2.2" description = "OpenTelemetry metrics exporter to user events" homepage = "https://github.com/open-telemetry/opentelemetry-rust-contrib/tree/main/opentelemetry-user-events-metrics" repository = "https://github.com/open-telemetry/opentelemetry-rust-contrib/tree/main/opentelemetry-user-events-metrics" diff --git a/opentelemetry-user-events-metrics/examples/basic.rs b/opentelemetry-user-events-metrics/examples/basic.rs index 65501c4f..986eb0dd 100644 --- a/opentelemetry-user-events-metrics/examples/basic.rs +++ b/opentelemetry-user-events-metrics/examples/basic.rs @@ -28,68 +28,113 @@ async fn main() -> Result<(), Box> { let exporter = opentelemetry_user_events_metrics::MetricsExporter::new(); let meter_provider = init_metrics(exporter); - let meter = meter_provider.versioned_meter( - "user-event-test", - Some("test-version"), - Some("test_url"), - Some(vec![KeyValue::new("key", "value")]), - ); + let meter = meter_provider.meter("user-event-test"); + // Create a Counter Instrument. let counter = meter - .f64_counter("counter_test") + .f64_counter("counter_f64_test") .with_description("test_decription") .with_unit(Unit::new("test_unit")) .init(); - // Create a UpCounter Instrument. - let updown_counter = meter.i64_up_down_counter("up_down_counter_test").init(); + + let counter2 = meter + .u64_counter("counter_u64_test") + .with_description("test_decription") + .with_unit(Unit::new("test_unit")) + .init(); + + // Create an UpDownCounter Instrument. + let updown_counter = meter.i64_up_down_counter("up_down_counter_i64_test").init(); + let updown_counter2 = meter.f64_up_down_counter("up_down_counter_f64_test").init(); // Create a Histogram Instrument. let histogram = meter - .f64_histogram("histogram_test") + .f64_histogram("histogram_f64_test") + .with_description("test_description") + .init(); + let histogram2 = meter + .i64_histogram("histogram_i64_test") .with_description("test_description") .init(); // Create a ObservableGauge instrument and register a callback that reports the measurement. let gauge = meter - .f64_observable_gauge("gauge_test") + .f64_observable_gauge("observable_gauge_f64_test") + .with_unit(Unit::new("test_unit")) + .with_description("test_description") + .init(); + + let gauge2 = meter + .i64_observable_gauge("observable_gauge_i64_test") .with_unit(Unit::new("test_unit")) - .with_description("test_descriptionn") + .with_description("test_description") .init(); meter.register_callback(&[gauge.as_any()], move |observer| { observer.observe_f64( &gauge, 1.0, - [ + &[ KeyValue::new("mykey1", "myvalue1"), KeyValue::new("mykey2", "myvalue2"), - ] - .as_ref(), + ], + ) + })?; + + meter.register_callback(&[gauge2.as_any()], move |observer| { + observer.observe_i64( + &gauge2, + 1, + &[ + KeyValue::new("mykey1", "myvalue1"), + KeyValue::new("mykey2", "myvalue2"), + ], ) })?; // Create a ObservableCounter instrument and register a callback that reports the measurement. let observable_counter = meter - .u64_observable_counter("obs_counter_test") + .u64_observable_counter("observable_counter_u64_test") .with_description("test_description") - .with_unit(Unit::new("tesT_unit")) + .with_unit(Unit::new("test_unit")) + .init(); + + let observable_counter2 = meter + .f64_observable_counter("observable_counter_f64_test") + .with_description("test_description") + .with_unit(Unit::new("test_unit")) .init(); meter.register_callback(&[observable_counter.as_any()], move |observer| { observer.observe_u64( &observable_counter, 100, - [ + &[ KeyValue::new("mykey1", "myvalue1"), KeyValue::new("mykey2", "myvalue2"), - ] - .as_ref(), + ], + ) + })?; + + meter.register_callback(&[observable_counter2.as_any()], move |observer| { + observer.observe_f64( + &observable_counter2, + 100.0, + &[ + KeyValue::new("mykey1", "myvalue1"), + KeyValue::new("mykey2", "myvalue2"), + ], ) })?; // Create a Observable UpDownCounter instrument and register a callback that reports the measurement. let observable_up_down_counter = meter - .i64_observable_up_down_counter("obs_up_down_counter_test") + .i64_observable_up_down_counter("observable_up_down_counter_i64_test") + .with_description("test_description") + .with_unit(Unit::new("test_unit")) + .init(); + let observable_up_down_counter2 = meter + .f64_observable_up_down_counter("observable_up_down_counter_f64_test") .with_description("test_description") .with_unit(Unit::new("test_unit")) .init(); @@ -98,11 +143,21 @@ async fn main() -> Result<(), Box> { observer.observe_i64( &observable_up_down_counter, 100, - [ + &[ + KeyValue::new("mykey1", "myvalue1"), + KeyValue::new("mykey2", "myvalue2"), + ], + ) + })?; + + meter.register_callback(&[observable_up_down_counter2.as_any()], move |observer| { + observer.observe_f64( + &observable_up_down_counter2, + 100.0, + &[ KeyValue::new("mykey1", "myvalue1"), KeyValue::new("mykey2", "myvalue2"), - ] - .as_ref(), + ], ) })?; @@ -110,32 +165,53 @@ async fn main() -> Result<(), Box> { // Record measurements using the Counter instrument. counter.add( 1.0, - [ + &[ KeyValue::new("mykey1", "myvalue1"), KeyValue::new("mykey2", "myvalue2"), - ] - .as_ref(), + ], + ); + + counter2.add( + 1, + &[ + KeyValue::new("mykey1", "myvalue1"), + KeyValue::new("mykey2", "myvalue2"), + ], ); // Record measurements using the UpCounter instrument. updown_counter.add( - -10, - [ + 10, + &[ + KeyValue::new("mykey1", "myvalue1"), + KeyValue::new("mykey2", "myvalue2"), + ], + ); + + updown_counter2.add( + 10.0, + &[ KeyValue::new("mykey1", "myvalue1"), KeyValue::new("mykey2", "myvalue2"), - ] - .as_ref(), + ], ); // Record measurements using the histogram instrument. histogram.record( 10.5, - [ + &[ + KeyValue::new("mykey1", "myvalue1"), + KeyValue::new("mykey2", "myvalue2"), + ], + ); + histogram2.record( + 10, + &[ KeyValue::new("mykey1", "myvalue1"), KeyValue::new("mykey2", "myvalue2"), - ] - .as_ref(), + ], ); + // Sleep for 1 second thread::sleep(Duration::from_secs(1)); }