Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UserEvent Metric Exporter release 0.2.2 #35

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions opentelemetry-user-events-metrics/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-user-events-metrics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
144 changes: 110 additions & 34 deletions opentelemetry-user-events-metrics/examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,68 +28,113 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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();
Expand All @@ -98,44 +143,75 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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(),
],
)
})?;

loop {
// 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));
}
Expand Down
Loading