Skip to content

Commit 2a2e4b1

Browse files
authored
Remove context from metrics force_flush (#1245)
1 parent b776b1e commit 2a2e4b1

File tree

10 files changed

+27
-29
lines changed

10 files changed

+27
-29
lines changed

opentelemetry-prometheus/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ use once_cell::sync::{Lazy, OnceCell};
9797
use opentelemetry::{
9898
global,
9999
metrics::{MetricsError, Result},
100-
Context, Key, Value,
100+
Key, Value,
101101
};
102102
use opentelemetry_sdk::{
103103
metrics::{
@@ -174,8 +174,8 @@ impl MetricReader for PrometheusExporter {
174174
self.reader.collect(rm)
175175
}
176176

177-
fn force_flush(&self, cx: &Context) -> Result<()> {
178-
self.reader.force_flush(cx)
177+
fn force_flush(&self) -> Result<()> {
178+
self.reader.force_flush()
179179
}
180180

181181
fn shutdown(&self) -> Result<()> {

opentelemetry-sdk/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
is now the API crate. [#1226](https://github.com/open-telemetry/opentelemetry-rust/pull/1226)
1414
- Add in memory span exporter [#1216](https://github.com/open-telemetry/opentelemetry-rust/pull/1216)
1515

16+
### Removed
17+
18+
- Remove context from Metric force_flush [#1245](https://github.com/open-telemetry/opentelemetry-rust/pull/1245)
19+
1620
## v0.20.0
1721

1822
### Added

opentelemetry-sdk/benches/metric.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::sync::{Arc, Weak};
44
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
55
use opentelemetry::{
66
metrics::{Counter, Histogram, MeterProvider as _, Result},
7-
Context, Key, KeyValue,
7+
Key, KeyValue,
88
};
99
use opentelemetry_sdk::{
1010
metrics::{
@@ -45,8 +45,8 @@ impl MetricReader for SharedReader {
4545
self.0.collect(rm)
4646
}
4747

48-
fn force_flush(&self, cx: &Context) -> Result<()> {
49-
self.0.force_flush(cx)
48+
fn force_flush(&self) -> Result<()> {
49+
self.0.force_flush()
5050
}
5151

5252
fn shutdown(&self) -> Result<()> {

opentelemetry-sdk/src/metrics/manual_reader.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::{
66
use opentelemetry::{
77
global,
88
metrics::{MetricsError, Result},
9-
Context,
109
};
1110

1211
use super::{
@@ -145,7 +144,7 @@ impl MetricReader for ManualReader {
145144
}
146145

147146
/// ForceFlush is a no-op, it always returns nil.
148-
fn force_flush(&self, _cx: &Context) -> Result<()> {
147+
fn force_flush(&self) -> Result<()> {
149148
Ok(())
150149
}
151150

opentelemetry-sdk/src/metrics/meter_provider.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99

1010
use opentelemetry::{
1111
metrics::{noop::NoopMeterCore, InstrumentProvider, Meter as ApiMeter, MetricsError, Result},
12-
Context, KeyValue,
12+
KeyValue,
1313
};
1414

1515
use crate::{instrumentation::Scope, Resource};
@@ -68,12 +68,11 @@ impl MeterProvider {
6868
///
6969
/// fn main() {
7070
/// let provider = init_metrics();
71-
/// let cx = Context::new();
7271
///
7372
/// // create instruments + record measurements
7473
///
7574
/// // force all instruments to flush
76-
/// provider.force_flush(&cx).unwrap();
75+
/// provider.force_flush().unwrap();
7776
///
7877
/// // record more measurements..
7978
///
@@ -83,8 +82,8 @@ impl MeterProvider {
8382
/// global::shutdown_meter_provider();
8483
/// }
8584
/// ```
86-
pub fn force_flush(&self, cx: &Context) -> Result<()> {
87-
self.pipes.force_flush(cx)
85+
pub fn force_flush(&self) -> Result<()> {
86+
self.pipes.force_flush()
8887
}
8988

9089
/// Shuts down the meter provider flushing all pending telemetry and releasing

opentelemetry-sdk/src/metrics/periodic_reader.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use futures_util::{
1414
use opentelemetry::{
1515
global,
1616
metrics::{MetricsError, Result},
17-
Context,
1817
};
1918

2019
use crate::runtime::Runtime;
@@ -345,7 +344,7 @@ impl MetricReader for PeriodicReader {
345344
}
346345
}
347346

348-
fn force_flush(&self, _cx: &Context) -> Result<()> {
347+
fn force_flush(&self) -> Result<()> {
349348
let mut inner = self.inner.lock()?;
350349
let (sender, receiver) = oneshot::channel();
351350
inner

opentelemetry-sdk/src/metrics/pipeline.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::{
88
use opentelemetry::{
99
global,
1010
metrics::{CallbackRegistration, MetricsError, Result, Unit},
11-
Context,
1211
};
1312

1413
use crate::{
@@ -103,8 +102,8 @@ impl Pipeline {
103102
}
104103

105104
/// Send accumulated telemetry
106-
fn force_flush(&self, cx: &Context) -> Result<()> {
107-
self.reader.force_flush(cx)
105+
fn force_flush(&self) -> Result<()> {
106+
self.reader.force_flush()
108107
}
109108

110109
/// Shut down pipeline
@@ -611,10 +610,10 @@ impl Pipelines {
611610
}
612611

613612
/// Force flush all pipelines
614-
pub(crate) fn force_flush(&self, cx: &Context) -> Result<()> {
613+
pub(crate) fn force_flush(&self) -> Result<()> {
615614
let mut errs = vec![];
616615
for pipeline in &self.0 {
617-
if let Err(err) = pipeline.force_flush(cx) {
616+
if let Err(err) = pipeline.force_flush() {
618617
errs.push(err);
619618
}
620619
}

opentelemetry-sdk/src/metrics/reader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Interfaces for reading and producing metrics
22
use std::{fmt, sync::Weak};
33

4-
use opentelemetry::{metrics::Result, Context};
4+
use opentelemetry::metrics::Result;
55

66
use super::{
77
aggregation::Aggregation,
@@ -49,7 +49,7 @@ pub trait MetricReader:
4949
///
5050
/// There is no guaranteed that all telemetry be flushed or all resources have
5151
/// been released on error.
52-
fn force_flush(&self, cx: &Context) -> Result<()>;
52+
fn force_flush(&self) -> Result<()>;
5353

5454
/// Flushes all metric measurements held in an export pipeline and releases any
5555
/// held computational resources.

opentelemetry-sdk/src/testing/metrics/in_memory_exporter.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use std::sync::{Arc, Mutex};
2828
///
2929
/// ```
3030
///# use opentelemetry_sdk::{metrics, runtime};
31-
///# use opentelemetry::{Context, KeyValue};
31+
///# use opentelemetry::{KeyValue};
3232
///# use opentelemetry::metrics::MeterProvider;
3333
///# use opentelemetry_sdk::testing::metrics::InMemoryMetricsExporter;
3434
///# use opentelemetry_sdk::metrics::PeriodicReader;
@@ -45,11 +45,10 @@ use std::sync::{Arc, Mutex};
4545
///
4646
/// // Create and record metrics using the MeterProvider
4747
/// let meter = meter_provider.meter(std::borrow::Cow::Borrowed("example"));
48-
/// let cx = Context::new();
4948
/// let counter = meter.u64_counter("my_counter").init();
5049
/// counter.add(1, &[KeyValue::new("key", "value")]);
5150
///
52-
/// meter_provider.force_flush(&cx).unwrap();
51+
/// meter_provider.force_flush().unwrap();
5352
///
5453
/// // Retrieve the finished metrics from the exporter
5554
/// let finished_metrics = exporter.get_finished_metrics().unwrap();

opentelemetry-sdk/src/testing/metrics/metric_reader.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::metrics::{
77
pipeline::Pipeline,
88
reader::{AggregationSelector, MetricProducer, MetricReader, TemporalitySelector},
99
};
10-
use opentelemetry::{metrics::Result, Context};
10+
use opentelemetry::metrics::Result;
1111

1212
#[derive(Debug)]
1313
pub struct TestMetricReader {}
@@ -21,13 +21,12 @@ impl MetricReader for TestMetricReader {
2121
Ok(())
2222
}
2323

24-
fn force_flush(&self, _cx: &Context) -> Result<()> {
24+
fn force_flush(&self) -> Result<()> {
2525
Ok(())
2626
}
2727

2828
fn shutdown(&self) -> Result<()> {
29-
let cx = Context::new();
30-
self.force_flush(&cx)
29+
self.force_flush()
3130
}
3231
}
3332

0 commit comments

Comments
 (0)