Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Lok <[email protected]>
  • Loading branch information
andylokandy committed Oct 27, 2023
1 parent 4c126f3 commit 2575e56
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
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(full_path = true)]` to use the full path of the function instead of only the function name.
- Add macro attribute `#[trace(path_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 full_path = false;
let mut path_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("full_path") => {
full_path = b.value;
args.insert("full_path");
})) if path.is_ident("path_name") => {
path_name = b.value;
args.insert("path_name");
}
NestedMeta::Meta(Meta::NameValue(MetaNameValue {
path,
Expand All @@ -69,9 +69,9 @@ impl Args {
}
}

let name = if full_path {
let name = if path_name {
if args.contains("name") {
abort_call_site!("`name` and `full_path` can not be used together");
abort_call_site!("`name` and `path_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.
/// * `full_path` - Whether to use the full path of the function as the span name. Defaults to `false`.
/// * `path_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", full_path = true)]
#[trace(name = "Name", path_name = true)]
fn f() {}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: `name` and `full_path` can not be used together
error: `name` and `path_name` can not be used together
--> tests/ui/err/has-name-and-full-path.rs:3:1
|
3 | #[trace(name = "Name", full_path = true)]
3 | #[trace(name = "Name", path_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(name = "Name", full_path = false)]
#[trace(name = "Name", path_name = false)]
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(full_path = true)]
#[trace(path_name = true)]
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(full_path = true)]
fn do_something_full_path(i: u64) {
#[trace(path_name = true)]
fn do_something_path_name(i: u64) {
std::thread::sleep(std::time::Duration::from_millis(i));
}

#[trace(full_path = true)]
async fn do_something_async_full_path(i: u64) {
#[trace(path_name = true)]
async fn do_something_async_path_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_full_path(100);
block_on(do_something_async_full_path(100));
do_something_path_name(100);
block_on(do_something_async_path_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_full_path []
lib::macro_example::{{closure}}::do_something_full_path []
lib::macro_example::{{closure}}::do_something_async_path_name []
lib::macro_example::{{closure}}::do_something_path_name []
"#;
assert_eq!(
tree_str_from_span_records(collected_spans.lock().clone()),
Expand Down

0 comments on commit 2575e56

Please sign in to comment.