pub struct InMemoryMetricExporter { /* private fields */ }Expand description
An in-memory metrics exporter that stores metrics data in memory.
This exporter is useful for testing and debugging purposes. It stores
metric data in a VecDeque<ResourceMetrics>. Metrics can be retrieved
using the get_finished_metrics method.
§Panics
This exporter may panic
- if there’s an issue with locking the
metricsMutex, such as if the Mutex is poisoned. - the data point recorded is not one of [i64, u64, f64]. This shouldn’t happen if used with OpenTelemetry API.
§Example
// Create an InMemoryMetricExporter
let exporter = InMemoryMetricExporter::default();
// Create a MeterProvider and register the exporter
let meter_provider = metrics::SdkMeterProvider::builder()
.with_reader(PeriodicReader::builder(exporter.clone()).build())
.build();
// Create and record metrics using the MeterProvider
let meter = meter_provider.meter("example");
let counter = meter.u64_counter("my_counter").build();
counter.add(1, &[KeyValue::new("key", "value")]);
meter_provider.force_flush().unwrap();
// Retrieve the finished metrics from the exporter
let finished_metrics = exporter.get_finished_metrics().unwrap();
// Print the finished metrics
for resource_metrics in finished_metrics {
println!("{:?}", resource_metrics);
}Implementations§
Source§impl InMemoryMetricExporter
impl InMemoryMetricExporter
Sourcepub fn get_finished_metrics(
&self,
) -> Result<Vec<ResourceMetrics>, InMemoryExporterError>
pub fn get_finished_metrics( &self, ) -> Result<Vec<ResourceMetrics>, InMemoryExporterError>
Trait Implementations§
Source§impl Clone for InMemoryMetricExporter
impl Clone for InMemoryMetricExporter
Source§impl Debug for InMemoryMetricExporter
impl Debug for InMemoryMetricExporter
Source§impl Default for InMemoryMetricExporter
impl Default for InMemoryMetricExporter
Source§impl PushMetricExporter for InMemoryMetricExporter
impl PushMetricExporter for InMemoryMetricExporter
Source§async fn export(&self, metrics: &ResourceMetrics) -> OTelSdkResult
async fn export(&self, metrics: &ResourceMetrics) -> OTelSdkResult
Export serializes and transmits metric data to a receiver. Read more
Source§fn force_flush(&self) -> OTelSdkResult
fn force_flush(&self) -> OTelSdkResult
Flushes any metric data held by an exporter.
Source§fn shutdown(&self) -> OTelSdkResult
fn shutdown(&self) -> OTelSdkResult
Shutdown with the default timeout of 5 seconds.
Source§fn shutdown_with_timeout(&self, _timeout: Duration) -> OTelSdkResult
fn shutdown_with_timeout(&self, _timeout: Duration) -> OTelSdkResult
Releases any held computational resources. Read more
Source§fn temporality(&self) -> Temporality
fn temporality(&self) -> Temporality
Access the Temporality of the MetricExporter.
Auto Trait Implementations§
impl Freeze for InMemoryMetricExporter
impl RefUnwindSafe for InMemoryMetricExporter
impl Send for InMemoryMetricExporter
impl Sync for InMemoryMetricExporter
impl Unpin for InMemoryMetricExporter
impl UnwindSafe for InMemoryMetricExporter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more