sentry-rust icon indicating copy to clipboard operation
sentry-rust copied to clipboard

eyre and color-eyre integration

Open kellpossible opened this issue 4 years ago • 3 comments

It would be good to have support for eyre/color-eyre too along with #180

kellpossible avatar Sep 26 '20 20:09 kellpossible

Maintainer of eyre/color-eyre here. At work we're in the process of integrating sentry with our application. I got some basic integration setup but the sentry UI doesn't seem to parse ansi codes, so I'm leaning towards writing our own panic integration rather than relying on color-eyre's panic reporting. I haven't really figured out what level of integration I want to get out of eyre::Reports, I'll have to look into how the anyhow integration is setup.

Once we've got it figured out though I'll be happy to upstream any integration we end up writing.

Here's what a color-eyre report looks like in the sentry UI:

Screenshot from 2020-12-08 15-10-20

Using this minimal setup code (ty again for the API @kellpossible ^_^):

        let builder = color_eyre::config::HookBuilder::default()
            .theme(theme)
            .issue_url(concat!(env!("CARGO_PKG_REPOSITORY"), "/issues/new"))
            .add_issue_metadata("version", env!("CARGO_PKG_VERSION"))
            .add_issue_metadata("git commit", Self::git_commit())
            .issue_filter(|kind| match kind {
                color_eyre::ErrorKind::NonRecoverable(_) => true,
                color_eyre::ErrorKind::Recoverable(error) => {
                    !error.is::<tower::timeout::error::Elapsed>()
                }
            });

        let (panic_hook, eyre_hook) = builder.into_hooks();
        eyre_hook.install().unwrap();

        // The Sentry default config pulls in the DSN from the `SENTRY_DSN`
        // environment variable.
        let guard = sentry::init(
            sentry::ClientOptions {
                debug: true,
                ..Default::default()
            }
            .add_integration(sentry_tracing::TracingIntegration::default()),
        );

        std::panic::set_hook(Box::new(move |panic_info| {
            let panic_report = panic_hook.panic_report(panic_info).to_string();
            let event = sentry::protocol::Event {
                exception: vec![sentry::protocol::Exception {
                    ty: "panic".into(),
                    mechanism: Some(sentry::protocol::Mechanism {
                        ty: "panic".into(),
                        handled: Some(false),
                        ..Default::default()
                    }),
                    value: Some(panic_report),
                    stacktrace: sentry::integrations::backtrace::current_stacktrace(),
                    ..Default::default()
                }]
                .into(),
                level: sentry::Level::Fatal,
                ..Default::default()
            };
            sentry::capture_event(event);
 
            // required because we use `panic = abort`
            if !guard.close(None) {
                warn!("unable to flush sentry events during panic");
            }
        }));

        panic!("fancy foo");

yaahc avatar Dec 08 '20 23:12 yaahc

Is there an eyre counterpart for sentry_anyhow::capture_anyhow?

raine avatar Jul 14 '23 21:07 raine

Is there an eyre counterpart for sentry_anyhow::capture_anyhow?

Sorry for the long delay. No, there isn't, at least not within Sentry.

loewenheim avatar Aug 03 '23 11:08 loewenheim