Skip to content

Add ability to print error Result using err via Debug instead of only Display #1630

@ciuncan

Description

@ciuncan

Feature Request

Crates

  • tracing-attributes

Motivation

Currently instrument attribute macro's err meta item makes the expanded code to print the Err result only using its Display implementation. Some Error types could be more beneficial to be printed using their Debug implementation. For example eyre::Result contains an error chain. When printed in via Display, it shows the most recent error message. But if you print it via the Debug implementation it shows the error with the error chain.

Proposal

Being able to write #[insturment(?err, ...)] would be in line with trace! et. al macro's fields, but it appears this isn't compatible with meta item syntax. Maybe two alternatives can be provided as:

  • #[instrument(err, ...)]: print the Error using Display implementation so that existing codes aren't affected.
  • #[instrument(err_dbg, ...)]: print the Error using Debug implementation.

I am willing to work on this and open a PR. Let me know if you can think of a better alternative syntax.

Alternatives

The only alternative I can think of is to remove err meta item from the attribute, catch the error somehow and print manually with "{:?}" format string. But this defeats the purpose of #[instrument] attribute (ergonomy) as it could easily implement this behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    crate/attributesRelated to the `tracing-attributes` cratekind/featureNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions