getsentry / sentry-unity

Development of Sentry SDK for Unity
https://docs.sentry.io/platforms/unity/
MIT License
218 stars 52 forks source link

Update initialization behaviour on `mobile` #1907

Open bitsandfoxes opened 3 days ago

bitsandfoxes commented 3 days ago

Programmatic Configuration and Native Support on Mobile

Background

The SDKs current approach let's the native SDKs self-initialize when targeting mobile. This approach guarantees the SDK to capture all errors (even Unity engine crashes) but it also creates a lot of friction for users during onboarding and setup. Having to explain the different layers is a non-trivial task.

Example:

Current State

The Unity SDK currently handles native support differently across platforms:

Mobile Platforms (Android, iOS)

Desktop Platforms (Windows/Linux/macOS)

Proposed Solution

1. Unified Configuration API (mostly done already)

2. Unified SDK Initialization

iOS Implementation

Android Implementation

3. Mobile Platform Auto-Initialization

Convert current auto-initialization to opt-in feature. This way we maintain crash capture capabilities for users who need it.

4. Future Enhancement

Implement native callback support. I.e. enable code/snippet injection for native SDK events (e.g., BeforeSend)

Benefits

  1. Simplified Configuration

    • Single, consistent configuration pattern
    • Eliminates confusion around runtime/build time configuration
  2. Improved Initialization Flow

    • Consistent initialization across all platforms
    • Predictable option handling
  3. Enhanced Flexibility

    • Optional auto-initialization for mobile platforms. So those users that need it can make the educated decision to work with/around the limitations
    • Better UaaL (Unity as a Library) support

Migration Path

We're going to have to make sure to let users know about the behavioural change. I.e. a popup notice during package update?