Rust

storage

Module

Where the current span is kept.

Contents

use utopia_span::Auto;
Rust
pub struct Auto

The task's span inside a Task::scope, the process's span outside.

Rust
use utopia_span::{Auto, Span, Storage};

let storage = Auto::new();
let span = Span::new("cli");
storage.set(Some(span.clone()));
assert_eq!(storage.get(), Some(span));
use utopia_span::Memory;
Rust
pub struct Memory

One current span for the whole process.

Rust
use utopia_span::{Memory, Span, Storage};

let storage = Memory::new();
assert!(storage.get().is_none());

let span = Span::new("job");
storage.set(Some(span.clone()));
assert_eq!(storage.get(), Some(span));
storage.set(None);
assert!(storage.get().is_none());
use utopia_span::Task;
Rust
pub struct Task

One current span per tokio task.

A task gets its own slot by running inside Task::scope; outside a scope there is no current span and Storage::set does nothing.

Rust
use utopia_span::{Span, Storage, Task};

let storage = Task::new();
storage.set(Some(Span::new("ignored")));
assert!(storage.get().is_none()); // outside a scope

Task::scope(async {
    let storage = Task::new();
    let span = Span::new("request");
    storage.set(Some(span.clone()));
    assert_eq!(storage.get(), Some(span));
})
.await;
use utopia_span::Storage;
Rust
pub trait Storage: Send + Sync

Keeps the current span of an execution context, so Span::add and Span::current work without passing spans around.

Implement it to keep spans elsewhere (a thread-local, a request extension); register it with Span::set_storage.

Implemented byMemoryTaskAuto