Skip to content

Commit 8882c31

Browse files
authored
chore: Nit fixes to examples (#3002)
1 parent c811cde commit 8882c31

File tree

6 files changed

+20
-19
lines changed

6 files changed

+20
-19
lines changed

examples/metrics-advanced/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,3 @@ Run the following, and the Metrics will be written out to stdout.
1212
```shell
1313
$ cargo run
1414
```
15-
16-
17-

examples/metrics-advanced/src/main.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,23 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
8585
.with_description("My histogram example description")
8686
.build();
8787

88-
// Record measurements using the histogram instrument.
89-
// This metric will have a cardinality limit of 2,
90-
// as set in the view. Because of this, only the first two
91-
// measurements will be recorded, and the rest will be folded
92-
// into the overflow attribute.
88+
// Record measurements using the histogram instrument. This metric will have
89+
// a cardinality limit of 2, as set in the view. Because of this, only the
90+
// first two distinct attribute combinations will be recorded, and the rest
91+
// will be folded into the overflow attribute. Any number of measurements
92+
// can be recorded as long as they use the same or already-seen attribute
93+
// combinations.
9394
histogram2.record(1.5, &[KeyValue::new("mykey1", "v1")]);
94-
9595
histogram2.record(1.2, &[KeyValue::new("mykey1", "v2")]);
9696

97+
// Repeatedly emitting measurements for "v1" and "v2" will not
98+
// trigger overflow, as they are already seen attribute combinations.
99+
histogram2.record(1.7, &[KeyValue::new("mykey1", "v1")]);
100+
histogram2.record(1.8, &[KeyValue::new("mykey1", "v2")]);
101+
102+
// Emitting measurements for new attribute combinations will trigger
103+
// overflow, as the cardinality limit of 2 has been reached.
104+
// All the below measurements will be folded into the overflow attribute.
97105
histogram2.record(1.23, &[KeyValue::new("mykey1", "v3")]);
98106

99107
histogram2.record(1.4, &[KeyValue::new("mykey1", "v4")]);
@@ -104,9 +112,9 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
104112

105113
histogram2.record(1.8, &[KeyValue::new("mykey1", "v7")]);
106114

107-
// Metrics are exported by default every 30 seconds when using stdout exporter,
115+
// Metrics are exported by default every 60 seconds when using stdout exporter,
108116
// however shutting down the MeterProvider here instantly flushes
109-
// the metrics, instead of waiting for the 30 sec interval.
117+
// the metrics, instead of waiting for the 60 sec interval.
110118
meter_provider.shutdown()?;
111119
Ok(())
112120
}

examples/metrics-basic/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,3 @@ Run the following, and the Metrics will be written out to stdout.
1111
```shell
1212
$ cargo run
1313
```
14-
15-
16-

examples/metrics-basic/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
136136
})
137137
.build();
138138

139-
// Metrics are exported by default every 30 seconds when using stdout
139+
// Metrics are exported by default every 60 seconds when using stdout
140140
// exporter, however shutting down the MeterProvider here instantly flushes
141-
// the metrics, instead of waiting for the 30 sec interval. Shutdown returns
141+
// the metrics, instead of waiting for the 60 sec interval. Shutdown returns
142142
// a result, which is bubbled up to the caller The commented code below
143143
// demonstrates handling the shutdown result, instead of bubbling up the
144144
// error.

opentelemetry-otlp/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ serde_json = { workspace = true, optional = true }
4545

4646
[dev-dependencies]
4747
tokio-stream = { workspace = true, features = ["net"] }
48-
# need tokio runtime to run smoke tests.
49-
opentelemetry_sdk = { features = ["trace", "rt-tokio", "testing"], path = "../opentelemetry-sdk" }
48+
opentelemetry_sdk = { features = ["trace", "testing"], path = "../opentelemetry-sdk" }
5049
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
5150
futures-util = { workspace = true }
5251
temp-env = { workspace = true }

opentelemetry-stdout/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ opentelemetry_sdk = { version = "0.30", path = "../opentelemetry-sdk" }
3333

3434
[dev-dependencies]
3535
opentelemetry = { path = "../opentelemetry", features = ["metrics"] }
36-
opentelemetry_sdk = { path = "../opentelemetry-sdk", features = ["rt-tokio", "metrics"] }
36+
opentelemetry_sdk = { path = "../opentelemetry-sdk", features = ["metrics"] }
3737
opentelemetry-appender-tracing = { workspace = true }
3838
tracing = { workspace = true, features = ["std"]}
3939
tracing-subscriber = { workspace = true, features = ["registry", "std"] }

0 commit comments

Comments
 (0)