mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-07 00:00:08 +02:00
trace: Allow field names to be separated by .s (#1027)
## Motivation In order to support conventions that add namespacing to `tokio-trace` field names, it's necessary to accept at least one type of separator character. Currently, the `tokio-trace` macros only accept valid Rust identifiers, so there is no clear separator character for namespaced conventions. See also #1018. ## Solution This branch changes the single `ident` fragment matcher for field names to match *one or more* `ident` fragments separated by `.` characters. ## Notes The resulting key is still exposed to `tokio-trace-core` as a string constant created by stringifying the dotted expression. However, if `tokio-trace-core` were later to adopt a first class notion of hierarchical field keys, we would be able to track that change in `tokio-trace` as an implementation detail. Closes #1018. Closes #1022. Signed-off-by: Eliza Weisman <[email protected]>
This commit is contained in:
@@ -278,6 +278,23 @@ fn moved_field() {
|
||||
handle.assert_finished();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dotted_field_name() {
|
||||
let (subscriber, handle) = subscriber::mock()
|
||||
.new_span(
|
||||
span::mock()
|
||||
.named("foo")
|
||||
.with_field(field::mock("fields.bar").with_value(&true).only()),
|
||||
)
|
||||
.done()
|
||||
.run_with_handle();
|
||||
with_default(subscriber, || {
|
||||
span!(Level::TRACE, "foo", fields.bar = true);
|
||||
});
|
||||
|
||||
handle.assert_finished();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn borrowed_field() {
|
||||
let (subscriber, handle) = subscriber::mock()
|
||||
|
||||
Reference in New Issue
Block a user