Skip to content

eyre and color-eyre integration #270

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

Closed
kellpossible opened this issue Sep 26, 2020 · 4 comments
Closed

eyre and color-eyre integration #270

kellpossible opened this issue Sep 26, 2020 · 4 comments

Comments

@kellpossible
Copy link

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

@yaahc
Copy link

yaahc commented Dec 8, 2020

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");

MTRNord added a commit to erooster-mail/erooster that referenced this issue May 31, 2022
@raine
Copy link

raine commented Jul 14, 2023

Is there an eyre counterpart for sentry_anyhow::capture_anyhow?

@loewenheim
Copy link
Contributor

Is there an eyre counterpart for sentry_anyhow::capture_anyhow?

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

@szokeasaurusrex
Copy link
Member

Hi all, we have decided to close this issue for now. While this is a legitimate feature request, our team likely will not have the capacity to implement and support this new feature anytime in the near future.

We would gladly be willing to accept PRs for this feature, but since we are not planning to implement this feature ourselves, I am closing the issue for now.

@szokeasaurusrex szokeasaurusrex closed this as not planned Won't fix, can't repro, duplicate, stale Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants