extensions.rs |
|
8483 |
mod.rs |
Storage for span data shared by multiple [`Layer`]s.
## Using the Span Registry
This module provides the [`Registry`] type, a [`Subscriber`] implementation
which tracks per-span data and exposes it to [`Layer`]s. When a `Registry`
is used as the base `Subscriber` of a `Layer` stack, the
[`layer::Context`][ctx] type will provide methods allowing `Layer`s to
[look up span data][lookup] 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 `Layer`s like so:
```rust
use tracing_subscriber::{registry::Registry, Layer, prelude::*};
# use tracing_core::Subscriber;
# pub struct FooLayer {}
# pub struct BarLayer {}
# impl<S: Subscriber> Layer<S> for FooLayer {}
# impl<S: Subscriber> Layer<S> for BarLayer {}
# impl FooLayer {
# fn new() -> Self { Self {} }
# }
# impl BarLayer {
# fn new() -> Self { Self {} }
# }
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:
```rust
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`][ctx] methods, such as [`Context::span`][lookup], that
require the root subscriber to be a registry.
[`Layer`]: crate::layer::Layer
[`Subscriber`]: tracing_core::Subscriber
[ctx]: crate::layer::Context
[lookup]: crate::layer::Context::span() |
19861 |
sharded.rs |
|
32183 |
stack.rs |
|
1854 |