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

Enrich Android event with device context when hard crash happens (signal handler)

Open marandaneto opened this issue 4 years ago • 3 comments

Description

Enrich Android event with device context when hard crash happens (signal handler)

When does the problem happen

When there's a hard crash, sentry-native writes a file to the disk and Android enriches this event on restart, but some non-static data can't be read accurately anymore like freeMemory/isLowMemory, etc... Some other data would be nice to be read before crashing too like connectivity status, likely the connectivity status is the same if the user opens the App. right away, but it might give wrong values as well if the device just lost connection.

  • [ ] During build
  • [X] During run-time
  • [ ] When capturing a hard crash

Environment

Any Android device/emulator

Steps To Reproduce

Cause an NDK hard crash (segfault)

Log output

See the event on sentry, if it crashes because of OOM, the freeMemory is high and isLowMemory is false.

marandaneto avatar Apr 19 '21 09:04 marandaneto

If the API changed across Android versions, we can support only 21+ which is 90%+ devices.

bruno-garcia avatar May 12 '21 13:05 bruno-garcia

I think this would require some more investigation effort, as it's unclear if this is even possible to call the Java layer within the signal handler.

markushi avatar Sep 27 '23 10:09 markushi

I think this would require some more investigation effort, as it's unclear if this is even possible to call the Java layer within the signal handler.

all the static data (what does not change, e.g. os version, model, etc.) can be passed to sentry native when sentry native is init. and keep it cached, so before writing to the disk, you can read that, so the file is already written with all the static data. for the dynamic data, you cannot call Java from NDK because the signal handler breaks the JNI bridge, yes, but NDK still can read every dynamic data similarly to the Java layer, you can access all the Android APIs from NDK as well, but then you duplicate a lot of code in C, its a trade-off.

marandaneto avatar Sep 27 '23 10:09 marandaneto