Skip to content

Commit 796ac1a

Browse files
feat: Add #[must_use] to AsyncInstrumentBuilder (#3246)
Co-authored-by: Cijo Thomas <[email protected]> Co-authored-by: Cijo Thomas <[email protected]>
1 parent 70a548e commit 796ac1a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

opentelemetry/CHANGELOG.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- **Breaking** Removed the following public fields and methods from the `SpanBuilder` [#3227][3227]:
77
- `trace_id`, `span_id`, `end_time`, `status`, `sampling_result`
88
- `with_trace_id`, `with_span_id`, `with_end_time`, `with_status`, `with_sampling_result`
9+
- **Added** `#[must_use]` attribute to `opentelemetry::metrics::AsyncInstrumentBuilder` to add compile time warning when `.build()` is not called on observable instrument builders, preventing silent failures where callbacks are never registered and metrics are never reported.
910

1011
[3227]: https://github.com/open-telemetry/opentelemetry-rust/pull/3227
1112

@@ -117,10 +118,10 @@ let counter = meter.u64_counter("my_counter").build();
117118
- Replaced `global::meter_with_version` with `global::meter_with_scope`
118119
- Added `global::tracer_with_scope`
119120
- Refer to PR description for migration guide.
120-
- **Breaking change**: replaced `InstrumentationScope` public attributes by getters [#2275](https://github.com/open-telemetry/opentelemetry-rust/pull/2275)
121+
- **Breaking change**: replaced `InstrumentationScope` public attributes by getters [#2275](https://github.com/open-telemetry/opentelemetry-rust/pull/2275)
121122

122123
- **Breaking change**: [#2260](https://github.com/open-telemetry/opentelemetry-rust/pull/2260)
123-
- Removed `global::set_error_handler` and `global::handle_error`.
124+
- Removed `global::set_error_handler` and `global::handle_error`.
124125
- `global::handle_error` usage inside the opentelemetry crates has been replaced with `global::otel_info`, `otel_warn`, `otel_debug` and `otel_error` macros based on the severity of the internal logs.
125126
- The default behavior of `global::handle_error` was to log the error using `eprintln!`. With otel macros, the internal logs get emitted via `tracing` macros of matching severity. Users now need to configure a `tracing` layer/subscriber to capture these logs.
126127
- Refer to PR description for migration guide. Also refer to [self-diagnostics](https://github.com/open-telemetry/opentelemetry-rust/tree/main/examples/self-diagnostics) example to learn how to view internal logs in stdout using `tracing::fmt` layer.
@@ -220,7 +221,7 @@ to learn how to provide Observable callbacks.
220221
opaque string. Migration: Replace `.with_unit(Unit::new("myunit"))` with
221222
`.with_unit("myunit")`.
222223

223-
- [1869](https://github.com/open-telemetry/opentelemetry-rust/pull/1869) Introduced the `LogRecord::set_target()` method in the log bridge API.
224+
- [1869](https://github.com/open-telemetry/opentelemetry-rust/pull/1869) Introduced the `LogRecord::set_target()` method in the log bridge API.
224225
This method allows appenders to set the target/component emitting the logs.
225226

226227
## v0.23.0
@@ -241,7 +242,7 @@ This method allows appenders to set the target/component emitting the logs.
241242
- opentelemetry::global::shutdown_logger_provider
242243
- opentelemetry::global::logger_provider
243244
- opentelemetry::global::GlobalLoggerProvider
244-
- opentelemetry::global::ObjectSafeLoggerProvider
245+
- opentelemetry::global::ObjectSafeLoggerProvider
245246
For creating appenders using Logging bridge API, refer to the opentelemetry-tracing-appender [example](https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-appender-tracing/examples/basic.rs)
246247

247248
### Changed

opentelemetry/src/metrics/instruments/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ impl<T> fmt::Debug for HistogramBuilder<'_, T> {
241241
pub type Callback<T> = Box<dyn Fn(&dyn AsyncInstrument<T>) + Send + Sync>;
242242

243243
/// Configuration for building an async instrument.
244+
#[must_use = "Callbacks will not be invoked unless you call .build() on this async instrument builder."]
244245
#[non_exhaustive] // We expect to add more configuration fields in the future
245246
pub struct AsyncInstrumentBuilder<'a, I, M> {
246247
/// Instrument provider is used to create the instrument.

0 commit comments

Comments
 (0)