Description
The Problem
Currently there are multiple ways to initialize the SDK, none of them ideal. There are multiple Init
methods while the SDK is auto-initializing. Users have no straight forward way to control or delay initialization.
Context
There are multiple ways to initialize the SDK.
SentrySdk.Init()
This is the entry point into the .NET SDK. It is discoverable and callable from anywhere inside the Unity project. The SDK calls this as part of SentryUnity.Init
.
SentryUnity.Init()
This is the entry point into the Unity SDK.
The SDK is also using it as part of the auto-initialization through
SentryInitialization
SentryInitialization.cs
The SDK provides a SentryInitialization.cs
as .cs
script so it has access to precompiler directives and other, targeted platform specifics like IL2CPP methods
sentry-unity/package-dev/Runtime/SentryInitialization.cs
Lines 54 to 56 in 14882b7
Due to the RuntimeInitializeOnLoadMethod
there's currently no way around the SDK attempting to auto-initialize.
The flow is
- The options get loaded from
/Resources
- The
ConfigureCallback
gets invoked, allowing user code to get executed
- Native SDKs get setup/initialized (scope observer, background worker setup, e.t.c)
sentry-unity/package-dev/Runtime/SentryInitialization.cs
Lines 88 to 96 in 14882b7
- The SDK calls
Init
Proposal
Changes
- Unify all
Init
into one classSentryUnity
. - Hide .NET SDK init - we do have access to the source due to submodule. We can hide it, or have it partial?
- Have one
Init
method with theRuntimeInitializeOnLoadMethod
that checks foroption.Enabled
and bails early. It calls 4. otherwise - Have a public
Init
method that gets called by 4. that also does the native-sdk configuration. Add/keep appropriate overloads. - Put
UnityInfo
somewhere accessible (i.e. the options, or have it onSentryUnity
and have the options fetch it from there).
User flow
Automatic Initialization
Nothing changes. The runtime attribute still initializes the SDK. The configure callback still gets invoked, allowing users to make programmatic changes to the options without having to worry/care about initialization timing.
Programmatic Initialization
For users that want to delay or manually initialize they'd disable the SDK in the config window. The auto-initialization will bail early. At any point, they can then call SentryUnity.Init
and the SDK will correctly handle native-sdk initialization and platform restriction.
Metadata
Metadata
Assignees
Type
Projects
Status