Skip to main content
Settings
Help

Module registry

Module registry 

Source
Expand description

Storage for span data shared by multiple Layers.

§Using the Span Registry

This module provides the Registry type, a Subscriber implementation which tracks per-span data and exposes it to Layers. When a Registry is used as the base Subscriber of a Layer stack, the layer::Context type will provide methods allowing Layers to look up span data stored in the registry. While Registry is a reasonable default for storing spans and events, other stores that implement LookupSpan and Subscriber themselves (with SpanData implemented by the per-span data they store) can be used as a drop-in replacement.

For example, we might create a Registry and add multiple Layers like so:

use tracing_subscriber::{registry::Registry, Layer, prelude::*};

let subscriber = Registry::default()
    .with(FooLayer::new())
    .with(BarLayer::new());

If a type implementing Layer depends on the functionality of a Registry implementation, it should bound its Subscriber type parameter with the LookupSpan trait, like so:

use tracing_subscriber::{registry, Layer};
use tracing_core::Subscriber;

pub struct MyLayer {
    // ...
}

impl<S> Layer<S> for MyLayer
where
    S: Subscriber + for<'a> registry::LookupSpan<'a>,
{
    // ...
}

When this bound is added, the Layer implementation will be guaranteed access to the Context methods, such as Context::span, that require the root subscriber to be a registry.

Structs§

Dataregistry and std
Span data stored in a Registry.
Extensionsstd
An immutable, read-only reference to a Span’s extensions.
ExtensionsMutstd
An mutable reference to a Span’s extensions.
Registryregistry and std
A shared, reusable store for spans.
Scope
An iterator over the parents of a span, ordered from leaf to root.
ScopeFromRootalloc or std
An iterator over the parents of a span, ordered from root to leaf.
SpanRef
A reference to [span data] and the associated registry.

Traits§

LookupSpan
Provides access to stored span data.
SpanData
A stored representation of data associated with a span.