Skip to content
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
6 changes: 3 additions & 3 deletions examples/metrics-advanced/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
.f64_histogram("my_histogram")
.with_unit("ms")
.with_description("My histogram example description")
.init();
.build();

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

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

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

// Record measurements using the histogram instrument.
// The values recorded are in the range of 1.2 to 1.5, warranting
Expand Down
14 changes: 7 additions & 7 deletions examples/metrics-basic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let meter = global::meter("mylibraryname");

// Create a Counter Instrument.
let counter = meter.u64_counter("my_counter").init();
let counter = meter.u64_counter("my_counter").build();

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

// Create a UpCounter Instrument.
let updown_counter = meter.i64_up_down_counter("my_updown_counter").init();
let updown_counter = meter.i64_up_down_counter("my_updown_counter").build();

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

// Create a Histogram Instrument.
let histogram = meter
Expand All @@ -93,7 +93,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
// Setting boundaries is optional. By default, the boundaries are set to
// [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]
.with_boundaries(vec![0.0, 5.0, 10.0, 15.0, 20.0, 25.0])
.init();
.build();

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

gauge.record(
1.0,
Expand All @@ -135,7 +135,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
],
)
})
.init();
.build();

// Metrics are exported by default every 30 seconds when using stdout exporter,
// however shutting down the MeterProvider here instantly flushes
Expand Down
2 changes: 1 addition & 1 deletion examples/self-diagnostics/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
// Create a meter from the above MeterProvider.
let meter = global::meter("example");
// Create a Counter Instrument.
let counter = meter.u64_counter("my_counter").init();
let counter = meter.u64_counter("my_counter").build();

// Record measurements with unique key-value pairs to exceed the cardinality limit
// of 2000 and trigger error message
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-otlp/examples/basic-otlp-http/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
.u64_counter("test_counter")
.with_description("a simple counter for demo purposes.")
.with_unit("my_unit")
.init();
.build();
for _ in 0..10 {
counter.add(1, &[KeyValue::new("test_key", "test_value")]);
}
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-otlp/examples/basic-otlp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
.u64_counter("test_counter")
.with_description("a simple counter for demo purposes.")
.with_unit("my_unit")
.init();
.build();
for _ in 0..10 {
counter.add(1, &[KeyValue::new("test_key", "test_value")]);
}
Expand Down
11 changes: 11 additions & 0 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
- **BREAKING**: [#2217](https://github.com/open-telemetry/opentelemetry-rust/pull/2217)
- **Replaced**: Removed `{Delta,Cumulative}TemporalitySelector::new()` in favor of directly using `Temporality` enum to simplify the configuration of MetricExporterBuilder with different temporalities.
- 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)
- **Breaking change for Metrics users:** The `init` method used to create instruments has been renamed to `build`.

Before:
```rust
let counter = meter.u64_counter("my_counter").init();
```

Now:
```rust
let counter = meter.u64_counter("my_counter").build();
```

## v0.26.0
Released 2024-Sep-30
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-sdk/benches/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn bench_counter(view: Option<Box<dyn View>>, temporality: &str) -> (SharedReade
builder = builder.with_view(view);
}
let provider = builder.build();
let cntr = provider.meter("test").u64_counter("hello").init();
let cntr = provider.meter("test").u64_counter("hello").build();

(rdr, cntr)
}
Expand Down Expand Up @@ -344,7 +344,7 @@ fn bench_histogram(bound_count: usize) -> (SharedReader, Histogram<u64>) {
let mtr = builder.build().meter("test_meter");
let hist = mtr
.u64_histogram(format!("histogram_{}", bound_count))
.init();
.build();

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

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

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/benches/metrics_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn create_counter(name: &'static str) -> Counter<u64> {
let meter = meter_provider.meter("benchmarks");

println!("Counter_Created");
meter.u64_counter(name).init()
meter.u64_counter(name).build()
}

fn criterion_benchmark(c: &mut Criterion) {
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/benches/metrics_gauge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn create_gauge() -> Gauge<u64> {
.build();
let meter = meter_provider.meter("benchmarks");

meter.u64_gauge("gauge_bench").init()
meter.u64_gauge("gauge_bench").build()
}

fn criterion_benchmark(c: &mut Criterion) {
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/benches/metrics_histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn create_histogram(name: &'static str) -> Histogram<u64> {
.build();
let meter = meter_provider.meter("benchmarks");

meter.u64_histogram(name).init()
meter.u64_histogram(name).build()
}

fn criterion_benchmark(c: &mut Criterion) {
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
//! let meter = global::meter("my_service");
//!
//! // create an instrument
//! let counter = meter.u64_counter("my_counter").init();
//! let counter = meter.u64_counter("my_counter").build();
//!
//! // record a measurement
//! counter.add(1, &[KeyValue::new("http.client_ip", "83.164.160.102")]);
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/metrics/meter_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ mod tests {
assert!(!reader.is_shutdown());
// create a meter and an instrument
let meter = global::meter("test");
let counter = meter.u64_counter("test_counter").init();
let counter = meter.u64_counter("test_counter").build();
// no need to drop a meter for meter_provider shutdown
let shutdown_res = provider.shutdown();
assert!(shutdown_res.is_ok());
Expand Down
Loading
Loading