diff --git a/casper-server/src/lua/trace.rs b/casper-server/src/lua/trace.rs index bf7a634..d324f65 100644 --- a/casper-server/src/lua/trace.rs +++ b/casper-server/src/lua/trace.rs @@ -46,6 +46,14 @@ impl UserData for LuaCurrentSpan { Ok(()) }) }); + + // Update the span name. + methods.add_method_mut("update_name", |_, _, name: String| { + get_active_span(|span| { + span.update_name(name); + Ok(()) + }) + }); } } @@ -208,6 +216,33 @@ mod tests { Ok(()) } + #[test] + #[serial] + fn test_current_span_update_name() -> Result<()> { + let lua = Lua::new(); + let trace = super::create_module(&lua)?; + + let (tracer, provider, exporter) = build_test_tracer(); + global::set_tracer_provider(provider); + + tracer.in_span("root", |_cx| { + lua.load(chunk! { + local span = $trace.current_span + span:update_name("new_root") + }) + .exec() + .unwrap(); + }); + + global::shutdown_tracer_provider(); // flush all spans + let spans = exporter.0.lock().unwrap(); + assert_eq!(spans.len(), 1); + let span = &spans[0]; + assert_eq!(span.name, "new_root"); + + Ok(()) + } + #[test] #[serial] fn test_new_span() -> Result<()> {