I am using trying to update a value in a span. I found https://docs.rs/tracing/latest/tracing/struct.Span.html#method.record where it says: However, it may also be used to record a new value for a field whose value was already recorded (with a example is_okay).
I basically want to do the same thing:
I have a function where I iterate over some steps. I want to log the name of the step that is processed. Instead of creating a new sub-span under my parent-span with the respective step name. I just want to modify step in parent-span directly.
I expect the following logs:
parent{trace_id=1, step=""} Start executing
parent{trace_id=1, step="stepA"} going to the ice cream shop
parent{trace_id=1, step="stepB"} buying ice cream
parent{trace_id=1, step="stepC"} delicious
however, I get:
parent{trace_id=1, step=""} Start executing
parent{trace_id=1, step="stepA"} going to the ice cream shop
parent{trace_id=1, step="stepA", step="stepB"} buying ice cream
parent{trace_id=1, step="stepA", step="stepB", step="stepC"} delicious
Isn't that in contrast to the docu, which says that the value is updated ? Instead I end with multiple step.
The span is created like:
let future = /* ... */;
let future = future.instrument(tracing::span!(
Level::INFO,
"reconcile",
id,
step = tracing::field::Empty
));
let result = future.await;
and updated like:
tracing::Span::current().record("step", tracing::field::debug(&step_name));