This repository has been archived by the owner on Jun 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
409 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use proc_macro2::TokenStream; | ||
|
||
pub(crate) fn module_tokens() -> TokenStream { | ||
quote!(emit::__private::__private_module!()) | ||
quote!(emit::module!()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
use core::{fmt, str::FromStr}; | ||
|
||
use emit_core::{ | ||
event::Event, | ||
filter::Filter, | ||
props::Props, | ||
value::{FromValue, ToValue, Value}, | ||
well_known::{EVENT_KIND_METRIC, EVENT_KIND_SPAN, KEY_EVENT_KIND}, | ||
}; | ||
|
||
#[non_exhaustive] | ||
#[derive(PartialEq, Eq, Hash, Clone, Copy)] | ||
pub enum Kind { | ||
Span, | ||
Metric, | ||
} | ||
|
||
impl fmt::Debug for Kind { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "\"{}\"", self) | ||
} | ||
} | ||
|
||
impl fmt::Display for Kind { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Kind::Span => f.write_str(EVENT_KIND_SPAN), | ||
Kind::Metric => f.write_str(EVENT_KIND_METRIC), | ||
} | ||
} | ||
} | ||
|
||
impl ToValue for Kind { | ||
fn to_value(&self) -> Value { | ||
Value::capture_display(self) | ||
} | ||
} | ||
|
||
impl<'v> FromValue<'v> for Kind { | ||
fn from_value(value: Value<'v>) -> Option<Self> { | ||
value | ||
.downcast_ref::<Kind>() | ||
.copied() | ||
.or_else(|| value.parse()) | ||
} | ||
} | ||
|
||
impl FromStr for Kind { | ||
type Err = ParseKindError; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
if s.eq_ignore_ascii_case(EVENT_KIND_SPAN) { | ||
return Ok(Kind::Span); | ||
} | ||
|
||
if s.eq_ignore_ascii_case(EVENT_KIND_METRIC) { | ||
return Ok(Kind::Metric); | ||
} | ||
|
||
Err(ParseKindError {}) | ||
} | ||
} | ||
|
||
pub struct ParseKindError {} | ||
|
||
pub struct IsKind(Kind); | ||
|
||
impl IsKind { | ||
pub fn new(kind: Kind) -> Self { | ||
IsKind(kind) | ||
} | ||
} | ||
|
||
pub fn is_span_filter() -> IsKind { | ||
IsKind::new(Kind::Span) | ||
} | ||
|
||
pub fn is_metric_filter() -> IsKind { | ||
IsKind::new(Kind::Metric) | ||
} | ||
|
||
impl Filter for IsKind { | ||
fn matches<P: Props>(&self, evt: &Event<P>) -> bool { | ||
evt.props().pull::<Kind, _>(KEY_EVENT_KIND) == Some(self.0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.