diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c6590f..401457e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Upgrade dependencies including opentelemtry and more. - Remove deprecated methods `Config::batch_report_interval` and `Config::batch_report_max_spans`. +- Deprecate `full_name!()` and rename it to `full_path!()`. ## v0.6.8 diff --git a/README.md b/README.md index 57da57a..af2f2bf 100644 --- a/README.md +++ b/README.md @@ -46,13 +46,13 @@ pub fn send_request(req: HttpRequest) -> Result<(), Error> { Libraries are able to set up an individual tracing context, regardless of whether the caller has set up a tracing context or not. This can be achieved by using `Span::root()` to start a new trace and `Span::set_local_parent()` to set up a local context for the current thread. -The `full_name!()` macro can detect the function's full name, which is used as the name of the root span. +The `func_path!()` macro can detect the function's full name, which is used as the name of the root span. ```rust use fastrace::prelude::*; pub fn send_request(req: HttpRequest) -> Result<(), Error> { - let root = Span::root(full_name!(), SpanContext::random()); + let root = Span::root(func_path!(), SpanContext::random()); let _guard = root.set_local_parent(); // ... diff --git a/fastrace-macro/src/lib.rs b/fastrace-macro/src/lib.rs index b5f1657..5d656d4 100644 --- a/fastrace-macro/src/lib.rs +++ b/fastrace-macro/src/lib.rs @@ -292,7 +292,7 @@ fn gen_name(span: proc_macro2::Span, func_name: &str, args: &Args) -> proc_macro } None => { quote_spanned!(span=> - fastrace::full_name!() + fastrace::func_path!() ) } } diff --git a/fastrace/examples/unit_test.rs b/fastrace/examples/unit_test.rs index 98ca281..27f7754 100644 --- a/fastrace/examples/unit_test.rs +++ b/fastrace/examples/unit_test.rs @@ -58,8 +58,8 @@ mod test_util { } pub fn closure_name() -> &'static str { - let full_name = std::any::type_name::(); - full_name + let func_path = std::any::type_name::(); + func_path .rsplit("::") .find(|name| *name != "{{closure}}") .unwrap() diff --git a/fastrace/src/future.rs b/fastrace/src/future.rs index bbdee1e..0bd72f6 100644 --- a/fastrace/src/future.rs +++ b/fastrace/src/future.rs @@ -64,7 +64,6 @@ pub trait FutureExt: std::future::Future + Sized { /// ``` /// /// [`Future`]:(std::future::Future) - /// [`Span::set_local_parent`](Span::set_local_parent) #[inline] fn in_span(self, span: Span) -> InSpan { InSpan { diff --git a/fastrace/src/lib.rs b/fastrace/src/lib.rs index 8293cf4..948daf7 100644 --- a/fastrace/src/lib.rs +++ b/fastrace/src/lib.rs @@ -38,7 +38,7 @@ //! [`Span::root()`] to start a new trace and [`Span::set_local_parent()`] to set up a //! local context for the current thread. //! -//! The [`full_name!()`] macro can detect the function's full name, which is used as +//! The [`func_path!()`] macro can detect the function's full name, which is used as //! the name of the root span. //! //! ``` @@ -47,7 +47,7 @@ //! # struct Error; //! //! pub fn send_request(req: HttpRequest) -> Result<(), Error> { -//! let root = Span::root(full_name!(), SpanContext::random()); +//! let root = Span::root(func_path!(), SpanContext::random()); //! let _guard = root.set_local_parent(); //! //! // ... @@ -403,11 +403,14 @@ pub mod prelude { pub use crate::event::Event; #[doc(no_inline)] pub use crate::file_location; + #[allow(deprecated)] #[doc(no_inline)] pub use crate::full_name; #[doc(no_inline)] pub use crate::func_name; #[doc(no_inline)] + pub use crate::func_path; + #[doc(no_inline)] pub use crate::future::FutureExt as _; #[doc(no_inline)] pub use crate::local::LocalSpan; diff --git a/fastrace/src/macros.rs b/fastrace/src/macros.rs index a88973f..fc2d53d 100644 --- a/fastrace/src/macros.rs +++ b/fastrace/src/macros.rs @@ -31,14 +31,29 @@ macro_rules! func_name { /// /// # Example /// -/// ```rust -/// use fastrace::full_name; +/// ``` +/// use fastrace::func_path; /// /// fn foo() { -/// assert_eq!(full_name!(), "rust_out::main::_doctest_main_fastrace_src_macros_rs_34_0::foo"); +/// assert_eq!(func_path!(), "rust_out::main::_doctest_main_fastrace_src_macros_rs_34_0::foo"); /// } /// # foo() #[macro_export] +macro_rules! func_path { + () => {{ + fn f() {} + fn type_name_of(_: T) -> &'static str { + std::any::type_name::() + } + let name = type_name_of(f); + let name = &name[..name.len() - 3]; + name.trim_end_matches("::{{closure}}") + }}; +} + +/// Get the full path of the function where the macro is invoked. Returns a `&'static str`. +#[deprecated(since = "0.7.0", note = "Please use `fastrace::func_path!()` instead")] +#[macro_export] macro_rules! full_name { () => {{ fn f() {}