Skip to content

Simplify BuildTime and Runtime Options #1621

Closed

Description

@bitsandfoxes

Problem

Because the native SDKs on mobile get initialized even before the game even starts, the SDK is providing two configure hooks to programmatically configure the options, one for runtime and one for build-time. This is creating a lot of confusion as to which options apply to what and when.
Examples:

  • Even tho I set the default tags right during build-time options they do not get applied during runtime.
  • I've set the sample rate in the runtime options but it does not seem to affect events coming from the native SDK

Current Setup

Serialized Options and programmatic configuration

We needed a place to keep all the options we surface in the editor config window. Instead of a config file the SDK makes use of the built-in ScriptableObject functionality. To allow for programmatic configuration the SDK provides two additional scriptable objects users can inherit and overwrite their Configure callback

Initialization

Before initialization we're "loading" the scriptable options and create SentryUnityOptions from there

public static SentryUnityOptions? LoadSentryUnityOptions(ISentryUnityInfo unityInfo)
{
var scriptableOptions = Resources.Load<ScriptableSentryUnityOptions>($"{ConfigRootFolder}/{ConfigName}");
if (scriptableOptions is not null)
{
return scriptableOptions.ToSentryUnityOptions(false, unityInfo);
}
return null;
}

and we're invoking the RuntimeConfiguration during the option creation.

RuntimeOptionsConfiguration.Configure(options);

Build Time Options

In comparison, the build time options get invoked in a bunch of different places during the build process. Any options set here do not apply to the C# layer at runtime.

Proposal

Unify Runtime & Build Time

Instead of having two scriptable objects with the same configure callback that apply to different "layers" we should have one that applies to all. To cover the use-case of wanting to overwrite/modify native layer options we can follow what the .NET is doing and add them as .NativeOptions to the options object. We can invoke the same callback everywhere (initialization, build time setup) and still keep the "native"-options nested in the UnityOptions.

public class OptionsConfiguration : SentryOptionsConfiguration
{
    public override void Configure(SentryUnityOptions options)
    {
        options.Dsn = "super-valid-dsn";
        options.Environment = "prod";

        // During build time we can construct the options and overwrite the relevant parts - where applicable
        options.NativeBuildTime.sampleRate = 0.5f;
    }
}

Sentry CLI options

Handling the CLI options can be done like with the regular options. If it exists, load the scriptable object. Add a property for a scriptable config to the editor window. If that exists, invoke the configure callback with the options.

Activity

  1. changed the title [-]Simplify BuildTime` and `Runtime` Options[/-] [+]Simplify `BuildTime` and `Runtime` Options[/+] on Apr 15, 2024
  2. moved this to Todo in GDXon Sep 10, 2024
  3. moved this from Todo to Done in GDXon Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions