-
Notifications
You must be signed in to change notification settings - Fork 761
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
tracing
override for #[instrument]
#1818
Comments
Hmm, i'm quite curious about when this would actually occur. The main scenarios I can think of is when you have a macro that expands to code including a I think adding something like this makes sense, although it seems relatively niche. Are you interested in opening a PR to add it? I'm happy to provide advice. |
Yes, it's that case. I wrote a web frontend framework that can be used to generate MVC component implementations like this (though most are more concise than that right now, since I'm the only user and only practically using it as static site generator at the moment). The problematic case appears when I try to write component libraries or unit tests and enable the tracing feature. (The attribute is unconditional, but I replace the (more context on usage) The generated components have The way component arguments are passed to I think it makes sense for me to generate the |
I'll try to make a PR some time this week. I think the one aspect I'm not entirely clear about is how you parse the arguments right now, but I haven't looked through the source code too thoroughly. Edit: I found it. I'll make sure to add relevant tests and documentation, too. |
Feature Request
Crates
tracing
(more specificallytracing_attributes
only)Motivation
As the
#[instrument]
macro is unable to use$crate
, it currently (unhygienically) grabstracing
from the locally available names.This generally works fine if the crate where that attribute ends up actually depends on
tracing
directly, but it fails whentracing
is only a transitive dependency and has not been imported.Proposal
I would like to see/implement an additional parameter for
#[instrument]
like this:#[instrument(tracing = some_path)]
where
some_path
is a path expression leading to thetracing
module.When no
tracing
argument is available,some_path
should default to justtracing
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
Currently, my documentation says to add
tracing = { version = "0.1", default-features = false }
to the consumer's dependencies to use the"tracing"
feature, which is less than ideal because the crate that uses my macro could be a library not otherwise depending ontracing
itself, and would then have to expose that as feature in turn in order to not be outright incompatible with crates that use the"tracing"
feature in mine.I could also emit a
use … as tracing;
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: