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

feature: add additional fields with #[instrument(err)] #3076

Open
nrdxp opened this issue Sep 6, 2024 · 0 comments
Open

feature: add additional fields with #[instrument(err)] #3076

nrdxp opened this issue Sep 6, 2024 · 0 comments

Comments

@nrdxp
Copy link

nrdxp commented 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 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 🙏

@nrdxp nrdxp changed the title feature: add additional features with #[instrument(err)] feature: add additional fields with #[instrument(err)] Sep 6, 2024
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

No branches or pull requests

1 participant