Using a HashMap in tracing log

Hi, I'm currently trying to port a project from slog to tracing but I'm facing an issue.

we have this kind of log:

info!("some msg"; &kv);

kv being a wrapper around a HashMap that implements slog::KV so the HashMap's keys become what would be a Field in tracing's terminology and the values as Value

Looking around the doc, it seems that I would not be able to just pass the HashMap to the macro and I would need to add a field name? Something like this:

tracing::info!(map = &kv, "my msg");

Am I missing something?

I believe it should work if both the key and value of the hash map implement valuable::Valuable.

Thanks for your answer!

Unfortunately, valuable is unstable, guess we'll stick with slog for now :slight_smile:

Valuable is used by tracing. A new incompatible version of valuable will require a new incompatible version of tracing, which in turn requires a new major version of tokio. Given the stability guarantees of tokio (3 years after initial release before new major release, 5 years support) you can consider valuable pretty stable too.

My hierarchy will not be OK with this:

(and me neither :slight_smile: )

By pure cusiosity, I made a test project to use valuable, but it seems that even with HashMap<String, String>, String implements Valuable, it can't destructure the hashmap so each key-value pair becomes a Field.

I see. Didn't realize it was an unstable feature.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.