diff --git a/core/src/event.rs b/core/src/event.rs index 70033de..15e2dcd 100644 --- a/core/src/event.rs +++ b/core/src/event.rs @@ -39,14 +39,6 @@ impl<'a, P: Props> Event<'a, P> { } } - pub fn ts(&self) -> Option { - self.extent().map(|ts| *ts.end()) - } - - pub fn tss(&self) -> Option { - self.extent().and_then(|ts| ts.start().cloned()) - } - pub fn extent(&self) -> Option<&Extent> { self.ts.as_ref() } @@ -71,16 +63,27 @@ impl<'a, P: Props> Event<'a, P> { &'kv self, mut for_each: F, ) { - if let Some(ref ts) = self.ts { - if let Some(start) = ts.start() { - for_each(TSS_KEY.to_key(), start.to_value()); + let mut reserved = || { + if let Some(ref ts) = self.ts { + if let Some(ts) = ts.to_point() { + for_each(TS_KEY.to_key(), ts.to_value())?; + } else { + let ts = ts.as_span(); + + for_each(TSS_KEY.to_key(), ts.start.to_value())?; + for_each(TS_KEY.to_key(), ts.end.to_value())?; + } } - for_each(TS_KEY.to_key(), ts.end().to_value()); - } + for_each(TPL_KEY.to_key(), self.tpl.to_value())?; + for_each(MSG_KEY.to_key(), Msg::new_ref(self).to_value())?; + + ControlFlow::Continue(()) + }; - for_each(TPL_KEY.to_key(), self.tpl.to_value()); - for_each(MSG_KEY.to_key(), Msg::new_ref(self).to_value()); + if let ControlFlow::Break(()) = reserved() { + return; + } self.props.for_each(for_each); } diff --git a/core/src/time.rs b/core/src/time.rs index 340fecf..4e5e6cf 100644 --- a/core/src/time.rs +++ b/core/src/time.rs @@ -1,4 +1,4 @@ -use core::{cmp, fmt, ops::RangeInclusive, str, str::FromStr, time::Duration}; +use core::{cmp, fmt, ops::Range, str, str::FromStr, time::Duration}; use crate::{ empty::Empty, @@ -62,14 +62,14 @@ pub struct Extent(ExtentInner); #[derive(Clone)] enum ExtentInner { - Point(Timestamp), - Span(RangeInclusive), + Point(Range), + Span(Range), } impl fmt::Debug for Extent { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.0 { - ExtentInner::Point(ts) => fmt::Debug::fmt(&ts, f), + ExtentInner::Point(ref ts) => fmt::Debug::fmt(&ts.start, f), ExtentInner::Span(ref ts) => fmt::Debug::fmt(ts, f), } } @@ -78,11 +78,11 @@ impl fmt::Debug for Extent { impl fmt::Display for Extent { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.0 { - ExtentInner::Point(ts) => fmt::Display::fmt(&ts, f), + ExtentInner::Point(ref ts) => fmt::Display::fmt(&ts.end, f), ExtentInner::Span(ref ts) => { - fmt::Display::fmt(ts.start(), f)?; - write!(f, "..=")?; - fmt::Display::fmt(ts.end(), f) + fmt::Display::fmt(&ts.start, f)?; + write!(f, "..")?; + fmt::Display::fmt(&ts.end, f) } } } @@ -90,28 +90,28 @@ impl fmt::Display for Extent { impl Extent { pub fn point(ts: Timestamp) -> Extent { - Extent(ExtentInner::Point(ts)) + Extent(ExtentInner::Point(ts..ts)) } - pub fn span(ts: RangeInclusive) -> Extent { - if ts.start() == ts.end() { - Extent::point(*ts.end()) + pub fn span(ts: Range) -> Extent { + if ts.start == ts.end { + Extent::point(ts.end) } else { Extent(ExtentInner::Span(ts)) } } - pub fn start(&self) -> Option<&Timestamp> { + pub fn as_span(&self) -> &Range { match self.0 { - ExtentInner::Point(_) => None, - ExtentInner::Span(ref ts) => Some(ts.start()), + ExtentInner::Point(ref ts) => ts, + ExtentInner::Span(ref ts) => ts, } } - pub fn end(&self) -> &Timestamp { + pub fn to_point(&self) -> Option<&Timestamp> { match self.0 { - ExtentInner::Point(ref ts) => ts, - ExtentInner::Span(ref ts) => ts.end(), + ExtentInner::Point(ref ts) => Some(&ts.start), + ExtentInner::Span(_) => None, } } } @@ -128,14 +128,14 @@ impl<'a> From<&'a Timestamp> for Extent { } } -impl From> for Extent { - fn from(span: RangeInclusive) -> Extent { +impl From> for Extent { + fn from(span: Range) -> Extent { Extent::span(span) } } -impl<'a> From<&'a RangeInclusive> for Extent { - fn from(span: &'a RangeInclusive) -> Extent { +impl<'a> From<&'a Range> for Extent { + fn from(span: &'a Range) -> Extent { Extent::span(span.clone()) } } diff --git a/src/macro_hooks.rs b/src/macro_hooks.rs index 4fddff7..d23b504 100644 --- a/src/macro_hooks.rs +++ b/src/macro_hooks.rs @@ -2,7 +2,7 @@ use core::{ any::Any, fmt, future::Future, - ops::{ControlFlow, RangeInclusive}, + ops::{ControlFlow, Range}, }; use emit_core::{ @@ -386,7 +386,7 @@ impl EventExtent for Timestamp { } } -impl EventExtent for RangeInclusive { +impl EventExtent for Range { fn to_extent(&self) -> Option { Some(Extent::span(self.clone())) } @@ -424,7 +424,7 @@ pub fn __private_span_start() -> Option { pub fn __private_span_end(start: Option) -> Option { let end = ambient::get().now(); - start.and_then(|start| end.map(|end| Extent::span(start..=end))) + start.and_then(|start| end.map(|end| Extent::span(start..end))) } #[repr(transparent)] diff --git a/targets/otlp/src/logs.rs b/targets/otlp/src/logs.rs index 0d3ae0c..0b4b5ac 100644 --- a/targets/otlp/src/logs.rs +++ b/targets/otlp/src/logs.rs @@ -64,7 +64,7 @@ impl emit_core::target::Target for OtlpLogsTarget { fn event(&self, evt: &emit_core::event::Event

) { let time_unix_nano = evt .extent() - .map(|ts| ts.end()) + .map(|ts| ts.as_span().end) .map(|ts| ts.to_unix().as_nanos() as u64) .unwrap_or_default();