Skip to content

Commit

Permalink
tracing: allow setting event names in macros (#2699)
Browse files Browse the repository at this point in the history
## Motivation

The motivation is #1426.  Currently, event names are set to a default
value of `event file:line`, which (1) doesn't allow for customization,
and (2) prevents events from working for some opentelemetry endpoints
(they often use the event name `exception` to designate something like a
panic).

## Solution

Went through the event macros, and added new parameterization that
allows for setting the `name`.  In addition, added some comments, and
reordering, to make life a bit better for the next person that comes
along to edit those macros.  Finally, added tests for the macro
expansion alongside the existing tests with a reasonable amount of
coverage (though, admittedly, more could be added for all of the macro
invocation types

Fixes #1426
  • Loading branch information
twitchax authored and hawkw committed Oct 1, 2023
1 parent 1771128 commit b8180dd
Show file tree
Hide file tree
Showing 3 changed files with 842 additions and 81 deletions.
13 changes: 11 additions & 2 deletions tracing/src/lib.rs
Expand Up @@ -214,7 +214,7 @@
//! ### Configuring Attributes
//!
//! Both macros require a [`Level`] specifying the verbosity of the span or
//! event. Optionally, the [target] and [parent span] may be overridden. If the
//! event. Optionally, the, [target] and [parent span] may be overridden. If the
//! target and parent span are not overridden, they will default to the
//! module path where the macro was invoked and the current span (as determined
//! by the subscriber), respectively.
Expand All @@ -237,7 +237,16 @@
//! ```
//!
//! The span macros also take a string literal after the level, to set the name
//! of the span.
//! of the span (as above). In the case of the event macros, the name of the event can
//! be overridden (the default is `event file:line`) using the `name:` specifier.
//!
//! ```
//! # use tracing::{span, event, Level};
//! # fn main() {
//! span!(Level::TRACE, "my span");
//! event!(name: "some_info", Level::INFO, "something has happened!");
//! # }
//! ```
//!
//! ### Recording Fields
//!
Expand Down

0 comments on commit b8180dd

Please sign in to comment.