Skip to content

Commit

Permalink
attributes: added missing RecordTypes for instrument (#2781)
Browse files Browse the repository at this point in the history
When using a function annotated with `#[instrument]` it parses the
parameters of the function and records them either using `Value` or
using `std::fmt::Debug`. There were a few types that implement `Value`
but were missing the RecordTypes array. Added them + a unit test for a
single one.

Fixed: #2775
  • Loading branch information
kaffarell authored and davidbarsky committed Nov 7, 2023
1 parent 203f60a commit caba13d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions tracing-attributes/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,13 @@ impl RecordType {
"i32",
"u64",
"i64",
"u128",
"i128",
"f32",
"f64",
"usize",
"isize",
"String",
"NonZeroU8",
"NonZeroI8",
"NonZeroU16",
Expand All @@ -434,6 +437,8 @@ impl RecordType {
"NonZeroI32",
"NonZeroU64",
"NonZeroI64",
"NonZeroU128",
"NonZeroI128",
"NonZeroUsize",
"NonZeroIsize",
"Wrapping",
Expand Down
8 changes: 5 additions & 3 deletions tracing-attributes/tests/instrument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn override_everything() {
#[test]
fn fields() {
#[instrument(target = "my_target", level = "debug")]
fn my_fn(arg1: usize, arg2: bool) {}
fn my_fn(arg1: usize, arg2: bool, arg3: String) {}

let span = expect::span()
.named("my_fn")
Expand All @@ -68,6 +68,7 @@ fn fields() {
expect::field("arg1")
.with_value(&2usize)
.and(expect::field("arg2").with_value(&false))
.and(expect::field("arg3").with_value(&"Cool".to_string()))
.only(),
),
)
Expand All @@ -79,6 +80,7 @@ fn fields() {
expect::field("arg1")
.with_value(&3usize)
.and(expect::field("arg2").with_value(&true))
.and(expect::field("arg3").with_value(&"Still Cool".to_string()))
.only(),
),
)
Expand All @@ -89,8 +91,8 @@ fn fields() {
.run_with_handle();

with_default(subscriber, || {
my_fn(2, false);
my_fn(3, true);
my_fn(2, false, "Cool".to_string());
my_fn(3, true, "Still Cool".to_string());
});

handle.assert_finished();
Expand Down

0 comments on commit caba13d

Please sign in to comment.