Replies: 1 comment 4 replies
-
Thanks for working on this, this is lovely! Another option for officially endorsing the new The primary reason for this is that the current |
Beta Was this translation helpful? Give feedback.
-
Thanks for working on this, this is lovely! Another option for officially endorsing the new The primary reason for this is that the current |
Beta Was this translation helpful? Give feedback.
-
Repository with backing code: https://github.com/CAD97/tracing-filter
See preview docs live: https://cad97.github.io/tracing-filter/tracing_filter/
So, I've implemented a new effectively replacement for
EnvFilter
. First off:And now that that's out of the way,
Wait, what is this?
What it says on the tin: I want to replace
EnvFilter
. To that end, I've implemented a 100% bug-for-bug compatible version ofEnvFilter
, along with another filter provider 100% compatible withenv_filter
's filter format. (Unfortunately, they aren't quite drop-in compatible, but this is in service of better Developer eXperience using them.)Motivation
Due to what could be described as "historical accident,"
EnvFilter
's format is... underspecified, to say the least, and its parser leaves much to be desired. Whiletarget[span]
is the normal filter we all know and love,EnvFilter
also allows such unusual filter directives as[span]target
,[span][span]
,[[[[[[[[[[[span]
, and[{/* you can put anything here; it's ignored */}]
. Having a more principled implementation allows us to understand and perhaps improve some of these "incidental features" and giveEnvFilter
some love.Also, the new parser gives nice miette-powered diagnostics for ignored directives:
To note: these diagnostics are first pass, and can likely be improved further with some more effort. (Notably, zkat/miette#139.) Send some ⭐s zkat's way for the wonderful library!
(Side note: while writing this I'm jumping around in tracing-filter's code pulling notes and examples, and I keep finding things, going "wait, that can't be right", testing them, and finding out that no, this is in fact the upstream behavior. There is a laundry list of low-hanging fruit for improvement to the
EnvFilter
format exposed by this port, and they're all technically breaking...)Future 🦄 👀
A new filter string format?
While working on tracing-filter, I've been sketching a "query1" language that can be used to better specify what events and spans to include (or exclude!) and would love to see it developed. Notably, it's much more structured than the existing ad-hoc extension to env_logger's format, which puts it in a great place to integrate with the experimental valuable support. Of course, 100% backwards compatibility with common2 env_logger filters will be provided; just the legacy
EnvFilter
syntax will be replaced3.Improvements to the legacy format?
While I personally am more interested and invested in the "query" format, having the much more principled implementation will allow for targeted improvements (say, multiple fields in a given
[span]
directive?) — and, given the improved understanding of the parser's behavior, perhaps these can even be non-breaking improvements for everyone.Post-facto filtering?
The real meat on the bone. While this is a stretch goal to a stretch goal, I'd love to shim the current
Filter
trait with a version that can work on serialized forms of events. This would allow cool new applications, such as recording the structured event stream in the json format, and then later using query filters to filter down the data set to the events actually necessary to diagnose a traced incident.Other?
I have an open tracking discussion where I want to hear your potential use cases!
Integration
There's three main approaches (and one "status quo" approach) that I see:
Upstream into tracing-subscriber
Pros
EnvFilter
directly (in-place, even, with the compatible format)Cons
Filter
traitLive in the tracing repo as tracing-filter (or similar)
Pros
Cons
Live in external repo, officially endorsed/recommended solution
Pros
Cons
External crate, no official endorsement (but a note in the docs)
Pros
Cons
What next?
Ideally, four things:
EnvFilter
)Also, disclaimer: assuming this work is "greenlit" to continue with official tracing's blessing, I currently plan to apply for a (small, individual) Project Grant from the Rust Foundation for this work (convenient timing!). I honestly expect to not get one (this is at best of tertiary benefit to the Rust Ecosystem, and it currently looks more focused on more directly rust-lang/rust adjacent work), but might as well through my hat in the ring.
Footnotes
Strictly speaking, it's not a real query language, as it cannot do data mapping (it only does the "filter" in map/filter/reduce), but it's a decent informal description of how it feels, so the moniker has stuck. ↩
Unfortunately, true 100% compatibility is untractable, due to env_logger's very permissive format. However, any directive of form
rust::module::path=level
will continue to work as in env_logger (i.e. only custom specified targets are potentially impacted). Also,/regex
filters from env_logger apply globally, and should be replaced with the query filters' support for the same functionality. Of course, you can always use the simple filter for true 100% compatibility with env_logger. ↩I could be talked into supporting a sensible subset of
EnvFilter
's syntax, as it is disjoint to common env_logger syntax (see previous footnote) and also doesn't overlap the planned way of specifying query filters. However, the point of a new format is to remove legacy jank, so (hopefully) no legacy jank is getting inherited. ↩I have compiler engineer brain. Every program is a compiler. Every data structure is a graph. I am not taking questions w.r.t. this footnote. ↩
Beta Was this translation helpful? Give feedback.
All reactions