Skip to content

Commit

Permalink
feat: rename full_name to func_path (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
andylokandy authored Jul 30, 2024
1 parent c6b609a commit aa7463e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();

// ...
Expand Down
2 changes: 1 addition & 1 deletion fastrace-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!()
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions fastrace/examples/unit_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ mod test_util {
}

pub fn closure_name<F: std::any::Any>() -> &'static str {
let full_name = std::any::type_name::<F>();
full_name
let func_path = std::any::type_name::<F>();
func_path
.rsplit("::")
.find(|name| *name != "{{closure}}")
.unwrap()
Expand Down
1 change: 0 additions & 1 deletion fastrace/src/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
InSpan {
Expand Down
7 changes: 5 additions & 2 deletions fastrace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//!
//! ```
Expand All @@ -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();
//!
//! // ...
Expand Down Expand Up @@ -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;
Expand Down
21 changes: 18 additions & 3 deletions fastrace/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(_: T) -> &'static str {
std::any::type_name::<T>()
}
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() {}
Expand Down

0 comments on commit aa7463e

Please # to comment.