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: allow constant field names in macros #2712

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Sep 5, 2023

This change was initially contributed by @wyfo in PR #2617 --- I've just opened a new PR after updating that branch to track the latest changes on master.

Motivation

I've found myself in the case where I wanted to have customized event field name for different trait implementations. In fact, these implementations are completely unrelated (in separate applications), so, in this use case, I find more readable to have foo="some_id" and bar=16 instead of resource="foo" value="some_id" and resource=bar value=16

Because events only accept identifier or literal as field name, this is quite cumbersome/impossible to do. A simple solution could be to make events accept constant expression too; in my use case, I could then add a associated constant to my trait.

Solution

This PR proposes a new syntax for using constant field names:

tracing::debug!({ CONSTANT_EXPR } = "foo");

This is the same syntax than constant expression, so it should be quite intuitive.

To avoid constant expression names conflict, internal variables of macro expansion have been prefixed with __, e.g. __CALLSITE.

Closes #2617

@hawkw hawkw requested review from davidbarsky and a team as code owners September 5, 2023 22:17
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.

2 participants