Skip to content

Commit 2eb55f3

Browse files
twitchaxdavidbarsky
authored andcommitted
tracing: allow setting event names in macros (#2699)
## 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
1 parent 3e1f23e commit 2eb55f3

File tree

3 files changed

+842
-81
lines changed

3 files changed

+842
-81
lines changed

tracing/src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
//! ### Configuring Attributes
215215
//!
216216
//! Both macros require a [`Level`] specifying the verbosity of the span or
217-
//! event. Optionally, the [target] and [parent span] may be overridden. If the
217+
//! event. Optionally, the, [target] and [parent span] may be overridden. If the
218218
//! target and parent span are not overridden, they will default to the
219219
//! module path where the macro was invoked and the current span (as determined
220220
//! by the subscriber), respectively.
@@ -237,7 +237,16 @@
237237
//! ```
238238
//!
239239
//! The span macros also take a string literal after the level, to set the name
240-
//! of the span.
240+
//! of the span (as above). In the case of the event macros, the name of the event can
241+
//! be overridden (the default is `event file:line`) using the `name:` specifier.
242+
//!
243+
//! ```
244+
//! # use tracing::{span, event, Level};
245+
//! # fn main() {
246+
//! span!(Level::TRACE, "my span");
247+
//! event!(name: "some_info", Level::INFO, "something has happened!");
248+
//! # }
249+
//! ```
241250
//!
242251
//! ### Recording Fields
243252
//!

0 commit comments

Comments
 (0)