Skip to content

Commit d8a2ce6

Browse files
authored
Merge branch 'main' into cijothomas/utkarsh-maintainer
2 parents fa4036b + a7de955 commit d8a2ce6

File tree

27 files changed

+109
-87
lines changed

27 files changed

+109
-87
lines changed

examples/metrics-advanced/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
7777
.f64_histogram("my_histogram")
7878
.with_unit("ms")
7979
.with_description("My histogram example description")
80-
.init();
80+
.build();
8181

8282
// Record measurements using the histogram instrument.
8383
histogram.record(
@@ -91,7 +91,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
9191
);
9292

9393
// Example 2 - Drop unwanted attributes using view.
94-
let counter = meter.u64_counter("my_counter").init();
94+
let counter = meter.u64_counter("my_counter").build();
9595

9696
// Record measurements using the Counter instrument.
9797
// Though we are passing 4 attributes here, only 1 will be used
@@ -115,7 +115,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
115115
.f64_histogram("my_second_histogram")
116116
.with_unit("ms")
117117
.with_description("My histogram example description")
118-
.init();
118+
.build();
119119

120120
// Record measurements using the histogram instrument.
121121
// The values recorded are in the range of 1.2 to 1.5, warranting

examples/metrics-basic/src/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
3131
let meter = global::meter("mylibraryname");
3232

3333
// Create a Counter Instrument.
34-
let counter = meter.u64_counter("my_counter").init();
34+
let counter = meter.u64_counter("my_counter").build();
3535

3636
// Record measurements using the Counter instrument.
3737
counter.add(
@@ -56,10 +56,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
5656
],
5757
)
5858
})
59-
.init();
59+
.build();
6060

6161
// Create a UpCounter Instrument.
62-
let updown_counter = meter.i64_up_down_counter("my_updown_counter").init();
62+
let updown_counter = meter.i64_up_down_counter("my_updown_counter").build();
6363

6464
// Record measurements using the UpCounter instrument.
6565
updown_counter.add(
@@ -84,7 +84,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
8484
],
8585
)
8686
})
87-
.init();
87+
.build();
8888

8989
// Create a Histogram Instrument.
9090
let histogram = meter
@@ -93,7 +93,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
9393
// Setting boundaries is optional. By default, the boundaries are set to
9494
// [0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 750.0, 1000.0, 2500.0, 5000.0, 7500.0, 10000.0]
9595
.with_boundaries(vec![0.0, 5.0, 10.0, 15.0, 20.0, 25.0])
96-
.init();
96+
.build();
9797

9898
// Record measurements using the histogram instrument.
9999
histogram.record(
@@ -111,7 +111,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
111111
.f64_gauge("my_gauge")
112112
.with_description("A gauge set to 1.0")
113113
.with_unit("myunit")
114-
.init();
114+
.build();
115115

116116
gauge.record(
117117
1.0,
@@ -135,7 +135,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
135135
],
136136
)
137137
})
138-
.init();
138+
.build();
139139

140140
// Metrics are exported by default every 30 seconds when using stdout exporter,
141141
// however shutting down the MeterProvider here instantly flushes

examples/self-diagnostics/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
137137
// Create a meter from the above MeterProvider.
138138
let meter = global::meter("example");
139139
// Create a Counter Instrument.
140-
let counter = meter.u64_counter("my_counter").init();
140+
let counter = meter.u64_counter("my_counter").build();
141141

142142
// Record measurements with unique key-value pairs to exceed the cardinality limit
143143
// of 2000 and trigger error message

opentelemetry-otlp/examples/basic-otlp-http/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
136136
.u64_counter("test_counter")
137137
.with_description("a simple counter for demo purposes.")
138138
.with_unit("my_unit")
139-
.init();
139+
.build();
140140
for _ in 0..10 {
141141
counter.add(1, &[KeyValue::new("test_key", "test_value")]);
142142
}

opentelemetry-otlp/examples/basic-otlp/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
127127
.u64_counter("test_counter")
128128
.with_description("a simple counter for demo purposes.")
129129
.with_unit("my_unit")
130-
.init();
130+
.build();
131131
for _ in 0..10 {
132132
counter.add(1, &[KeyValue::new("test_key", "test_value")]);
133133
}

opentelemetry-sdk/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
- **BREAKING**: [#2217](https://github.com/open-telemetry/opentelemetry-rust/pull/2217)
99
- **Replaced**: Removed `{Delta,Cumulative}TemporalitySelector::new()` in favor of directly using `Temporality` enum to simplify the configuration of MetricExporterBuilder with different temporalities.
1010
- When creating new metric instruments, SDK would return a no-op instrument if the validation fails. [#2166](https://github.com/open-telemetry/opentelemetry-rust/pull/2166)
11+
- **Breaking change for Metrics users:** The `init` method used to create instruments has been renamed to `build`.
12+
13+
Before:
14+
```rust
15+
let counter = meter.u64_counter("my_counter").init();
16+
```
17+
18+
Now:
19+
```rust
20+
let counter = meter.u64_counter("my_counter").build();
21+
```
1122

1223
## v0.26.0
1324
Released 2024-Sep-30

opentelemetry-sdk/benches/metric.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ fn bench_counter(view: Option<Box<dyn View>>, temporality: &str) -> (SharedReade
125125
builder = builder.with_view(view);
126126
}
127127
let provider = builder.build();
128-
let cntr = provider.meter("test").u64_counter("hello").init();
128+
let cntr = provider.meter("test").u64_counter("hello").build();
129129

130130
(rdr, cntr)
131131
}
@@ -344,7 +344,7 @@ fn bench_histogram(bound_count: usize) -> (SharedReader, Histogram<u64>) {
344344
let mtr = builder.build().meter("test_meter");
345345
let hist = mtr
346346
.u64_histogram(format!("histogram_{}", bound_count))
347-
.init();
347+
.build();
348348

349349
(r, hist)
350350
}
@@ -384,7 +384,7 @@ fn benchmark_collect_histogram(b: &mut Bencher, n: usize) {
384384
.meter("sdk/metric/bench/histogram");
385385

386386
for i in 0..n {
387-
let h = mtr.u64_histogram(format!("fake_data_{i}")).init();
387+
let h = mtr.u64_histogram(format!("fake_data_{i}")).build();
388388
h.record(1, &[]);
389389
}
390390

opentelemetry-sdk/benches/metrics_counter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn create_counter(name: &'static str) -> Counter<u64> {
4444
let meter = meter_provider.meter("benchmarks");
4545

4646
println!("Counter_Created");
47-
meter.u64_counter(name).init()
47+
meter.u64_counter(name).build()
4848
}
4949

5050
fn criterion_benchmark(c: &mut Criterion) {

opentelemetry-sdk/benches/metrics_gauge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn create_gauge() -> Gauge<u64> {
3939
.build();
4040
let meter = meter_provider.meter("benchmarks");
4141

42-
meter.u64_gauge("gauge_bench").init()
42+
meter.u64_gauge("gauge_bench").build()
4343
}
4444

4545
fn criterion_benchmark(c: &mut Criterion) {

opentelemetry-sdk/benches/metrics_histogram.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn create_histogram(name: &'static str) -> Histogram<u64> {
4242
.build();
4343
let meter = meter_provider.meter("benchmarks");
4444

45-
meter.u64_histogram(name).init()
45+
meter.u64_histogram(name).build()
4646
}
4747

4848
fn criterion_benchmark(c: &mut Criterion) {

0 commit comments

Comments
 (0)