librasn / rasn

A Safe #[no_std] ASN.1 Codec Framework
Other
210 stars 49 forks source link

Adding optional tracing #328

Open Nicceboy opened 1 month ago

Nicceboy commented 1 month ago

For debugging purposes, it would be exceptionally useful if we add, for example tracing support as an optional compile-time feature. It will come with performance cost but reduces the need to split complex types for smaller parts to see what is wrong.

E.g. every encode/decode method could log the value, constraints, encoded length and encoded value bytes.

XAMPPRocky commented 1 month ago

Thank you for your issue! I'm unsure about it being a compile-time feature due to it creating a lot of code complexity. I think we can start with it included by default, and then run benchmarks on how much impact it would have, that would give us an informed opinion of the cost of having it there but not in use.

Nicceboy commented 1 month ago

#![no_std] is likely the primary challenge again. Probably the shared functionality can be added as without feature requirements and then add default stdout or file-based subscriber as std feature.

XAMPPRocky commented 1 month ago

tracing is no_std. https://docs.rs/tracing/latest/tracing/#crate-feature-flags

Nicceboy commented 1 month ago

It is, but it cannot do anything useful without subscriber? E.g. write logs to file or print to stdout.

XAMPPRocky commented 1 month ago

Right, but we're a library, we don't need to setup a subscriber. Applications setup the subscriber.

Nicceboy commented 1 month ago

Right, but we're a library, we don't need to setup a subscriber. Applications setup the subscriber.

Yeah, I think I was too focused on some easy default. I can try to implement this without subscriber at some point by using tracing crate.

XAMPPRocky commented 1 month ago

Yeah, you don't want to have a subscriber in the library because you want to give applications the maximum flexibility of where they log to. We can of course setup the benches and some tests with a subscriber of course for our own debugging.