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

Feature: #[trace(variables = [b])] #135

Closed
taqtiqa-mark opened this issue Mar 30, 2022 · 9 comments
Closed

Feature: #[trace(variables = [b])] #135

taqtiqa-mark opened this issue Mar 30, 2022 · 9 comments

Comments

@taqtiqa-mark
Copy link
Contributor

taqtiqa-mark commented Mar 30, 2022

Another use case to take into account while the model phase of #113 is taking shape.....

This is also related to the #134 use case, but not limited to:

  • aiding a new/infrequent user quickly get useful data to assist with debugging.
  • 'tracing' the LHS of the expression where the function is in a sealed trait or 3rd-party crate.

The following should be possible (initially sync only):

#[trace(variables=[p, n]]
fn factorial(mut n: u64) -> u64 {
    let mut p = 1;
    while n > 1 {
        p *= n;
        n -= 1;
    }
    p
}

The idea would be to have this become (better suggestions welcome):

fn factorial(mut n: u64) -> u64 {
    let _g = LocalSpan::enter_with_local_parent();
    let mut p;
    {
            let _mt = LocalSpan::enter_with_local_parent();
            p = 1;
    }
    while n > 1 {
        {
            let _mt = LocalSpan::enter_with_local_parent();
            p *= n;
        }
        {
            let _mt = LocalSpan::enter_with_local_parent();
            n -= 1;
        }
    }
    p
}

Producing SpanRecords for:

  • p = 1
  • p = 8
  • n = 7
  • p = 56
  • n = 6
@taqtiqa-mark taqtiqa-mark changed the title Feature: #[trace(var = [a,b])] Feature: #[trace(variables = [a,b])] Apr 1, 2022
@taqtiqa-mark taqtiqa-mark changed the title Feature: #[trace(variables = [a,b])] Feature: #[trace(variables = [b])] Apr 1, 2022
@andylokandy
Copy link
Collaborator

Implemented in #150. Refer to example

@taqtiqa-mark
Copy link
Contributor Author

I don't see where in that example you get the variable tracing from #[trace(variables=[p, n]].

@andylokandy
Copy link
Collaborator

andylokandy commented Jul 19, 2023

Oh my bad, I initially thought it was only supposed to record function arguments and return values similar to log_derive. However, even if such a feature could be implemented in minitrace, it might be more beneficial to incorporate it into log_derive.

@taqtiqa-mark
Copy link
Contributor Author

taqtiqa-mark commented Jul 19, 2023

Isn't this categorically different when the RHS is a 3rd party crate, and more so if it uses minitrace. Will the result really be the same as using log_derive?

@andylokandy
Copy link
Collaborator

andylokandy commented Jul 21, 2023

It's not the same as using log_derive, but what I proposed is to add such feature to log_derive. And because minitrace could work seamlessly with log, it will eventually the same as implementing such feature in minitrace.

@taqtiqa-mark
Copy link
Contributor Author

OK, I need to become more familiar with log_derive.

@andylokandy
Copy link
Collaborator

The log_derive crate appears to have been unmaintained for some time and is not compatible with async-trait. It might be feasible to consider a successor crate.

@andylokandy
Copy link
Collaborator

andylokandy commented Jul 21, 2023

FYI, I've made an experimental crate logcall for async-trait compatibility by doing some simple changes on current minitrace-macro implementation.

@taqtiqa-mark
Copy link
Contributor Author

taqtiqa-mark commented Sep 11, 2023

@andylokandy , sorry to keep pushing back on this closure. In the OP I provided a sketch of the tracing that would be injected. Could you similarly provide the tracing logic that would apply to the given example for the approach you advocate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants