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:
Eliza Weisman
2019-04-03 14:44:11 -07:00
committed by GitHub
parent 4271a9cd8d
commit 44f65afcc6
4 changed files with 398 additions and 361 deletions
+17
View File
@@ -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()