sentry-unity
sentry-unity copied to clipboard
Simplify `BuildTime` and `Runtime` Options
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
- https://github.com/getsentry/sentry-unity/blob/2085934e83c2f0f7242a6fd64bc21ec1a675a053/src/Sentry.Unity/SentryRuntimeOptionsConfiguration.cs#L13
- https://github.com/getsentry/sentry-unity/blob/2085934e83c2f0f7242a6fd64bc21ec1a675a053/src/Sentry.Unity/SentryBuildTimeOptionsConfiguration.cs#L13
Initialization
Before initialization we're "loading" the scriptable options
and create SentryUnityOptions
from there
https://github.com/getsentry/sentry-unity/blob/2085934e83c2f0f7242a6fd64bc21ec1a675a053/src/Sentry.Unity/ScriptableSentryUnityOptions.cs#L121-L130
and we're invoking the RuntimeConfiguration
during the option creation.
https://github.com/getsentry/sentry-unity/blob/2085934e83c2f0f7242a6fd64bc21ec1a675a053/src/Sentry.Unity/ScriptableSentryUnityOptions.cs#L219
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.
- https://github.com/getsentry/sentry-unity/blob/2085934e83c2f0f7242a6fd64bc21ec1a675a053/src/Sentry.Unity.Editor/Android/PostBuildCheck.cs#L17
- https://github.com/getsentry/sentry-unity/blob/2085934e83c2f0f7242a6fd64bc21ec1a675a053/src/Sentry.Unity.Editor.iOS/BuildPostProcess.cs#L22
- https://github.com/getsentry/sentry-unity/blob/2085934e83c2f0f7242a6fd64bc21ec1a675a053/src/Sentry.Unity.Editor/Il2CppBuildPreProcess.cs#L25
- https://github.com/getsentry/sentry-unity/blob/2085934e83c2f0f7242a6fd64bc21ec1a675a053/src/Sentry.Unity.Editor/Native/BuildPostProcess.cs#L26
- https://github.com/getsentry/sentry-unity/blob/2085934e83c2f0f7242a6fd64bc21ec1a675a053/src/Sentry.Unity.Editor/AutoInstrumentation/SentryPerformanceAutoInstrumentation.cs#L18
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.