-
Notifications
You must be signed in to change notification settings - Fork 721
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_subscriber: add additional fields for printing to json fmt subscriber #2943
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gave this a quick spin and it seems to work great!
Maybe we should add an example though? The InjectingSubscriber setup is not so easy for someone who just wants to add some fields.
I've added an example with usage. |
I tried to make this work with |
What do you mean by this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example looks good!
Currently, the extension wraps I tried changing that to When |
ooh, because it's not serializable, right. |
Motivation
Closes #1531
There are scenarios where one wants to add some information to logs emitted by
FmtSubscriber
, for example adding OpenTelemetry trace ID and span ID.Solution
This adds an extension which all other subscribers can fill with any fields and then the formatting subscriber can emit these fields alongside the normal ones.
The extension currently wraps a
HashMap<String, String>
, but it could also feasibly be something likeHashMap<String, Box<dyn Value>>
but the flexibility of having other types than string permissible heredidn't seem to offset the additional allocations for thisString
also needs an allocation. Otherwise we could useHashMap<String, serde_json::Value>
if this would be considered to be json-specific but I don't think we should go that way now.Currently, only the
Json
formatter prints these fields as other ones do not print span attributes at all.