Skip to content

tracing::instrument decorator should require a level argument. #1070

@Hoverbear

Description

@Hoverbear

Feature Request

Crates

tracing::instrument

Motivation

The tracing::instrument proc macro is incredibly useful, and the docs encourage users to use it, as well as set a level. Not all users read documentation, so many use defaults. (Like me)

By default, they seem to decorate at all logging levels, which can impact performance for users in unexpected ways.

We met this problem in Vector recently, we merged vectordotdev/vector#4485 which introduced tracing::instrument on some hot paths, and, since we didn't pick a level, this lead to a 5x slowdown of the overall code along many of our topologies. We only caught it after during testing with bench users. (Our recent CI migration had benching out of commission, we're feeling that bad right now!)

Proposal

I propose #[tracing::instrument(level = "something")] be the required minimal syntax. This forces users to understand the performance characteristics of the tool and make a deliberate choice.

Alternatives

We could choose a default level, but someone will always complain.

We could not change. There is no harm in this.

We could update the docs to better highlight this issue. (This should probably be done regardless)

Metadata

Metadata

Assignees

No one assigned

    Labels

    crate/attributesRelated to the `tracing-attributes` crategood first issueGood for newcomersmeta/breakingThis is a breaking change, and should wait until the next breaking release.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions