use std::borrow::Cow;
use crate::local::local_span_stack::LOCAL_SPAN_STACK;
use crate::Span;
pub struct Event;
impl Event {
pub fn add_to_parent<I, F>(name: impl Into<Cow<'static, str>>, parent: &Span, properties: F)
where
I: IntoIterator<Item = (Cow<'static, str>, Cow<'static, str>)>,
F: FnOnce() -> I,
{
#[cfg(feature = "enable")]
{
let mut span = Span::enter_with_parent(name, parent).with_properties(properties);
if let Some(mut inner) = span.inner.take() {
inner.raw_span.is_event = true;
inner.submit_spans();
}
}
}
pub fn add_to_local_parent<I, F>(name: impl Into<Cow<'static, str>>, properties: F)
where
I: IntoIterator<Item = (Cow<'static, str>, Cow<'static, str>)>,
F: FnOnce() -> I,
{
#[cfg(feature = "enable")]
{
LOCAL_SPAN_STACK
.try_with(|stack| stack.borrow_mut().add_event(name, properties))
.ok();
}
}
}