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

tracing-core: correctly use features for tracing macro #2739

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mladedav
Copy link
Contributor

@mladedav mladedav commented May 13, 2024

Motivation

An alternative to #2655.

Currently, tracing-core defines a tracing feature which is never used, because it was intended only for expansion inside a macro, but the #[cfg(feature = "tracing")] attribute is expanded and is evaluated based on whether the consuming crate (in this case either axum or axum-extra) has the feature enabled.

Solution

Based on the feature, we can either expand the macro to a tracing::event! call or we can just expand to nothing. This way, the feature works as intended.

One difference between this and removing the feature is that with this change, if either tracing or tracing-extra enables the tracing feature, it will transitively enable the same feature in tracing-core so extractors from both crates will have their rejections logged.

If we instead remove the feature from tracing-core, each crate's tracing feature will be independent which may result in some extractors being logged and others not. So although it gives more control to the user, I personally think the behavior may be surprising.

Also, removing the feature is a breaking change while this is not.

@@ -7,7 +8,6 @@ macro_rules! __log_rejection {
body_text = $body_text:expr,
status = $status:expr,
) => {
#[cfg(feature = "tracing")]
{
tracing::event!(
target: "axum::rejection",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I get where you're coming from re. confusion but actually I find it also pretty weird that right now, we use this tracing target for both axum and axum-extra extractors... I'm wondering if it wouldn't be better to just copy-paste the macro into each crate.

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

Successfully merging this pull request may close these issues.

None yet

2 participants