NullExporter

Struct NullExporter 

Source
pub struct NullExporter { /* private fields */ }
Expand description

A test exporter that collects spans in memory.

Thread-safe via std::sync::Mutex (available when std feature is on) or via single-threaded usage in no_std tests.

§Examples

use grafos_observe::export::NullExporter;
use grafos_observe::export::SpanExporter;
use grafos_observe::span::ResourceSpan;
use grafos_observe::trace::TraceContext;

let exporter = NullExporter::new();
let span = ResourceSpan::new("test", TraceContext::default());
exporter.export(&[span]);
assert_eq!(exporter.len(), 1);

let spans = exporter.drain();
assert_eq!(spans.len(), 1);
assert_eq!(spans[0].name, "test");

Implementations§

Source§

impl NullExporter

Source

pub fn new() -> Self

Create a new null exporter.

Source

pub fn len(&self) -> usize

Number of spans collected so far.

Source

pub fn is_empty(&self) -> bool

Whether any spans have been collected.

Source

pub fn drain(&self) -> Vec<ResourceSpan>

Drain all collected spans, returning them and clearing the buffer.

Source

pub fn snapshot(&self) -> Vec<ResourceSpan>

Get a snapshot (clone) of all collected spans.

Trait Implementations§

Source§

impl Default for NullExporter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl SpanExporter for NullExporter

Source§

fn export(&self, spans: &[ResourceSpan])

Export a batch of spans. Implementations should not block the caller for extended periods; buffering and async flush are preferred.
Source§

fn flush(&self)

Flush any buffered spans. Called on shutdown.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.