Skip to content

Commit 6a48989

Browse files
committed
keep lifetime and store ref
1 parent 4327789 commit 6a48989

File tree

6 files changed

+42
-33
lines changed

6 files changed

+42
-33
lines changed

opentelemetry/src/metrics/instruments/counter.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@ impl<T> Counter<T> {
3737
}
3838
}
3939

40-
impl TryFrom<InstrumentBuilder<Counter<u64>>> for Counter<u64> {
40+
impl TryFrom<InstrumentBuilder<'_, Counter<u64>>> for Counter<u64> {
4141
type Error = MetricsError;
4242

43-
fn try_from(builder: InstrumentBuilder<Counter<u64>>) -> Result<Self, Self::Error> {
43+
fn try_from(builder: InstrumentBuilder<'_, Counter<u64>>) -> Result<Self, Self::Error> {
4444
builder
4545
.instrument_provider
4646
.u64_counter(builder.name, builder.description, builder.unit)
4747
}
4848
}
4949

50-
impl TryFrom<InstrumentBuilder<Counter<f64>>> for Counter<f64> {
50+
impl TryFrom<InstrumentBuilder<'_, Counter<f64>>> for Counter<f64> {
5151
type Error = MetricsError;
5252

53-
fn try_from(builder: InstrumentBuilder<Counter<f64>>) -> Result<Self, Self::Error> {
53+
fn try_from(builder: InstrumentBuilder<'_, Counter<f64>>) -> Result<Self, Self::Error> {
5454
builder
5555
.instrument_provider
5656
.f64_counter(builder.name, builder.description, builder.unit)

opentelemetry/src/metrics/instruments/gauge.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,30 @@ impl<T> Gauge<T> {
3737
}
3838
}
3939

40-
impl TryFrom<InstrumentBuilder<Gauge<u64>>> for Gauge<u64> {
40+
impl TryFrom<InstrumentBuilder<'_, Gauge<u64>>> for Gauge<u64> {
4141
type Error = MetricsError;
4242

43-
fn try_from(builder: InstrumentBuilder<Gauge<u64>>) -> Result<Self, Self::Error> {
43+
fn try_from(builder: InstrumentBuilder<'_, Gauge<u64>>) -> Result<Self, Self::Error> {
4444
builder
4545
.instrument_provider
4646
.u64_gauge(builder.name, builder.description, builder.unit)
4747
}
4848
}
4949

50-
impl TryFrom<InstrumentBuilder<Gauge<f64>>> for Gauge<f64> {
50+
impl TryFrom<InstrumentBuilder<'_, Gauge<f64>>> for Gauge<f64> {
5151
type Error = MetricsError;
5252

53-
fn try_from(builder: InstrumentBuilder<Gauge<f64>>) -> Result<Self, Self::Error> {
53+
fn try_from(builder: InstrumentBuilder<'_, Gauge<f64>>) -> Result<Self, Self::Error> {
5454
builder
5555
.instrument_provider
5656
.f64_gauge(builder.name, builder.description, builder.unit)
5757
}
5858
}
5959

60-
impl TryFrom<InstrumentBuilder<Gauge<i64>>> for Gauge<i64> {
60+
impl TryFrom<InstrumentBuilder<'_, Gauge<i64>>> for Gauge<i64> {
6161
type Error = MetricsError;
6262

63-
fn try_from(builder: InstrumentBuilder<Gauge<i64>>) -> Result<Self, Self::Error> {
63+
fn try_from(builder: InstrumentBuilder<'_, Gauge<i64>>) -> Result<Self, Self::Error> {
6464
builder
6565
.instrument_provider
6666
.i64_gauge(builder.name, builder.description, builder.unit)

opentelemetry/src/metrics/instruments/histogram.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ impl<T> Histogram<T> {
3636
}
3737
}
3838

39-
impl TryFrom<InstrumentBuilder<Histogram<f64>>> for Histogram<f64> {
39+
impl TryFrom<InstrumentBuilder<'_, Histogram<f64>>> for Histogram<f64> {
4040
type Error = MetricsError;
4141

42-
fn try_from(builder: InstrumentBuilder<Histogram<f64>>) -> Result<Self, Self::Error> {
42+
fn try_from(builder: InstrumentBuilder<'_, Histogram<f64>>) -> Result<Self, Self::Error> {
4343
builder
4444
.instrument_provider
4545
.f64_histogram(builder.name, builder.description, builder.unit)
4646
}
4747
}
4848

49-
impl TryFrom<InstrumentBuilder<Histogram<u64>>> for Histogram<u64> {
49+
impl TryFrom<InstrumentBuilder<'_, Histogram<u64>>> for Histogram<u64> {
5050
type Error = MetricsError;
5151

52-
fn try_from(builder: InstrumentBuilder<Histogram<u64>>) -> Result<Self, Self::Error> {
52+
fn try_from(builder: InstrumentBuilder<'_, Histogram<u64>>) -> Result<Self, Self::Error> {
5353
builder
5454
.instrument_provider
5555
.u64_histogram(builder.name, builder.description, builder.unit)

opentelemetry/src/metrics/instruments/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ pub trait AsyncInstrument<T>: Send + Sync {
2525
}
2626

2727
/// Configuration for building a sync instrument.
28-
pub struct InstrumentBuilder<T> {
29-
instrument_provider: Arc<dyn InstrumentProvider + Send + Sync>,
28+
pub struct InstrumentBuilder<'a, T> {
29+
instrument_provider: &'a dyn InstrumentProvider,
3030
name: Cow<'static, str>,
3131
description: Option<Cow<'static, str>>,
3232
unit: Option<Unit>,
3333
_marker: marker::PhantomData<T>,
3434
}
3535

36-
impl<T> InstrumentBuilder<T>
36+
impl<'a, T> InstrumentBuilder<'a, T>
3737
where
3838
T: TryFrom<Self, Error = MetricsError>,
3939
{
4040
/// Create a new instrument builder
41-
pub(crate) fn new(meter: &Meter, name: Cow<'static, str>) -> Self {
41+
pub(crate) fn new(meter: &'a Meter, name: Cow<'static, str>) -> Self {
4242
InstrumentBuilder {
43-
instrument_provider: meter.instrument_provider.clone(),
43+
instrument_provider: meter.instrument_provider.as_ref(),
4444
name,
4545
description: None,
4646
unit: None,
@@ -84,7 +84,7 @@ where
8484
}
8585
}
8686

87-
impl<T> fmt::Debug for InstrumentBuilder<T> {
87+
impl<T> fmt::Debug for InstrumentBuilder<'_, T> {
8888
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8989
f.debug_struct("InstrumentBuilder")
9090
.field("name", &self.name)

opentelemetry/src/metrics/instruments/up_down_counter.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ impl<T> UpDownCounter<T> {
4242
}
4343
}
4444

45-
impl TryFrom<InstrumentBuilder<UpDownCounter<i64>>> for UpDownCounter<i64> {
45+
impl TryFrom<InstrumentBuilder<'_, UpDownCounter<i64>>> for UpDownCounter<i64> {
4646
type Error = MetricsError;
4747

48-
fn try_from(builder: InstrumentBuilder<UpDownCounter<i64>>) -> Result<Self, Self::Error> {
48+
fn try_from(builder: InstrumentBuilder<'_, UpDownCounter<i64>>) -> Result<Self, Self::Error> {
4949
builder.instrument_provider.i64_up_down_counter(
5050
builder.name,
5151
builder.description,
@@ -54,10 +54,10 @@ impl TryFrom<InstrumentBuilder<UpDownCounter<i64>>> for UpDownCounter<i64> {
5454
}
5555
}
5656

57-
impl TryFrom<InstrumentBuilder<UpDownCounter<f64>>> for UpDownCounter<f64> {
57+
impl TryFrom<InstrumentBuilder<'_, UpDownCounter<f64>>> for UpDownCounter<f64> {
5858
type Error = MetricsError;
5959

60-
fn try_from(builder: InstrumentBuilder<UpDownCounter<f64>>) -> Result<Self, Self::Error> {
60+
fn try_from(builder: InstrumentBuilder<'_, UpDownCounter<f64>>) -> Result<Self, Self::Error> {
6161
builder.instrument_provider.f64_up_down_counter(
6262
builder.name,
6363
builder.description,

opentelemetry/src/metrics/meter.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,15 @@ impl Meter {
273273
pub fn u64_counter(
274274
&self,
275275
name: impl Into<Cow<'static, str>>,
276-
) -> InstrumentBuilder<Counter<u64>> {
276+
) -> InstrumentBuilder<'_, Counter<u64>> {
277277
InstrumentBuilder::new(self, name.into())
278278
}
279279

280280
/// creates an instrument builder for recording increasing values.
281281
pub fn f64_counter(
282282
&self,
283283
name: impl Into<Cow<'static, str>>,
284-
) -> InstrumentBuilder<Counter<f64>> {
284+
) -> InstrumentBuilder<'_, Counter<f64>> {
285285
InstrumentBuilder::new(self, name.into())
286286
}
287287

@@ -305,15 +305,15 @@ impl Meter {
305305
pub fn i64_up_down_counter(
306306
&self,
307307
name: impl Into<Cow<'static, str>>,
308-
) -> InstrumentBuilder<UpDownCounter<i64>> {
308+
) -> InstrumentBuilder<'_, UpDownCounter<i64>> {
309309
InstrumentBuilder::new(self, name.into())
310310
}
311311

312312
/// creates an instrument builder for recording changes of a value.
313313
pub fn f64_up_down_counter(
314314
&self,
315315
name: impl Into<Cow<'static, str>>,
316-
) -> InstrumentBuilder<UpDownCounter<f64>> {
316+
) -> InstrumentBuilder<'_, UpDownCounter<f64>> {
317317
InstrumentBuilder::new(self, name.into())
318318
}
319319

@@ -334,17 +334,26 @@ impl Meter {
334334
}
335335

336336
/// creates an instrument builder for recording independent values.
337-
pub fn u64_gauge(&self, name: impl Into<Cow<'static, str>>) -> InstrumentBuilder<Gauge<u64>> {
337+
pub fn u64_gauge(
338+
&self,
339+
name: impl Into<Cow<'static, str>>,
340+
) -> InstrumentBuilder<'_, Gauge<u64>> {
338341
InstrumentBuilder::new(self, name.into())
339342
}
340343

341344
/// creates an instrument builder for recording independent values.
342-
pub fn f64_gauge(&self, name: impl Into<Cow<'static, str>>) -> InstrumentBuilder<Gauge<f64>> {
345+
pub fn f64_gauge(
346+
&self,
347+
name: impl Into<Cow<'static, str>>,
348+
) -> InstrumentBuilder<'_, Gauge<f64>> {
343349
InstrumentBuilder::new(self, name.into())
344350
}
345351

346352
/// creates an instrument builder for recording independent values.
347-
pub fn i64_gauge(&self, name: impl Into<Cow<'static, str>>) -> InstrumentBuilder<Gauge<i64>> {
353+
pub fn i64_gauge(
354+
&self,
355+
name: impl Into<Cow<'static, str>>,
356+
) -> InstrumentBuilder<'_, Gauge<i64>> {
348357
InstrumentBuilder::new(self, name.into())
349358
}
350359

@@ -376,15 +385,15 @@ impl Meter {
376385
pub fn f64_histogram(
377386
&self,
378387
name: impl Into<Cow<'static, str>>,
379-
) -> InstrumentBuilder<Histogram<f64>> {
388+
) -> InstrumentBuilder<'_, Histogram<f64>> {
380389
InstrumentBuilder::new(self, name.into())
381390
}
382391

383392
/// creates an instrument builder for recording a distribution of values.
384393
pub fn u64_histogram(
385394
&self,
386395
name: impl Into<Cow<'static, str>>,
387-
) -> InstrumentBuilder<Histogram<u64>> {
396+
) -> InstrumentBuilder<'_, Histogram<u64>> {
388397
InstrumentBuilder::new(self, name.into())
389398
}
390399

0 commit comments

Comments
 (0)