Skip to content

Commit

Permalink
Add current_span:update_name method to Lua
Browse files Browse the repository at this point in the history
  • Loading branch information
khvzak committed Sep 26, 2024
1 parent d5bfcc2 commit 2d9db3e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions casper-server/src/lua/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ impl UserData for LuaCurrentSpan {
Ok(())
})
});

// Update the name of this (current) span.
methods.add_method_mut("update_name", |_, _, name: String| {
get_active_span(|span| {
span.update_name(name);
Ok(())
})
});
}
}

Expand Down Expand Up @@ -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<()> {
Expand Down

0 comments on commit 2d9db3e

Please sign in to comment.