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

span_telemetry has hard-coded caller #2

Open
alfiedotwtf opened this issue Feb 27, 2025 · 0 comments
Open

span_telemetry has hard-coded caller #2

alfiedotwtf opened this issue Feb 27, 2025 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@alfiedotwtf
Copy link
Collaborator

Currently, the span_telemetry macro has "unknown" hard-coded for the caller's name as tracing::span!() requires name to be const. This requirement is because internally tracing::span!() is evaluating name in static context however coercing the call site outside of #[proc_macro_attribute] (like how #[tracing::instrument] is implemented) has been impossible (I've tried everything and then some).

This issue is to track the possibility of either tracing::span() relaxing their requirement for static context, or somehow get the following compiling with the same meaning:

macro_rules! error_telemetry {
    ($($arg:tt)*) => {{
        fn caller() -> String {
            let call_site = std::any::type_name_of_val(&(|| ()));
            let mut call_chain = call_site.rsplit("::");

            if let (Some(here), Some(_), Some(caller)) =
                (call_chain.next(), call_chain.next(), call_chain.next())
            {
                caller.to_string()
            } else {
                "unknown".to_string()
            }
        }

        tracing::span!(tracing::Level::ERROR, caller().as_str(), telemetry = true).in_scope(|| {
            tracing::error!($($arg)*)
        });
    }};
}

Since we already have the caller here, I even tried passing the caller's name to a #[proc_macro] which creates a literal string via a token stream and injects it into it's own call to tracing::span!(), but the compiler could still tell it wasn't const 🙃

@alfiedotwtf alfiedotwtf added the enhancement New feature or request label Feb 27, 2025
@alfiedotwtf alfiedotwtf self-assigned this Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant