mirror of
https://github.com/tokio-rs/tracing.git
synced 2026-03-30 03:10:54 +00:00
## Motivation I'm writing a tracing subscriber layer that captures tracing events to display in an in-program UI in a somewhat structured manner; as such I don't want to just use the fmt layer's format-to-a-single-string approach, and instead capture (currently) the event metadata, fields, timestamp, thread, and spantrace, to be displayed in a filterable/searchable/interactable manner later. Currently, the only way to capture a `SpanTrace` is via `SpanTrace::capture`. This (rightfully) captures the `SpanTrace` of the current execution. However, I'm currently inside `Subscribe::on_event`; I have the span right here! Even if `Span::current` happens to be the same during `on_event` as when the event was fired, it seems more "proper" to create a `SpanTrace` from the span passed in to me, rather than looking up `Span::current`. ## Solution The actual code change is almost trivial: all that needs to happen is to expose a `SpanTrace::new` that takes a `Span` in addition to the existing `SpanTrace::current`.