Skip to content

Commit

Permalink
Update AynshronousInstrumentBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
utpilla committed Oct 14, 2024
1 parent 3f5c230 commit 531ea49
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions opentelemetry-sdk/src/metrics/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl SdkMeter {

let observable = Arc::new(Observable::new(ms));

for callback in builder.callbacks {
if let Some(callback) = builder.callback {
let cb_inst = Arc::clone(&observable);
self.pipes
.register_callback(move || callback(cb_inst.as_ref()));
Expand Down Expand Up @@ -166,7 +166,7 @@ impl SdkMeter {

let observable = Arc::new(Observable::new(ms));

for callback in builder.callbacks {
if let Some(callback) = builder.callback {
let cb_inst = Arc::clone(&observable);
self.pipes
.register_callback(move || callback(cb_inst.as_ref()));
Expand Down Expand Up @@ -203,7 +203,7 @@ impl SdkMeter {

let observable = Arc::new(Observable::new(ms));

for callback in builder.callbacks {
if let Some(callback) = builder.callback {
let cb_inst = Arc::clone(&observable);
self.pipes
.register_callback(move || callback(cb_inst.as_ref()));
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry/src/metrics/instruments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ where
pub unit: Option<Cow<'static, str>>,

/// Callbacks to be called for this instrument.
pub callbacks: Vec<Callback<M>>,
pub callback: Option<Callback<M>>,

_inst: marker::PhantomData<I>,
}
Expand All @@ -275,7 +275,7 @@ where
description: None,
unit: None,
_inst: marker::PhantomData,
callbacks: Vec::new(),
callback: None,
}
}

Expand All @@ -302,7 +302,7 @@ where
where
F: Fn(&dyn AsyncInstrument<M>) + Send + Sync + 'static,
{
self.callbacks.push(Box::new(callback));
self.callback = Some(Box::new(callback));
self
}
}
Expand Down Expand Up @@ -354,7 +354,7 @@ where
.field("description", &self.description)
.field("unit", &self.unit)
.field("kind", &std::any::type_name::<I>())
.field("callbacks_len", &self.callbacks.len())
.field("has callback", &self.callback.is_some())

Check warning on line 357 in opentelemetry/src/metrics/instruments/mod.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry/src/metrics/instruments/mod.rs#L357

Added line #L357 was not covered by tests
.finish()
}
}

0 comments on commit 531ea49

Please sign in to comment.