mirror of
https://github.com/tokio-rs/tracing.git
synced 2025-10-02 15:24:47 +00:00

## Motivation Currently, the `span::Attributes` type in `tokio-trace-core` contains a reference to `Metadata` with a generic lifetime `'a`. This means that if a `Subscriber` wishes to store span metadata, it cannot simply store a `&'static Metadata<'static>`. Instead, it must extract the individual components from the metadata and store them in its own structure. In addition, while the `name` and `FieldSet` in a `Metadata` are always `'static`, the target and file path are not. If the `Subscriber` needs to store those values, they must be cloned into a `String` on the heap. This is somewhat unergonomic for subscriber implementors, in comparison to being able to use a `&'static Metadata<'static>` reference. In addition, it implies additional overhead when using certain parts of a span's metadata. ## Solution This branch changes the `Metadata` fields in `Event` and `Attributes` to be `'static`, and `Subscriber::register_callsite` to take an `&'static Metadata<'static>`. Unlike PR #108, this branch leaves `Metadata` generic over a lifetime, and `Subscriber::enabled` takes an `&'a Metadata<'a>`. Since subscribers are provided all span metadata as a static reference in both `register_callsite` and `new_span`, they can clone _those_ static references, but `Subscriber::enabled` can still be called with `Metadata` constructed from a `log::Record`. This means that log records can still be filtered as normal. A different callsite, which does not have metadata from the log record, is used when actually recording events constructed from `log::Records`; in a follow-up, we can propagate the log metadata as fields there. Closes #78 Closes #108 Signed-off-by: Eliza Weisman <eliza@buoyant.io>