Skip to content

Commit

Permalink
remove Context argument from breadcrumb_from_event
Browse files Browse the repository at this point in the history
  • Loading branch information
tsionyx committed Dec 5, 2023
1 parent 7ba8dee commit 3c65139
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
34 changes: 17 additions & 17 deletions sentry-tracing/src/converters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ fn level_to_exception_type(level: &tracing_core::Level) -> &'static str {

/// Extracts the message and metadata from an event
/// and also optionally from its spans chain.
fn extract_event_data<S>(
event: &tracing_core::Event,
ctx: Option<Context<S>>,
) -> (Option<String>, FieldVisitor)
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
fn extract_event_data(event: &tracing_core::Event) -> (Option<String>, FieldVisitor) {
// Find message of the event, if any
let mut visitor = FieldVisitor::default();
event.record(&mut visitor);
Expand All @@ -50,6 +44,18 @@ where
.or_else(|| visitor.json_values.remove("error"))
.and_then(|v| v.as_str().map(|s| s.to_owned()));

(message, visitor)
}

fn extract_event_data_with_context<S>(
event: &tracing_core::Event,
ctx: Option<Context<S>>,
) -> (Option<String>, FieldVisitor)
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
let (message, mut visitor) = extract_event_data(event);

// Add the context fields of every parent span.
let current_span = ctx.as_ref().and_then(|ctx| {
event
Expand Down Expand Up @@ -147,14 +153,8 @@ impl Visit for FieldVisitor {
}

/// Creates a [`Breadcrumb`] from a given [`tracing_core::Event`]
pub fn breadcrumb_from_event<'context, S>(
event: &tracing_core::Event,
_ctx: impl Into<Option<Context<'context, S>>>,
) -> Breadcrumb
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
let (message, visitor) = extract_event_data::<S>(event, None);
pub fn breadcrumb_from_event(event: &tracing_core::Event) -> Breadcrumb {
let (message, visitor) = extract_event_data(event);
Breadcrumb {
category: Some(event.metadata().target().to_owned()),
ty: "log".into(),
Expand Down Expand Up @@ -230,7 +230,7 @@ pub fn event_from_event<'context, S>(
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
let (message, mut visitor) = extract_event_data(event, ctx.into());
let (message, mut visitor) = extract_event_data_with_context(event, ctx.into());

Event {
logger: Some(event.metadata().target().to_owned()),
Expand All @@ -254,7 +254,7 @@ where
// proper grouping and issue metadata generation. tracing_core::Record does not contain sufficient
// information for this. However, it may contain a serialized error which we can parse to emit
// an exception record.
let (mut message, visitor) = extract_event_data(event, ctx.into());
let (mut message, visitor) = extract_event_data_with_context(event, ctx.into());
let FieldVisitor {
mut exceptions,
mut json_values,
Expand Down
2 changes: 1 addition & 1 deletion sentry-tracing/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ where
match (self.event_filter)(event.metadata()) {
EventFilter::Ignore => EventMapping::Ignore,
EventFilter::Breadcrumb => {
EventMapping::Breadcrumb(breadcrumb_from_event(event, span_ctx))
EventMapping::Breadcrumb(breadcrumb_from_event(event))
}
EventFilter::Event => EventMapping::Event(event_from_event(event, span_ctx)),
EventFilter::Exception => {
Expand Down

0 comments on commit 3c65139

Please sign in to comment.