-
Notifications
You must be signed in to change notification settings - Fork 27
fastrace
override for #[trace]
#69
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
Comments
This is essentially a copy of this feature request I filed with Tracing in early 2022 and submitted an implementation for, but unfortunately my pull-request never got processed despite maintainers' initial tentative approval. I'm still working on-and-off on my framework, as time permits, and still need a good tracing system that can instrument async functions and blocks. I also think this feature would be helpful for other macro authors. You can look at the changes submitted there to see roughly how I'd do this, of course adapted to this project's code style instead of Tracing's. |
fastrace
override for #[instrument]
fastrace
override for #[trace]
Whoops, forgot to adjust the title of all things. Sorry about that 😅 |
Thanks for investigating fastrace :) I suggest using the underlying building blocks i.e., |
In theory yes, though it would make my macro more complex. You're right though, I'll see if I can integrate this easily in other ways first. |
Is it possible to address the very first issue by reexporting #[your_macro]
fn user_function() {
// user code ...
}
// expands to
fn user_function() {
use your_crate::reexport::fastrace;
#[fastrace::trace]
fn inner() {
// user code ...
}
inner()
} |
Likely yes, but only because the macro currently isn't hygienic. Fixing this part of hygiene by default would be a breaking change, so I'll submit it separately, but I'd like to be able to specify a fully qualified path for fastrace either way. Edit: Though, I think I would have fewer issues here from the get-go, since |
Feature Request
Crates
fastrace-macro
Motivation
As the
#[trace]
macro is unable to use$crate
, it currently (unhygienically) grabsfastrace
from the locally available names.This generally works fine if the crate where that attribute ends up actually depends on
fastrace
directly, but it fails whenfastrace
is only a transitive dependency and has not been imported.In my case specifically, I'd like to auto-instrument components generated by my UI component framework, which aren't simple functions.
Proposal
I would like to implement an additional parameter for
#[trace]
like this:#[trace(fastrace = some_path)]
where
some_path
is a path expression leading to thefastrace
module.When no
fastrace
argument is available,some_path
should default to justfastrace
with call site resolution, as before.The hygiene information on those path tokens should be preserved to make it easier to use in other macros, but this is the default when pasting into a
quote!(…)
anyway, so I don't see a reason not to handle it like that.Alternatives
I could document my framework to tell users to add a specific version of
fastrace
with relevant features to their dependencies to use a new"fastrace"
feature I'd add, which is less than ideal because the crate that uses my macro could be a library not otherwise depending onfastrace
itself, and would then have to expose that as feature in turn.Since fastrace-instrumentation should be zero-cost when tracing is disabled, I'd like to enable it unconditionally instead, but without complicating my library's use.
I could also emit a
use … as fastrace;
import statement, but this adds an item to the consumer-visible namespace and can lead to unexpected collisions (or shadowing, if I rewrite some of my code to scope it).The text was updated successfully, but these errors were encountered: