-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Replace custom logging by tracing #2814
Conversation
Visit the preview URL for this PR (updated for commit 00ae994): https://yew-rs-api--pr2814-tracing-30juq21r.web.app (expires Sat, 13 Aug 2022 23:07:15 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
Benchmark - SSRYew Master
Pull Request
|
Size Comparison
✅ None of the examples has changed their size significantly. |
The problem with this approach is that the binary must be recompiled every time logging level is to be changed. Unlike CLI applications (for example), there's no Browser dev tools take care of this with their logging levels and filers. See them for Firefox and Chrome I'm not really keen on adding tracing here. I think we should use |
I don't think that's generally true. By default, all tracing events are statically enabled. Then, you register a tracing subscriber on startup. Not sure which one is best here, but there's a lot to choose from, and it's not too hard to write your own. Then, at runtime, the subscriber can once again decide to filter spans and events by their metadata, including their log level and module, or handle them in any way they see fit - or not at all. Since there is no environment variables to read, one could still read a global from javascript to determine the log level on initialization. To make the analogy to logging in other programs, it's On the other hand, using To also quell some fears about code size: the above comparison actually has all tracing callsites (events and spans) statically enabled (they can still be filtered by the eventual subscriber), yet the bundle size actually decreases. |
I wasn't really concerned about code size because of dead code elimination, in case tracing isn't used.
I didn't think of this approach, but it makes sense. Read a JS variable and then use it initialize the tracing subscriber. Would it make sense to tracing for our other logs? |
I guess so. Incidentally, that would also address #2795. |
not yet in testing, and for some errors!
I am in favour of switching to log or tracing instead of As This allows a logging experience unified for wasm and non-wasm environments. Logs from other crates can also be captured if we encourage users to register a logger with log crate. In addition, a logger does not have to always write to console. With tracing / log, we can implement a custom logger that shows an overlay like webpack when an error is logged via |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. It should be documentation that we use tracing for logging so users know to enable it. Maybe we can set it up, like the console panic hook?
If you don't want to document it in this PR, please do create an issue for it.
Follow up is linked. Setting up a subscriber by default sounds like a good idea, unless it has the potential of overriding an already set user defined one. I think it's simpler to find a good example of one to use, usually, they can be setup in a single line of code, like |
Description
Fixes #2790
Fixes #2795
Replaces the logging of lifecycle events by the tracing crate. The nice thing is that the behaviour, including compile-time maximal levels, can be configured in the final executable, and is automatically applied in all crates emitting traces. Does not include a subscriber, this should also be configured in the final binary crate.
Not included (yet?) is the configuration of all examples crates to turn off tracing events at compile time, so I wouldn't be surprised by a small increase in bundle size per the benchmarks.
If it turns out to be a sizeable increase, I will add this.EDIT: seems to at least balanced by the removed code.I have tried tracing-wasm crate for consuming the logs/as a subscriber, but there seems to be some incompatibility with chrome (works better on Firefox) that leads to weirdly long measurements. The span and events are fine though, the problem is more with the
performance
browser API.Another nice feature is that one can turn on
tracing = { feature = ["log-always"] }
to forward events tolog
consumers, which works withwasm_logger
.Checklist