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

Const value as target = value in instrument. #2460

Closed
dpc opened this issue Feb 7, 2023 · 1 comment · Fixed by #2941
Closed

Const value as target = value in instrument. #2460

dpc opened this issue Feb 7, 2023 · 1 comment · Fixed by #2941

Comments

@dpc
Copy link
Contributor

dpc commented Feb 7, 2023

Feature Request

Crates

tracing

Motivation

We keep the set of tracing targets as a list of const LOG_SMTH : &str = "smth";
to avoid typos.

Proposal

I'd like to:

#[instrument(tracing = LOG_SMTH)]
@hawkw
Copy link
Member

hawkw commented Feb 7, 2023

Currently, the target value is parsed using the StrArg helper:

let target = input.parse::<StrArg<kw::target>>()?.value;

This parses the input as a keyword followed by a string literal:
impl<T: Parse> Parse for StrArg<T> {
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
let _ = input.parse::<T>()?;
let _ = input.parse::<Token![=]>()?;
let value = input.parse()?;
Ok(Self {
value,
_p: std::marker::PhantomData,
})
}
}

We could support constants in the attribute if we changed this code to accept a string literal or an identifier. We might want to do the same for other attribute arguments that are currently only able to accept string literals and not constants, besides the target.

This is probably a pretty straightforward change, if anyone is interested in submitting a PR. I'm happy to provide some guidance!

mbrobbel added a commit to mbrobbel/tracing that referenced this issue Mar 26, 2024
mbrobbel added a commit to mbrobbel/tracing that referenced this issue Mar 26, 2024
dpc pushed a commit to dpc/tracing that referenced this issue Apr 20, 2024
dpc pushed a commit to dpc/tracing that referenced this issue Apr 22, 2024
dpc pushed a commit to dpc/tracing that referenced this issue Apr 22, 2024
dpc pushed a commit to dpc/tracing that referenced this issue Apr 23, 2024
dpc pushed a commit to dpc/tracing that referenced this issue Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants