tracing-record-hierarchical
Record parent tracing::Span fields from inside child tracing::Span's context.
Motivation
Dealing with the complex relationship in the hierarchy of nested Spans in tracing may become quite cumbersome. When faced with the need to record a new value for a field of a Span higher in the tree, users have no choice but to refactor their code in some way to allow that. This includes:
-
Extracting a
Span::recordout of the childSpan:Which doesn't work when:
-
Bringing the parent
Spanto the child:We had to construct a
parentSpanusing*_span!macro and pass it to the child.
Those workarounds are not ergonomic. Furthermore, in some cases cannot be used at all.
Overview
This crate adds a HierarchicalRecord Layer and a SpanExt trait with the record_hierarchical() method that can be used as a drop-in replacement for a Span::record.
Usage
Add the HierarchicalRecord Layer to your subscriber:
# use *;
use HierarchicalRecord;
Whenever you're to use a Span::record to record a value to a parent Span's field, call the record_hierarchical() method instead, or a panicking must_record_hierarchical() version instead:
use SpanExt as _;
#
#
License
Copyright © 2023 Instrumentisto Team, https://github.com/instrumentisto
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.