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

Detect app crashed last session

Open pistoleta opened this issue 2 years ago • 12 comments

Currently OOM crashes are sent on app restart before the scope is set. Since seems is not possible to bind that event to the scope... It would be really helpful I we could ask the SDK if there has been a crash on last session somehow, and then ourselves could send a different event like... 'This user (probably) had a OOM' In which we would bind the scope..attach the device logs and everything we need to find what was the player doing. This would be really helpful on beta testing to find memory sensitive spots during the game.

Thanks!

pistoleta avatar May 11 '22 08:05 pistoleta

Hey @pistoleta and thanks for raising this. To provide more information (from the discussion on Discord): The OOM issue coming through the Cocoa SDK is based on heuristics. The SDK sends this during start-up and the C# layer never gets to see it/apply any additional information to it. The reason it is currently done like this: Since it's based on heuristics about the previous run, there is very little context information that is guaranteed to be correct. Instead of reporting possibly wrong information, the SDK opts not to include them.

We will be looking into what context information actually persists (hardware is unlikely to have changed) and how to communicate the event between SDKs.

bitsandfoxes avatar May 12 '22 10:05 bitsandfoxes

@pistoleta, what you could do already now is use beforeSend on the native layer and check if it's an OOM. Then you could add extra information to this event. We don't have the possibility to add attachments in beforeSend yet, but we are soonish going to add this to Android. For iOS, I can't give you an ETA yet.

philipphofmann avatar May 12 '22 14:05 philipphofmann

I could detect if its a OOM in the BeforeSend and set a flag to send a full report with the full context once the user has been identified then!

pistoleta avatar May 12 '22 16:05 pistoleta

I'm trying to set a breakpoint in the BeforeSend while debugging on device to see how to discern between OOM exceptions but maybe the BeforeSend is being attached before the IDE is able to connect with the Unity process... How could I know from the BeforeSend if what's being sent is an OOM event?

pistoleta avatar May 12 '22 17:05 pistoleta

The BeforeSend @philipphofmann is referring to is the one from the Cocoa SDK. You'd need to extend the generated Xcode with your own functionality.

bitsandfoxes avatar May 13 '22 07:05 bitsandfoxes

Unfortunately I don't have the knowledge but I could try, it would be enough by setting some flag in playerPrefs for example. Would this be possible to do in the cocoa sdk layer and retreive it from the unity one?

pistoleta avatar May 13 '22 11:05 pistoleta

We would also benefit a lot from this feature

BenWilles avatar May 14 '22 15:05 BenWilles

@philipphofmann could you point me where's the beforeSend method in the cocoa sdk?

pistoleta avatar May 16 '22 12:05 pistoleta

Captura de Pantalla 2022-05-17 a las 10 24 51

It would really help us finding the cause of this issues

pistoleta avatar May 17 '22 08:05 pistoleta

@philipphofmann could you point me where's the beforeSend method in the cocoa sdk?

The BeforeSend is a callback and part of the options object, just like in the Unity SDK. When you build for iOS we generate Objective-C options from the ones you set in Unity and write them to a file called SentryOptions.m. You could try to modify that file and implement your BeforeSend callback there to see if that works for you. Just be careful - the file is auto-generated and changes to it might get lost when triggering new builds from within Unity.

bitsandfoxes avatar May 17 '22 11:05 bitsandfoxes

Seriously, given the risks and possible updates by your side I find it a little bit ridiculous. We are not asking too much, is it that hard to simply set a flag from the native BeforeSend so we can retreive it from unity side? I doubt is more than 1 line to add it to PlayerPrefs for example... We don't need a sophisticated solution right now just a way to know the device that has sent an OOM. Thanks

pistoleta avatar May 19 '22 18:05 pistoleta

Hey @pistoleta, sorry to be the source of your frustration. I can see where you are coming from and I'd be more than happy to just add that feature but it's just not that simple. Currently, there is no way to grab the flag you're asking for from the Cocoa SDK and provide it to the Unity SDK.

We intend to add some cross SDK sync functionality in the future, it's just not there yet.

bitsandfoxes avatar May 20 '22 21:05 bitsandfoxes