Skip to content

refactor(tracing): remove EventFilter::exception and always attach exception #768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions sentry-tracing/src/converters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,27 @@ where
S: Subscriber + for<'a> LookupSpan<'a>,
{
let (message, visitor) = extract_event_data_with_context(event, ctx.into());

let FieldVisitor {
exceptions,
mut json_values,
} = visitor;

let errors = exceptions
.iter()
.rev()
.filter_map(|x| x.value.as_ref().map(|v| format!("{}: {}", x.ty, *v)))
.collect::<Vec<String>>();
if !errors.is_empty() {
json_values.insert("errors".to_owned(), errors.into());
}

Breadcrumb {
category: Some(event.metadata().target().to_owned()),
ty: "log".into(),
level: convert_tracing_level(event.metadata().level()),
message,
data: visitor.json_values,
data: json_values,
..Default::default()
}
}
Expand Down Expand Up @@ -217,31 +232,11 @@ fn contexts_from_event(
context
}

/// Creates an [`Event`] from a given [`tracing_core::Event`]
/// Creates an [`Event`] (possibly carrying an exception) from a given [`tracing_core::Event`]
pub fn event_from_event<'context, S>(
event: &tracing_core::Event,
ctx: impl Into<Option<Context<'context, S>>>,
) -> Event<'static>
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
let (message, mut visitor) = extract_event_data_with_context(event, ctx.into());

Event {
logger: Some(event.metadata().target().to_owned()),
level: convert_tracing_level(event.metadata().level()),
message,
tags: tags_from_event(&mut visitor.json_values),
contexts: contexts_from_event(event, visitor.json_values),
..Default::default()
}
}

/// Creates an exception [`Event`] from a given [`tracing_core::Event`]
pub fn exception_from_event<'context, S>(
event: &tracing_core::Event,
ctx: impl Into<Option<Context<'context, S>>>,
) -> Event<'static>
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
Expand Down
9 changes: 2 additions & 7 deletions sentry-tracing/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ pub enum EventFilter {
Ignore,
/// Create a [`Breadcrumb`] from this [`Event`]
Breadcrumb,
/// Create a message [`sentry_core::protocol::Event`] from this [`Event`]
/// Create a [`sentry_core::protocol::Event`] from this [`Event`]
Event,
/// Create an exception [`sentry_core::protocol::Event`] from this [`Event`]
Exception,
}

/// The type of data Sentry should ingest for a [`Event`]
Expand All @@ -44,7 +42,7 @@ pub enum EventMapping {
/// `warning` and `info`, and `debug` and `trace` logs are ignored.
pub fn default_event_filter(metadata: &Metadata) -> EventFilter {
match metadata.level() {
&Level::ERROR => EventFilter::Exception,
&Level::ERROR => EventFilter::Event,
&Level::WARN | &Level::INFO => EventFilter::Breadcrumb,
&Level::DEBUG | &Level::TRACE => EventFilter::Ignore,
}
Expand Down Expand Up @@ -217,9 +215,6 @@ where
EventMapping::Breadcrumb(breadcrumb_from_event(event, span_ctx))
}
EventFilter::Event => EventMapping::Event(event_from_event(event, span_ctx)),
EventFilter::Exception => {
EventMapping::Event(exception_from_event(event, span_ctx))
}
}
}
};
Expand Down
Loading