-
Notifications
You must be signed in to change notification settings - Fork 254
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
Tracking issue for kv_unstable (structured logging) #328
Comments
@KodrAus thanks for all the work you've put into this (and linking to this issue from a forum post). I was curious: is there a release planned that includes the beta version of |
Hi @yoshuawuyts! 👋 Right now any release of [dependencies.log]
git = "https://github.com/rust-lang-nursery/log.git"
features = ["kv_unstable"] I think what we need are a few draft PRs in some of these log frameworks that tease out any breaking changes we should make, and then will be able to publish a release that replaces the |
Oh oops, maybe I was being a bit vague. The last release on crates.io was done in October 2018, which means currently no releases ship with In order to help test this feature, it would be nice if there was a release on crates.io with the So my question is: could a version be of P.S. Thanks for taking time out of your day to reply to my questions! |
Ah this sounds fair enough. I think we can get pretty far without needing to break anything, but it's probably going to happen at some point. But right now it is harder for folks to get started with these new APIs, so once #339 lands I'll put together a release so you can depend on it from |
@KodrAus in the top-level post there's an entry about "Explore macro support". Do you have any plans to experiment with this? We've integrated key-value logging in lrlna/femme#1; all that's missing now is a way to create key-value pairs and send them to a logger. Even a small code example would be helpful, but ideally there'd be a small log crate that could work with this. Also: is it perhaps useful to open a separate issue to track/discuss logging macros? edit 2019-07-21: let record = log::Record::builder().key_values(kv_pairs).build();
log::logger().log(&record); |
Ah yes that Opening a separate issue to design macro support sounds like a good idea! We’ve got a couple of constraints but also plenty of opportunity to improve things. |
Macro issue created: #343 |
Created a crate for shared types in key-value logs (to mark pairs of logs) -- https://github.com/yoshuawuyts/log-types. Not sure yet how useful this is, but I think it might be a fun reference of how to create source/key/value structs, and probably a useful experiment (: |
Having some standards around well-known key-value pairs is something I've also been exploring in a little wrapper. It seems like it'll be useful for a more composable logging ecosystem. |
199: remove custom log code in favor of macro crate r=stjepang a=yoshuawuyts This removes our custom log macro code in favor of using [`kv-log-macro`](https://github.com/yoshuawuyts/kv-log-macro). This is a temporary crate that exists only until rust-lang/log#353 lands which enables progress on rust-lang/log#328. Thanks! Co-authored-by: Yoshua Wuyts <[email protected]>
199: remove custom log code in favor of macro crate r=yoshuawuyts a=yoshuawuyts This removes our custom log macro code in favor of using [`kv-log-macro`](https://github.com/yoshuawuyts/kv-log-macro). This is a temporary crate that exists only until rust-lang/log#353 lands which enables progress on rust-lang/log#328. Thanks! Co-authored-by: Yoshua Wuyts <[email protected]>
I'm hesitant to add to the list of todos because I really want this feature, but it might be worth adding fern as another crate to integrate with. I don't use it (I use slog), but it seems like it has quite a lot of usage (600,000+ all time downloads on crates.io). |
trait SourceCount: Source {
fn count(&self) -> usize;
} Rationale is it looks more reasonable to just make it a type-system question whether a certain type has a notion of a count of it's And if that's not the desired use case for making |
@MOZGIII unfortunately a separate trait wouldn't really work because we'd lose the implementation when erasing as
The desire for
Hmm, I don't think the current implementation really supports this kind of scenario because pairs can be visited and fetched at any point. I also don't think it's really desirable to support either, because pairs may be inspected and visited multiple times any expensive work or externally changing information could be confusing to end consumers. |
Given all that, I'm having hard time imagining a case when the |
Any plan to make this stable ? More than 4 years since issue opening. This feature is mandatory for attaching contextual information to logs (user, error id, use case, etc.) that can then be passed as kv to logging/event ingestion systems (ELK, Loki, InfluxDB, etc.). Or any workaround ? |
The workaround is to use the unstable feature, or use the slog crate. |
|
It is better to have a unified log library. I know that the popular ones are |
For structured logging, format strings seem less important, for example: error!("something failed: {:?}", err); The following one is better (syntax of tracing): error!(?err, "something failed"); Forgoing format strings makes macros a lot more pleasant to design. |
It would be great to have a fresh look at anything blocking this and I can't really think of any left 👍 The macros are a bit rough-and-ready, but I think suitable for most use cases. We really should get this out the door. Before stabilizing, I think the next step would be running through a full API review with @Thomasdezeeuw, @JohnTitor and anybody else who might want to participate.
Yeh, I think the issue here is format args producing a string and throwing away its interpolated arguments. It's nice and intuitive to be able to both describe your event and some of the structured data attached to it using some kind of interpolation. This practice is popular in .NET for example, but Rust's |
I can only think of two things that we should think about of the top of my head, but neither should block stabilisation:
I can do that next weekend 👍
Since we're really dependant on rust std lib on this you could ask in rust-lang/rust#99012 for this. Though it might conflict with rust-lang/rust#78356 which was stabilised in 1.71. |
I think this is something that would be reasonable to do 👍
Ah, I think this highlights one thing we definitely need to work on; documentation. You should be able to support
Personally, I think it's ok for
If you have the bandwidth to run over things sometime that would be amazing! I'd be happy to do something a bit more synchronous too or at least do a pass over our docs if that would be helpful? |
I've done a review of the key-value feature in the log crate and opened #584 to discuss some things. Overall I think it looks pretty good and I think we're close to stabilisation. I still want to review the valuebag crate (added dependency), I think I'm going to skip serde and sval as they are much larger and more widely used already. I've also opened #583 containing some small fixes and additions. |
Thanks @Thomasdezeeuw! A good review of |
@KodrAus I took a look at value-bag (from the perspective of using it in the log crate). Overall I think it looks good 👍 For the We could get the size down from 3 to 2 words (on 64 bit) by using tagged pointers, but I don't know if that is worth all the One final note is around the |
Thanks for this work. Looking forward to it being released proper. Some systems generate a significant amount of log data in debug mode, so it might be worth the effort, but personally I wouldn't want a change at this point to hold up release of this feature. It seems more important that structured logging become a stable feature sooner rather than later. |
log is used by over 50000 crates, which means you'll inevitably pull it in as a transitive dependency. I'm therefore concerned about value-bag being added as a dependency here. Will this remain an optional, non-default feature? |
I'm afraid not, it's the core of the Maybe we can move it to the rust-lang org? /cc @KodrAus |
@chloekek I think that's a reasonable concern. In fact, in #613 I've made that dependency fully optional for structured logging, so if you just want to log simple primitives, like numbers, strings, booleans, or formattable values, you won't pull it in. For some background on what that I would happily move that repository anywhere or add any collaborators of |
Tracking issue for the implementation of #296. See also #149
slog
slog::Value
andlog::kv::Value
. We should be able to do zero-allocation conversion fromlog
toslog
, but may need to allocate fromslog
tolog
.tracing
(log: Support structured values tokio-rs/tracing#341)tracing::Value
andlog::kv::Value
in theevent!
macro (Make it easier to create a Value from owned or erased external types #339)std::error::Error
s asValue
sfern
async-log
std-logger
(Print key values Thomasdezeeuw/std-logger#14)Source
has any key-value pairs (Add a count method to Source #329)femme
env_logger
(Add support for Key-Value data in log records. rust-cli/env_logger#137)antlog
(an experimental wrapper to prove out requirements)log!("msg {}", interpolated, { key: value })
(kv macro support #353) - We ended up having to revert this inlog
, but are experimenting externallylog_kv_macro
log_macros
serde
serde::Serialize
andstd::fmt::Debug
(Add key and value methods to DebugMap rfcs#2696). Seeserde_fmt
.sval
(Add structured support to kv::Value using sval #342)Source::count
return aResult<usize>
instead of a plainusize
?The text was updated successfully, but these errors were encountered: