Open svix-aaron1011 opened 3 months ago
I found it weird that this would be required and checked why foo.type
didn't work without quoting in the first place. Turns out the proc-macro code is actually fine (it uses parse_any
) to allow keywords, but one internal macro_rules!
that was used by the proc-macro required the field path expression to match the expr
fragment-specifier. #2925 fixes that and should thus supersede this PR (though maybe it doesn't hurt to support both if the span!
macro also supports literals?).
Motivation
The 'tracing::span!' macro supports passing in field names as string literals, which can be used to use an invalid Rust identifier as a field name (e.g. "type"). However, the 'instrument!' macro required that arguments to 'fields' be period-separated Rust identifiers.
Solution
This commit extends the
#[instrument]
macro to support both period-separated identifiers and single string-literal fields. We preserve the original argument and pass it to thetracing::span!
macro to preserve span/hygiene information.Fixes #2438