Skip to content

Allow for a delayed or manual SDK initialization #2145

@bitsandfoxes

Description

@bitsandfoxes

Problem Statement

Currently, there is no straight forward way to delay the SDK's initialization. In addition, while manual initialization is possible, it might come with some hurdles.

Context

The Unity SDK relies on configuration provided within the Editor that is saved to /Resources as a .asset file.

The SDK compiles SentryInitialization.cs with your game. This way it has access to preprocessor directives.

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
#endif
public static void Init()

Part of loading the options is invoking the user's configuration callback.

var options = ScriptableSentryUnityOptions.LoadSentryUnityOptions(unityInfo);

OptionsConfiguration.Configure(options);

So while you can call SentryUnity.Init, users are missing out on the native SDK setup (which includes init and scope sync)

SetupNativeSdk(options, unityInfo);

So in all practicality, manually calling call SentryUnity.Init has a very limited usecase.

Proposal

Users should have the option to control automatic initialization. This could be a separate option in addition to Enabled.
Users should have the option to manually call Init the same way the SDK does.

Workaround

  1. Setup programmatic configuration
  2. Have the options.Enabled resolve to false based on your condition for the delay
  3. The SDK will attempt to auto-initialize and because of 2. skip
  4. When you're ready can call SentryInitialization.Init yourself
  5. The SDK will load the options again
  6. The SDK will invoke the options configuration callback again
  7. This time, you should have options.Enabled resolve to true
  8. The SDK will do the rest of the initialization

** Note, that on mobile platforms, for this workaround it is recommended to have the options.InitializationType set to Runtime as otherwise, the SDK will close down the native SDK during the first initialization attempt.

I know, this is not a pretty solution but at least you're not blocked.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions