Skip to content

Commit 2d9db3e

Browse files
committed
Add current_span:update_name method to Lua
1 parent d5bfcc2 commit 2d9db3e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

casper-server/src/lua/trace.rs

+35
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ impl UserData for LuaCurrentSpan {
4646
Ok(())
4747
})
4848
});
49+
50+
// Update the name of this (current) span.
51+
methods.add_method_mut("update_name", |_, _, name: String| {
52+
get_active_span(|span| {
53+
span.update_name(name);
54+
Ok(())
55+
})
56+
});
4957
}
5058
}
5159

@@ -208,6 +216,33 @@ mod tests {
208216
Ok(())
209217
}
210218

219+
#[test]
220+
#[serial]
221+
fn test_current_span_update_name() -> Result<()> {
222+
let lua = Lua::new();
223+
let trace = super::create_module(&lua)?;
224+
225+
let (tracer, provider, exporter) = build_test_tracer();
226+
global::set_tracer_provider(provider);
227+
228+
tracer.in_span("root", |_cx| {
229+
lua.load(chunk! {
230+
local span = $trace.current_span
231+
span:update_name("new_root")
232+
})
233+
.exec()
234+
.unwrap();
235+
});
236+
237+
global::shutdown_tracer_provider(); // flush all spans
238+
let spans = exporter.0.lock().unwrap();
239+
assert_eq!(spans.len(), 1);
240+
let span = &spans[0];
241+
assert_eq!(span.name, "new_root");
242+
243+
Ok(())
244+
}
245+
211246
#[test]
212247
#[serial]
213248
fn test_new_span() -> Result<()> {

0 commit comments

Comments
 (0)