Godot Sentry Crash reporting

Viewed 325

I'm currently working on a small project in which I'd like to catch crashes using sentry. The project is using the c# implementation for Godot.

Sentry needs to wrap all executing code to catch exceptions.

Is there a general entrypoint where I can place this try/catch block or would I need to add this into every section of the code that is being called by Godot?

Thanks in advance :)

2 Answers

Once it's set-up, the Sentry C# client attaches itself to some dotnet framework exception hooks, like AppDomain.UnhandledException.

So, you're not required to plant try / catch clauses anywhere.

Just initialize the SentrySDK object like this:

SentrySdk.Init(o => {
    o.Dsn = new Dsn("https://451cf9b0fd9e4f0294a0d15b6c36bce2@sentry.io/5170198");
});

And the framework should invoke Sentry and create a report on its own.

I recently wrote an article demonstrating just that.

I have recently implemented Sentry SDK but AppDomain.UnhandledException doesn't work in Godot C# mono implementation. You have to manually catch unhandled exceptions like this:

SentrySdk.Init(opts => { opts.Dsn = "<sentry dsn url>"; });

GD.UnhandledException += (sender, args) => {
    if (SentrySdk.IsEnabled) {
        SentrySdk.CaptureException(args.Exception);
    }
};

This was added in Godot 3.3+ version https://github.com/godotengine/godot/pull/46174

Related