pub struct InMemorySpanExporter { /* private fields */ }Expand description
An in-memory span exporter that stores span data in memory.
This exporter is useful for testing and debugging purposes. It stores
metric data in a Vec<SpanData>. Metrics can be retrieved
using the get_finished_spans method.
§Example
    let exporter = InMemorySpanExporterBuilder::new().build();
    let provider = SdkTracerProvider::builder()
        .with_span_processor(BatchSpanProcessor::builder(exporter.clone()).build())
        .build();
    global::set_tracer_provider(provider.clone());
    let tracer = global::tracer("example/in_memory_exporter");
    let span = tracer
        .span_builder("say hello")
        .with_kind(SpanKind::Server)
        .start(&tracer);
    let cx = Context::current_with_span(span);
    cx.span().add_event("handling this...", Vec::new());
    cx.span().end();
    if let Err(e) = provider.force_flush() {
        println!("{:?}", e)
    }
    let spans = exporter.get_finished_spans().unwrap();
    for span in spans {
        println!("{:?}", span)
    }Implementations§
Source§impl InMemorySpanExporter
 
impl InMemorySpanExporter
Sourcepub fn get_finished_spans(&self) -> Result<Vec<SpanData>, InMemoryExporterError>
 
pub fn get_finished_spans(&self) -> Result<Vec<SpanData>, InMemoryExporterError>
Trait Implementations§
Source§impl Clone for InMemorySpanExporter
 
impl Clone for InMemorySpanExporter
Source§fn clone(&self) -> InMemorySpanExporter
 
fn clone(&self) -> InMemorySpanExporter
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
 
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from 
source. Read moreSource§impl Debug for InMemorySpanExporter
 
impl Debug for InMemorySpanExporter
Source§impl Default for InMemorySpanExporter
 
impl Default for InMemorySpanExporter
Source§impl SpanExporter for InMemorySpanExporter
 
impl SpanExporter for InMemorySpanExporter
Source§async fn export(&self, batch: Vec<SpanData>) -> OTelSdkResult
 
async fn export(&self, batch: Vec<SpanData>) -> OTelSdkResult
Exports a batch of readable spans. Protocol exporters that will
implement this function are typically expected to serialize and transmit
the data to the destination. Read more
Source§fn shutdown_with_timeout(&mut self, _timeout: Duration) -> OTelSdkResult
 
fn shutdown_with_timeout(&mut self, _timeout: Duration) -> OTelSdkResult
Shuts down the exporter. Called when SDK is shut down. This is an
opportunity for exporter to do any cleanup required. Read more
Source§fn set_resource(&mut self, resource: &Resource)
 
fn set_resource(&mut self, resource: &Resource)
Set the resource for the exporter.
Source§fn shutdown(&mut self) -> OTelSdkResult
 
fn shutdown(&mut self) -> OTelSdkResult
Shuts down the exporter with default timeout.
Source§fn force_flush(&mut self) -> OTelSdkResult
 
fn force_flush(&mut self) -> OTelSdkResult
This is a hint to ensure that the export of any Spans the exporter
has received prior to the call to this function SHOULD be completed
as soon as possible, preferably before returning from this method. Read more
Auto Trait Implementations§
impl Freeze for InMemorySpanExporter
impl RefUnwindSafe for InMemorySpanExporter
impl Send for InMemorySpanExporter
impl Sync for InMemorySpanExporter
impl Unpin for InMemorySpanExporter
impl UnwindSafe for InMemorySpanExporter
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