-
Notifications
You must be signed in to change notification settings - Fork 727
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
Expose tracing-log's metadata normalization system #2043
Conversation
(Ah, whoops, this was meant to be marked as a draft.) This is essentially a proof-of-concept that this works, but likely wants a number of changes to actually be upstreamed, not the least of which is new tests and examples of using the functionality. |
Also, after putting in work to do things "the right way" for tracing-filter, it was nice to be able to sit back and just make something work for a bit. |
Can I have little a code crimes, as a treat? In short, this works by sniffing the metadata name, rather than identifing a specific known callsite just for tracing-log. After the magic metadata name is found, event fields are extracted based on more magic names to fill in the runtime metadata contents, and any remaining fields are passed along to the end consumer.
I have a commit using this in my project that motivated it here. It does seem to work, but the magic fields are still printed by the formatters, rather than being filtered out. I haven't yet figured out what conspiring is going on to hide the fields from regular |
The "proper"/"better" way would be to utilize the normalized metadata's FieldSet and only record fields seen in that fieldset, but this is what is already done, and works fine, so *shrug emoji* Technically tracing-log doesn't specify that field magic starts with the name magic, but we're smuggling crimes anyway and it does so
Found it! To illustrate the benefits of using this patch, here's a comparison: (Mapping Before, default fmt:
After, default fmt:
Before, pretty fmt:
After, pretty fmt:
With that, I think I'm done with the PoC, and I need to ask whether this is a use case that tracing wants to support at all, and if so, how we want to go about it (in terms of API design, anyway; smuggling the normalization in fields seems the way to go). |
(Also doing this for |
@hawkw, can I have little a code crimes, as a treat?
Motivation
I'm piping a linked library's logging callbacks into tracing. The callbacks provide file/line/func/message, which maps nicely into the log crate's model of log events, and equally fine into tracing, but because I'm using tracing, I can't provide dynamic file/line/module into the events to be logged, so instead attach them as structured fields.
Solution
Tracing-log already does this for
log
records, so this "just" exposes and slightly extends/generalizes the practice to support arbitrary user implementations of runtime-normalized metadata.In short, this works by sniffing the metadata name, rather than identifing a specific known callsite just for tracing-log. After the magic metadata name is found, event fields are extracted based on more magic names to fill in the runtime metadata contents, and any remaining fields are passed along to the end consumer.