Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Unity as a Library does not report crashes/fatals #1727

Open
Esildor opened this issue Jul 16, 2024 · 6 comments
Open

Using Unity as a Library does not report crashes/fatals #1727

Esildor opened this issue Jul 16, 2024 · 6 comments
Labels
Bug Something isn't working Feature New feature or request

Comments

@Esildor
Copy link

Esildor commented Jul 16, 2024

Environment

How do you use Sentry?
Sentry SaaS

Which version of the SDK?
2.1.0

How did you install the package?
Git-URL

Which version of Unity?
6000.0.4f1

Is this happening in Unity (editor) or on a player like Android, iOS, Windows?
Android

Steps to Reproduce

  1. Download and open the Unity as a Library (UaaL) example.
  2. Install Sentry as a package.
  3. Run the setup wizard to ensure the Sentry plugin is activated.
  4. Ensure that Android Native Support is enabled.
  5. Add this script this script to the project. This will add buttons to simulate various crashes via UnityEngine.Diagnostics.Utils.ForceCrash(). To the top left of the screen.
  6. Continue setting up the UaaL project per the instructions in Unity's Github docs
  7. Build and run on a device
  8. Press any of the ForcedCrashCategory buttons, for example: Engine Crash - FatalError, Engine Crash - AccessViolation, etc.

Expected Result

Unity engine-level crashes/fatal issues are reported to Sentry.

Actual Result

No fatal crash is reported. It's also worth noting: Performing these steps in a non-UaaL project reports fatal level crashes to Sentry as expected, see the image below.

Any logs or screenshots

image

@bitsandfoxes
Copy link
Contributor

Thanks @Esildor for reaching out! Tbh I've never tried the UaaL sample. I'll get back to you after giving this a try!

@bitsandfoxes bitsandfoxes added the Bug Something isn't working label Jul 17, 2024
@bitsandfoxes
Copy link
Contributor

This has not been forgotten. I'm working my way through the guide.

@Esildor
Copy link
Author

Esildor commented Jul 29, 2024

Thanks for the update 💖

@bitsandfoxes
Copy link
Contributor

bitsandfoxes commented Oct 8, 2024

We're working on, well, making that work. There are a couple of questions that need to be answered first:

  • How (if) the Unity SDK should sync with the surrounding native SDK
  • Do those SDK share a DSN? Should the Unity SDK just send events one way and not care?
  • Should the scope be de-synced during the game's shutdown. I.e. The native app is some sort of launcher and there are a bunch of Unity games

@bitsandfoxes
Copy link
Contributor

bitsandfoxes commented Oct 18, 2024

I've created a UaaL repro here to have something to work off of.

@bitsandfoxes
Copy link
Contributor

Context

When exporting as a library Unity we have a couple of different things to watch out for:

  1. The Unity game itself is covered by the Unity SDK
  2. Native Android Support should be disabled as to not create conflicts with the surrounding app
  3. The surrounding app brings its own Android SDK that is responsible to capturing native error

Setup for Automatic Native Crash Capture

Number 3 is currently the crux. When exporting as a library, Unity has its own activity to run in

<activity
    android:name=".MainUnityGameActivity"
    android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density"
    android:hardwareAccelerated="false"
    android:process=":Unity"
    android:screenOrientation="fullSensor"></activity>

To get the Android SDK to have the NDK integration running in the separate process we have to follow our "multi process apps" docs and add

<provider
    android:name="io.sentry.android.core.SentryInitProvider"
    android:authorities="${applicationId}.SentryInitProvider"
    android:exported="false"
    android:process=":Unity"
    tools:node="merge"
/>

to the AndroidManifest.xml The process name can be taken directly from the activity.

Gotcha

Add uploadNativeSymbols = true and have the thing set to release in the build variant.

Result

Having followed this setup native crashes do automatically get captured.
But the stacktrace does not look too good.
Image

Open Issues

There are a couple issues remaining, mostly debug symbols and IL2CPP related.

Debug Symbol Upload

The debug symbols automatically uploaded by the Android Gradle Plugin seem to be lacking the debug companions. Uploading the symbols manually after the build via sentry-cli debug-files upload ../uaal-unity/UnityProject/Library/Bee --org sentry-sdks --project sentry-unity fixes that and improves the stacktrace quality.
Image

C# line numbers and IL2CPP Mappings

Because native support during the export is disabled we also don't generate and upload the IL2CPP mappings errors captured by the Unity SDK are missing line numbers.Image but this can be fixed on the SDK side.

C# frames in native crashes

The screenshots of native crashes have a couple of __emutls_get_address frames. Looking at the symbolicated C# exception we can see these as symbols. It looks like we need to find a way to get from the symbols to the actual function during symbolication?

"stacktrace": {
          "frames": [
            {
              "function": "ThrowNull",
              "symbol": "__emutls_get_address",
              "module": "BugFarmButtons",
              "package": "Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
              "in_app": true,
              "data": {
                "symbolicator_status": "symbolicated"
              },
              "instruction_addr": "0x8000000000fd77b0"
            }
          ],
          "instruction_addr_adjustment": "none"

TLDR; What to do?

  1. Improve automatic debug symbol upload when exporting
  • We could either simply upload during export. But I'm not sure if these symbols stay valid after the Android build. Maybe have an additional flag for "symbol upload during export" and we modify the UnityLib gradle file like we would in a regular export.
  1. Fix line numbers in C# error. But that relies on us having a gameplan for 1.
  2. Improve stacktrace quality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Feature New feature or request
Projects
Status: In Progress
Status: No status
Development

No branches or pull requests

3 participants