-
Notifications
You must be signed in to change notification settings - Fork 733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tracing-subscriber Filtering Confusion #722
Comments
@gatoWololo Sorry I didn't see this issue earlier! Let me try and answer your questions:
That's correct: entering a span is per-thread; spawning a new thread does not automatically propagate the current span. This is stated in the docs here, but it might not be sufficiently clear? Entering a span is per-thread by design, because in many cases each thread in a program is executing a separate logical unit of work, and it wouldn't make sense to propagate them by default. However, if you want a spawned thread to also enter a span, you can do this: let span = tracing::info_span!(...);
let _enter = span.enter();
// ...
let span2 = span.clone();
let thread = std::thread::spawn(move || {
let _enter = span2.enter();
// ...
}); Or, if the span is not in the same scope as where the thread is spawned, you can propagate the current span to the spawned thread, like this: let span = Span::current();
let thread = std::thread::spawn(move || {
let _enter = span.enter();
// ...
});
If memory serves, you should be able to escape parens using Not being able to use commas, square brackets, and curly brackets is a current limitation of the env-filter parser, since these are part of the filter syntax — we should definitely support them as well. The parser for the filtering syntax is currently quite simple, so it may require a bit of a rewrite. Square and curly brackets would also need to be escaped, as they also have a meaning in the regex syntax, but if we stopped interpreting them as part of the filter syntax when inside a field, that should just work. This could be worth opening a separate feature-request issue, as I'd really like to get it working!
Directives in the filter syntax are separated by commas. So If that form was supported, I would expect that to create a filter that enables everything inside a span named On the other hand, when there is a single set of brackets, like
It's possible that's a parser bug! I'm going to continue replying to your questions in a separate comment; this one has gotten quite long. But, it seems like you've hit a lot of edge cases in the filter implementation — I think most folks don't use a lot of the more advanced filtering options, so I think nobody else has found some of these issues. Sorry about that! |
Continued:
This is kind of a consequence of an interaction between a few of the more counterintuitive aspects of how span filtering works. The filter's Does that make sense? I realize this behavior is somewhat surprising, and while I don't think there's a lot we can do to change the behavior here, it looks like the docs don't really explain this — that, at least, I think we can fix! :)
Ah, yup, this is because the filtering DSL interprets those values as tracing/tracing-subscriber/src/filter/env/field.rs Lines 40 to 45 in 18764d1
Since the values are recorded using tracing/tracing-subscriber/src/filter/env/field.rs Lines 315 to 321 in 18764d1
and therefore don't match the filter, even though they probably should. This behavior is...not great. I think we can fix it by not special-casing primitives here, and just performing all field matching with debug patterns in This should, at least, be pretty simple to fix.
So, when you create a field named
and outputs type .
However, We should make this behavior more consistent, by changing
That's quite alright, thanks for opening the issue! I think you are probably trying to use a lot more of the advanced filtering functionality than most people tend to, and so you've hit a bunch of edge cases. Sorry about that — the filtering code is actually one of the most complex part of Are you interested in helping out with this? If so, please let me know! I'd be happy to provide additional guidance on how to fix some of these problems. Otherwise, no pressure! I appreciate the work you've done in reporting these issues. Thanks! |
I am new to tracing but I am confused why |
log votes received for the last block. used while debugging test cases. re: perf, i was mildly curious and dug up: tokio-rs/tracing#722 (comment) ..which indicates that tracing won't calculate attributes unless a subscriber is interested in an event. i'm happy to hear that this is the case!
Bug Report
Version
tracing_example v0.1.0 (/home/gatowololo/Research/tracing_example)
├── tracing v0.1.14
│ ├── tracing-attributes v0.1.8
│ └── tracing-core v0.1.10
└── tracing-subscriber v0.2.5
├── tracing-core v0.1.10 ()
├── tracing-log v0.1.1
│ └── tracing-core v0.1.10 ()
└── tracing-serde v0.1.1
└── tracing-core v0.1.10 (*)
Platform
Linux thinkpad 5.4.0-29-generic # 33-Ubuntu SMP Wed Apr 29 14:32:27 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Crates
tracing-subscriber
Description
Hello I am trying to use tracing + tracing-subscriber for some fancy filtering. I have ran into some issues. I'm happy to work on fixing it but I wanted to verify this is indeed unexpected behavior. Or add to the documentation since I found some of this cases quite puzzling.
The following code is a boiled down example exhibiting my questions:
This code outputs the following base messages which I will be filtering:
Spans don't live through thread boundaries
Even though span
Thread
is in scope it seems spans don't live through thread boundaries as shown by the span-lessINFO Created child thread
is this correct?Env filter does not accept parentheses, braces, or curly braces as field values.
I can filter by id like:
Great! But it seems I cannot use
[]
or()
or{}
:Which looks like:
This sorta makes sense since it clashes with regex syntax. Using parens seems to fail silently:
This would be useful as Rust's auto derive for debug uses curly braces and I want to filter by small arrays which use square brackets.
Span Ordering and Commas
I'm unsure what the difference is between the following filters. They all seem to produce some output:
It seems order matters when applying filters:
RUST_LOG="[Thread Channel]"
vsRUST_LOG="[Channel Thread]"
? I assume it tries to apply the directives in order from left to rights?I'm not sure what the difference is between:
RUST_LOG="[Thread Channel]"
vsenv RUST_LOG="[Thread][Channel]"
?Adding the comma produces different results between:
RUST_LOG="[Thread][Channel]"
vsRUST_LOG="[Thread],[Channel]"
I'm not sure if some of this syntax is documented.
Intuition behind directives and filtering | Names of fields between spans matter
I don't have a clear mental model for how directives are applied to filter spans. Specifically for field directives: I thought it worked as follows: "The directive is checked against a span to decide whether to enter that span or not".
The following examples show my confusion:
This makes sense based on my filter since all spans have an id field.
This is a bit surprising as the Thread span
id
field has the wrong value (!= Id<3>
) so I'm surprised it is entered (Note: this is actually the behaviour I want though since I want to see the "context", that is, all the parent spans).But for some reason this seems to happen only because both fields are named
id
if I change the name of the field for the Channel fromid
tocid
:This no longer follow my intuition:
In this example all context is lost. Which is a reasonable implementation by itself. But given the example above where the context was kept since both fields happened to be named
id
seems wrong.Similarly why is the context kept in this case but not the one above?
Using primitives in Debug Instances
I can happily filter based on my Id:
However if I change my Debug impl for ID:
So that now it looks like:
Looks good... but then filtering fails:
It seems we cannot have our Debug instances "look like" primitive types? I know tracking-subscriber treats certain numeric types, books, and strings special.
Field names cannot be reserved words?
Again I can happily filter by the id field:
Looks good. But if my field is called type:
Looks like:
I don't seem to be able to filter by the field name anymore:
Conclusion
I realize this is a lot of questions for one issue! Sorry! If anyone could confirm any of the observations/bugs above I'd be happy to dig deeper. I really want filtering for my project. I think the idea is extremely powerful. Thank you for making
tracing
!The text was updated successfully, but these errors were encountered: