I'm trying to measure how long function's decorated with tracing::instrument but
in wasm I can't get timing from the FmtSpan::CLOSE event. It triggers a panic because it uses std::time::Instant which is not available in wasm land.
I tried creating a web_time::Instant::now() in a custom Layer in the on_enter method. Then setting it to a field in on_exitand on_close like:
fn on_enter(..) {
...
span.extensions_mut().insert(Instant::now());
}
fn on_exit(..) { // also `on_close`
if let Some(start_time) = span.extensions().get::<StartTime>() {
let elapsed = start_time.0.elapsed();
let duration_ms = elapsed.as_secs_f64() * 1000.0;
drop(span.extensions()); // Release the borrow
tracing::Span::current().reecord("duration_ms", duration_ms)
}
}
But this didn't work. In fact I never see the fields added when I do Span::current().record(..) in on_exit or on_record.
So any suggestions would be greatly appreciated. Thanks!