You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if we could add additional fields to the event created when using #[instrument(err)], as it stands now, unless I'm missing something obvious, it is limited only to the error field, which makes attaching metadata using this pattern impossible.
Crates
tracing-attributes
Motivation
For example, I have an error that returns a detected path on the system where the error originated from, I'd like to log this in a seperate path field, but in order to do that, I have to write the code manually with tracing::error! instead of relying on the more declarative #[instrument(err)]
Proposal
It would be pretty nice if the fields of a struct were just automatically printed as extra fields in the log, or perhaps you could select fields of a struct inside the macro, e.g. #[instrument(err(fields = ["log", "these", "fields"]))]
Of you could do something a bit more manual and provide a reference to the error to construct fields: #[instrument(err(fields(path = err.path)) where err is a reference to the error.
Or maybe just a combination of the two, where if the = is omitted, then the field is assumed to exist inside the err reference: #[instrument(err(fields(path, some = err.other_field))
Alternatives
Maybe this is already possible and I just missed it? If so, some instruction would be much appreciated 🙏
The text was updated successfully, but these errors were encountered:
nrdxp
changed the title
feature: add additional features with #[instrument(err)]
feature: add additional fields with #[instrument(err)]Sep 6, 2024
Feature Request
It would be nice if we could add additional fields to the event created when using
#[instrument(err)]
, as it stands now, unless I'm missing something obvious, it is limited only to theerror
field, which makes attaching metadata using this pattern impossible.Crates
tracing-attributes
Motivation
For example, I have an error that returns a detected path on the system where the error originated from, I'd like to log this in a seperate
path
field, but in order to do that, I have to write the code manually withtracing::error!
instead of relying on the more declarative#[instrument(err)]
Proposal
It would be pretty nice if the fields of a struct were just automatically printed as extra fields in the log, or perhaps you could select fields of a struct inside the macro, e.g.
#[instrument(err(fields = ["log", "these", "fields"]))]
Of you could do something a bit more manual and provide a reference to the error to construct fields:
#[instrument(err(fields(path = err.path))
whereerr
is a reference to the error.Or maybe just a combination of the two, where if the
=
is omitted, then the field is assumed to exist inside theerr
reference:#[instrument(err(fields(path, some = err.other_field))
Alternatives
Maybe this is already possible and I just missed it? If so, some instruction would be much appreciated 🙏
The text was updated successfully, but these errors were encountered: