Skip to content
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

[Feature Request] Structured logging (KV) support #70

Open
SpriteOvO opened this issue Jul 25, 2024 · 3 comments
Open

[Feature Request] Structured logging (KV) support #70

SpriteOvO opened this issue Jul 25, 2024 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@SpriteOvO
Copy link
Owner

SpriteOvO commented Jul 25, 2024

Structured logging enhances traditional text-based log records with user-defined attributes. Structured logs can be analyzed using a variety of data processing techniques, without needing to find and parse attributes from unstructured text first.

With JsonFormatter (PR #69) added, the KV can be injected into the output logs as a separated JSON object for parsing by third-party programs.

Implementation

Working in PR #77.

Details

There are multiple possible implementations for kv::Value: enum (like serde_json::Value), std::any, log::kv::Value (based on crate value-bag), which one is better?

Reference

A reference is the log kv implementation, we can see if we can improve anything base on that, and tracing's fields (thanks @AlexTMjugador).

There are more references in rust-lang/log#343.

@SpriteOvO SpriteOvO added the enhancement New feature or request label Jul 25, 2024
@SpriteOvO SpriteOvO added this to the v0.5.0 milestone Jul 25, 2024
@SpriteOvO
Copy link
Owner Author

SpriteOvO commented Nov 19, 2024

I've started this work today, and trying the first step - implementing kv::Value. Basically I want to make sure that a kv::Value is downcastable and stored at almost zero cost.

There are multiple possible implementations, I'll try to summarize and keep updating the pros and cons of them here.

  • Make a enum like serde_json::Value ourselves

    I prefer not to do this because it requires a lot of code to be written and a lot of effort to keep them interactive.

  • Use std::any

    Consider how to support it for user-defined types? And if we need to support external traits (like serde) we need to write some code for that as well.

  • Use value-bag

    Its implementation is a bit like enum + any, and external traits are available out of the box. This seems pretty cool. The only drawback is that it comes from an external crate, should we wrap it or just expose it to the user?

I'm going to try value-bag first.

@AlexTMjugador
Copy link

AlexTMjugador commented Nov 20, 2024

Hello! I just happened to notice that the issue I reported about log's KV downcasting was mentioned here, and I figured that I could give my two cents here: the more feature-rich tracing crate also supports structured logging, allowing events (basically, log records) to include typed fields identified by name. This might be worth considering as a reference for implementation as well.

@SpriteOvO
Copy link
Owner Author

@AlexTMjugador Hi, I'm happy to know that you saw this issue. 😄 Yes, tracing has a large user base and is practically tested, so I'm learning about its implementation of kv as well. Thank you for the information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants