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

Android: synchronize App context to native

Open vaind opened this issue 3 years ago • 4 comments

Problem Statement

While working on a similar feature for sentry-unity SDK, I've noticed some context is synced to native crashes (namely Device) while the App context is missing. It would be useful to get the App information discovered by the java layer passed to native so that any crashes have the info.

Current state:

Solution Brainstorm

No response

vaind avatar May 18 '22 19:05 vaind

The App context is added via an event processor https://github.com/getsentry/sentry-java/blob/main/sentry-android-core/src/main/java/io/sentry/android/core/DefaultAndroidEventProcessor.java One of the reasons why it's not added to the event is that if the app has updated, the version, app start time, version code, etc are going to be wrong and you'll be debugging an older version. Ideally, all this device context should be passed to sentry-native during init time, so the data is available before crashing.

marandaneto avatar May 20 '22 11:05 marandaneto

Ideally, all this device context should be passed to sentry-native during init time, so the data is available before crashing.

Yes, that's what I'm doing now for other SDKs in unity

vaind avatar May 20 '22 16:05 vaind

https://github.com/getsentry/sentry-unity/blob/6322d6b6e5701d8dad143eac0efe0453f1b84b20/src/Sentry.Unity.Native/NativeContextWriter.cs may serve as an example of how to pass it to sentry-native

May need to be done in background as not to slow down app start.

@marandaneto will start a docs page for this.

adinauer avatar Jun 22 '22 14:06 adinauer

We could reuse what @stefanosiano has done for testing the Java and C layer and write an integration test that runs on Sauce Labs or emulator.

adinauer avatar Jun 22 '22 14:06 adinauer

In the first iteration we could just provide the static App context data on SDK init.

markushi avatar Feb 15 '23 15:02 markushi

Let's wait for ANRv2 as we can already re-use the background worker to sync the data to sentry-native.

markushi avatar Feb 15 '23 15:02 markushi