Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macro use full name as default #171

Merged
merged 6 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## v0.6.1

- Add macro attribute `#[trace(path_name = true)]` to use the full path of the function instead of only the function name.
- Add macro attribute `#[trace(full_name = true)]` to use the full path of the function instead of only the function name.

## v0.6.0

Expand Down
14 changes: 7 additions & 7 deletions minitrace-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Args {

let mut args = HashSet::new();
let mut func_name = func_name;
let mut path_name = false;
let mut full_name = false;
let mut enter_on_poll = false;

for arg in &input {
Expand All @@ -53,9 +53,9 @@ impl Args {
path,
lit: Lit::Bool(b),
..
})) if path.is_ident("path_name") => {
path_name = b.value;
args.insert("path_name");
})) if path.is_ident("full_name") => {
full_name = b.value;
args.insert("full_name");
}
NestedMeta::Meta(Meta::NameValue(MetaNameValue {
path,
Expand All @@ -69,9 +69,9 @@ impl Args {
}
}

let name = if path_name {
let name = if full_name {
if args.contains("name") {
abort_call_site!("`name` and `path_name` can not be used together");
abort_call_site!("`name` and `full_name` can not be used together");
}
Name::FullPath
} else {
Expand Down Expand Up @@ -100,7 +100,7 @@ impl Args {
/// ## Arguments
///
/// * `name` - The name of the span. Defaults to the function name.
/// * `path_name` - Whether to use the full path of the function as the span name. Defaults to `false`.
/// * `full_name` - Whether to use the full path of the function as the span name. Defaults to `false`.
/// * `enter_on_poll` - Whether to enter the span on poll, if set to `false`, `in_span` will be used.
/// Only available for `async fn`. Defaults to `false`.
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use minitrace::trace;

#[trace(name = "Name", path_name = true)]
#[trace(name = "Name", full_name = true)]
fn f() {}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: `name` and `path_name` can not be used together
--> tests/ui/err/has-name-and-path-name.rs:3:1
error: `name` and `full_name` can not be used together
--> tests/ui/err/has-name-and-full-name.rs:3:1
|
3 | #[trace(name = "Name", path_name = true)]
3 | #[trace(name = "Name", full_name = true)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the attribute macro `trace` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use minitrace::trace;

#[trace(path_name = true)]
#[trace(full_name = true)]
async fn f(a: u32) -> u32 {
a
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use minitrace::trace;

#[trace(name = "Name", path_name = false)]
#[trace(name = "Name", full_name = false)]
async fn f(a: u32) -> u32 {
a
}
Expand Down
16 changes: 8 additions & 8 deletions minitrace/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,13 @@ fn macro_example() {
futures_timer::Delay::new(std::time::Duration::from_millis(i)).await;
}

#[trace(path_name = true)]
fn do_something_path_name(i: u64) {
#[trace(full_name = true)]
fn do_something_full_name(i: u64) {
std::thread::sleep(std::time::Duration::from_millis(i));
}

#[trace(path_name = true)]
async fn do_something_async_path_name(i: u64) {
#[trace(full_name = true)]
async fn do_something_async_full_name(i: u64) {
futures_timer::Delay::new(std::time::Duration::from_millis(i)).await;
}

Expand All @@ -504,8 +504,8 @@ fn macro_example() {
let _g = root.set_local_parent();
do_something(100);
block_on(do_something_async(100));
do_something_path_name(100);
block_on(do_something_async_path_name(100));
do_something_full_name(100);
block_on(do_something_async_full_name(100));
}

minitrace::flush();
Expand All @@ -514,8 +514,8 @@ fn macro_example() {
root []
do_something []
do_something_async []
lib::macro_example::{{closure}}::do_something_async_path_name []
lib::macro_example::{{closure}}::do_something_path_name []
lib::macro_example::{{closure}}::do_something_async_full_name []
lib::macro_example::{{closure}}::do_something_full_name []
"#;
assert_eq!(
tree_str_from_span_records(collected_spans.lock().clone()),
Expand Down
Loading