From 9958cbeef2ab95a7b901126765660b757650a3bd Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 23 May 2025 10:38:04 -0700 Subject: [PATCH] chore: Nit fixes to examples --- examples/metrics-advanced/README.md | 3 --- examples/metrics-advanced/src/main.rs | 24 ++++++++++++++++-------- examples/metrics-basic/README.md | 3 --- examples/metrics-basic/src/main.rs | 4 ++-- opentelemetry-otlp/Cargo.toml | 3 +-- opentelemetry-stdout/Cargo.toml | 2 +- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/examples/metrics-advanced/README.md b/examples/metrics-advanced/README.md index 1d0cc42e01..624e1735b7 100644 --- a/examples/metrics-advanced/README.md +++ b/examples/metrics-advanced/README.md @@ -12,6 +12,3 @@ Run the following, and the Metrics will be written out to stdout. ```shell $ cargo run ``` - - - diff --git a/examples/metrics-advanced/src/main.rs b/examples/metrics-advanced/src/main.rs index 104e75b501..41861e7f27 100644 --- a/examples/metrics-advanced/src/main.rs +++ b/examples/metrics-advanced/src/main.rs @@ -85,15 +85,23 @@ async fn main() -> Result<(), Box> { .with_description("My histogram example description") .build(); - // Record measurements using the histogram instrument. - // This metric will have a cardinality limit of 2, - // as set in the view. Because of this, only the first two - // measurements will be recorded, and the rest will be folded - // into the overflow attribute. + // Record measurements using the histogram instrument. This metric will have + // a cardinality limit of 2, as set in the view. Because of this, only the + // first two distinct attribute combinations will be recorded, and the rest + // will be folded into the overflow attribute. Any number of measurements + // can be recorded as long as they use the same or already-seen attribute + // combinations. histogram2.record(1.5, &[KeyValue::new("mykey1", "v1")]); - histogram2.record(1.2, &[KeyValue::new("mykey1", "v2")]); + // Repeatedly emitting measurements for "v1" and "v2" will not + // trigger overflow, as they are already seen attribute combinations. + histogram2.record(1.7, &[KeyValue::new("mykey1", "v1")]); + histogram2.record(1.8, &[KeyValue::new("mykey1", "v2")]); + + // Emitting measurements for new attribute combinations will trigger + // overflow, as the cardinality limit of 2 has been reached. + // All the below measurements will be folded into the overflow attribute. histogram2.record(1.23, &[KeyValue::new("mykey1", "v3")]); histogram2.record(1.4, &[KeyValue::new("mykey1", "v4")]); @@ -104,9 +112,9 @@ async fn main() -> Result<(), Box> { histogram2.record(1.8, &[KeyValue::new("mykey1", "v7")]); - // Metrics are exported by default every 30 seconds when using stdout exporter, + // Metrics are exported by default every 60 seconds when using stdout exporter, // however shutting down the MeterProvider here instantly flushes - // the metrics, instead of waiting for the 30 sec interval. + // the metrics, instead of waiting for the 60 sec interval. meter_provider.shutdown()?; Ok(()) } diff --git a/examples/metrics-basic/README.md b/examples/metrics-basic/README.md index 3b3e04a0e3..61ed0601be 100644 --- a/examples/metrics-basic/README.md +++ b/examples/metrics-basic/README.md @@ -11,6 +11,3 @@ Run the following, and the Metrics will be written out to stdout. ```shell $ cargo run ``` - - - diff --git a/examples/metrics-basic/src/main.rs b/examples/metrics-basic/src/main.rs index 042c703c83..e02b045e1e 100644 --- a/examples/metrics-basic/src/main.rs +++ b/examples/metrics-basic/src/main.rs @@ -136,9 +136,9 @@ async fn main() -> Result<(), Box> { }) .build(); - // Metrics are exported by default every 30 seconds when using stdout + // Metrics are exported by default every 60 seconds when using stdout // exporter, however shutting down the MeterProvider here instantly flushes - // the metrics, instead of waiting for the 30 sec interval. Shutdown returns + // the metrics, instead of waiting for the 60 sec interval. Shutdown returns // a result, which is bubbled up to the caller The commented code below // demonstrates handling the shutdown result, instead of bubbling up the // error. diff --git a/opentelemetry-otlp/Cargo.toml b/opentelemetry-otlp/Cargo.toml index ac37c68523..9987d233a8 100644 --- a/opentelemetry-otlp/Cargo.toml +++ b/opentelemetry-otlp/Cargo.toml @@ -45,8 +45,7 @@ serde_json = { workspace = true, optional = true } [dev-dependencies] tokio-stream = { workspace = true, features = ["net"] } -# need tokio runtime to run smoke tests. -opentelemetry_sdk = { features = ["trace", "rt-tokio", "testing"], path = "../opentelemetry-sdk" } +opentelemetry_sdk = { features = ["trace", "testing"], path = "../opentelemetry-sdk" } tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } futures-util = { workspace = true } temp-env = { workspace = true } diff --git a/opentelemetry-stdout/Cargo.toml b/opentelemetry-stdout/Cargo.toml index 484f691c93..305bd0eb51 100644 --- a/opentelemetry-stdout/Cargo.toml +++ b/opentelemetry-stdout/Cargo.toml @@ -33,7 +33,7 @@ opentelemetry_sdk = { version = "0.30", path = "../opentelemetry-sdk" } [dev-dependencies] opentelemetry = { path = "../opentelemetry", features = ["metrics"] } -opentelemetry_sdk = { path = "../opentelemetry-sdk", features = ["rt-tokio", "metrics"] } +opentelemetry_sdk = { path = "../opentelemetry-sdk", features = ["metrics"] } opentelemetry-appender-tracing = { workspace = true } tracing = { workspace = true, features = ["std"]} tracing-subscriber = { workspace = true, features = ["registry", "std"] }