Skip to content

Errors are silently discarded if tracing event gets converted to a message and in breadcrumbs #702

Closed
@thomaseizinger

Description

@thomaseizinger

Environment

  • Version 0.34.0

Steps to Reproduce

  1. Create an event-filter that maps WARN logs to Sentry events: https://github.com/firezone/firezone/blob/51d92265f4163967c0045f67495954515da15c62/rust/logging/src/lib.rs#L102-L115
  2. Attach errors as &dyn std::error::Error in a WARN log as advised in the documentation: https://github.com/firezone/firezone/blob/51d92265f4163967c0045f67495954515da15c62/rust/gateway/src/eventloop.rs#L80

Expected Result

To receive a Sentry event that contains the error.

Actual Result

A Sentry event that only contains the log message but not the error:

Image


I've been digging through the source code here and the problem is that when a tracing event gets converted to a Sentry event, all fields apart from what is prefixed with tags. gets silently dropped:

/// Creates an [`Event`] 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()
}
}

This is pretty confusing because the documentation clearly states:

To track error structs, assign a reference to error trait object as field in one of the logging macros. By convention, it is recommended to use the ERROR level and assign it to a field called error, although the integration will also work with all other levels and field names.

What is perhaps missing here is a foot-note that it will work with all levels as long as you configure an event filter that converts the event to a sentry exception! However, instead of fixing the documentation here, I think the proper fix is to actually make this work the way the documentation states and attach the exception to the message, even if the log level is not ERROR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't workingTraces

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions