Skip to content

Conversation

@bitsandfoxes
Copy link
Contributor

@bitsandfoxes bitsandfoxes commented Mar 5, 2025

This came up through user feedback looking for functionality similar to AppCenter's Crashes.GetLastSessionCrashReportAsync().

Snippet on how to consume the API

// This assumes that the SDK is already initialized and that he SDK has already set 
// up the native scope sync - it will return `Unknown` otherwise
var lastRunState = SentrySdk.CrashedLastRun();

switch (lastRunState)
{
    case Sentry.LastRunState.Crashed:
        // Perform recovery actions or show user message.
        break;
        
    case Sentry.LastRunState.DidNotCrash:
        // Operate normally
        break;
        
    case Sentry.LastRunState.Unknown:
        // The SDK was either not initialized or does not have access to the native layer
        break;
}

Also resolves getsentry/sentry-unity#741

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2025

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against ad97662

@bitsandfoxes bitsandfoxes changed the title feat: Added 'SentrySdk.CrashedLastRun' feat: Added SentrySdk.CrashedLastRun Mar 5, 2025
/// <summary>
/// The application did not crash during the last run.
/// </summary>
DidNotCrash,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In .NET (JIT-land) we might return DidNotCrash when in fact the app crashed natively. Since we don't capture native crashes when running on JIT on Windows/Mac/Linux. We do capture native crashes Native AOT, or JIT on Android, for example.

Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we return true if the app crashed with an unhandled C# exception? (On Unity it keeps going, on .NET it crashes)

At first I thought it made sense adding this here too but now thinking to the fact we have this SDK running on UWP and all other weird runtimes where we can't confidently report on this status. It's prob best to keep it on Unity only for now.

@jamescrosswell
Copy link
Collaborator

So this would be a superset of the functionality provided by the native libraries (and wrapped in #3958)? As in, this would work for vanilla .NET applications as well?

Also, presumably not relevant for server side apps (like ASP.NET Core)?

@bruno-garcia
Copy link
Member

Also, presumably not relevant for server side apps (like ASP.NET Core)?

The server could OOM and crash. And we'd say DidNotCrash

@bitsandfoxes
Copy link
Contributor Author

bitsandfoxes commented Mar 6, 2025

Since this came through a Unity SDK user and there we do have confidence in reporting the last run state there, I'm closing this in favour of getsentry/sentry-unity#2049

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

Successfully merging this pull request may close these issues.

Propagate app crashed last session from native layer to managed

4 participants