-
Notifications
You must be signed in to change notification settings - Fork 853
Open
Labels
crate/attributesRelated to the `tracing-attributes` crateRelated to the `tracing-attributes` cratekind/featureNew feature or requestNew feature or request
Description
Feature Request
Crates
tracing
Motivation
When we have a trait, some trait methods may have less descriptive names on their own, example:
#[async_trait]
impl trait Pool for PoolXpto {
#[instrument]
async fn create(&self) { ... }
}In some cases, you might want a more specific name for the span, example "Pool::create" or "Pool::PoolXpto::create". In this case I ended up changing each instrument, example:
#[async_trait]
impl trait Pool for PoolXpto {
#[instrument(name = "Pool::PoolXpto::create")]
async fn create(&self) { ... }
}This process of manually changing the name is a bit tedious and error prone. It would be nice if we could somehow do this automatically.
Proposal
- Maybe we can have a post fix that gets automatically added to the name? Example:
#[async_trait]
impl trait Pool for PoolXpto {
#[instrument(postfix = "Pool::PoolXpto")] // -> span name would be "Pool::PoolXpto::create"
async fn create(&self) { ... }
}- Can we add some information to the trait that the instrument might be able to make use of? Example:
#[async_trait]
#[tracing_postfix]
impl trait Pool for PoolXpto {
#[instrument] // => this would then create a span with name "Pool::PoolXpto::create"
async fn create(&self) { ... }
}Maybe we could have a trait that gets implemented with "tracing" and returns the postfix name which then instrument uses. Not sure how feasible this is though. Maybe something like:
trait TracingPostfix<Trait: ?Sized> {
fn postfix(&self) -> &static str;
}
impl trait TracingPostfix<dyn PoolXpto> for Pool {
fn postfix(&self) -> &'static str { "Pool::PoolXpto" }
}Alternatives
Simply add the names one by one on each trait method and be sure to set them correctly.
Metadata
Metadata
Assignees
Labels
crate/attributesRelated to the `tracing-attributes` crateRelated to the `tracing-attributes` cratekind/featureNew feature or requestNew feature or request