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

## Motivation Fixes #298 ## Solution Add a new function to either parse the name from the macro's attribute or return the default name (instrumented method's name). Do you want to have the previous function's name as a field? In that case, that would require a bit of change (maybe return an option of something from `name`). I added some tests, please tell me if you need more (in the nightly async/await test for example) refs: #298
44 lines
943 B
Rust
44 lines
943 B
Rust
mod support;
|
|
use support::*;
|
|
|
|
use tracing::subscriber::with_default;
|
|
use tracing_attributes::instrument;
|
|
|
|
#[instrument]
|
|
fn default_name() {}
|
|
|
|
#[instrument(name = "my_name")]
|
|
fn custom_name() {}
|
|
|
|
#[test]
|
|
fn default_name_test() {
|
|
let (subscriber, handle) = subscriber::mock()
|
|
.new_span(span::mock().named("default_name"))
|
|
.enter(span::mock().named("default_name"))
|
|
.exit(span::mock().named("default_name"))
|
|
.done()
|
|
.run_with_handle();
|
|
|
|
with_default(subscriber, || {
|
|
default_name();
|
|
});
|
|
|
|
handle.assert_finished();
|
|
}
|
|
|
|
#[test]
|
|
fn custom_name_test() {
|
|
let (subscriber, handle) = subscriber::mock()
|
|
.new_span(span::mock().named("my_name"))
|
|
.enter(span::mock().named("my_name"))
|
|
.exit(span::mock().named("my_name"))
|
|
.done()
|
|
.run_with_handle();
|
|
|
|
with_default(subscriber, || {
|
|
custom_name();
|
|
});
|
|
|
|
handle.assert_finished();
|
|
}
|