tracing-dynamic
:warning: Read this before using this library :warning:
This is a small library to allow you to create dynamic attributes on spans and events.
Things to consider before using this:
- It will leak memory. This happens on each instantiation of SpanFactory or EventFactory. You'll want to create factories sparingly and reuse them.
- I didn't test it in a real program.
- It'll be slower than the tracing macros, but you came here for flexibility right?
If after reading the above you want to try it, here's how you can use it:
= "0.3.1"
use ;
// Some dynamic attributes, these could be read from a file or a database.
let attrs = vec!;
// Factories leak, create these once and reuse them.
let span_factory = new;
let event_factory = new;
let subscriber = fmt.pretty.finish;
with_default;
Output
2023-10-30T08:44:52.178162Z INFO event_target: dyn_attr_1: "dyn_attr_1", dyn_attr_2: "dyn_attr_2"
in span_target::span_name with dyn_attr_1: "dyn_attr_1", dyn_attr_2: "dyn_attr_2"