Open andrewbanchich opened 1 year ago
I would probably implement something like this at the subscriber level, perhaps as a wrapper for the FormatFields
trait (which determines how tracing-subscriber::fmt
formats fields on spans and events).
There are some existing wrappers for changing field visitor behavior in the tracing_subscriber::field
module, so I think it would be quite reasonable to add some kind of truncation wrapper there as well.
I don't have the time to implement something like this in the near future, but I'd definitely accept a pull request, and I'm happy to provide some guidance if you're interested in implementing this.
As a potential alternative solution or workaround, I would also point out that the #[instrument]
macro does have the capability to skip recording some arguments to a function as fields. So, if there are specific arguments to an #[instrument]
ed function that are always long, you could use this to skip those fields entirely.
Truncation is probably a nicer solution, since it could be configured globally rather than per-function, and would allow a field to still be displayed completely if it's not too long. But, using #[instrument(skip(...))]
may be a good interim solution, depending on your use case.
I don't have the time to implement something like this in the near future, but I'd definitely accept a pull request, and I'm happy to provide some guidance if you're interested in implementing this.
Great, thanks! I'll give it a shot.
Feature Request
For large fields, tracing instrumentation can make logs pretty hard to read. It would be really nice to have some setting for the instrument macro that would truncate fields longer than a given value.