Skip to content

Commit

Permalink
feat: Add OptionConfiguration to replace Runtime/BuildTime (#1888)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsandfoxes authored Nov 21, 2024
1 parent e4feaa5 commit 3c6d1a0
Show file tree
Hide file tree
Showing 26 changed files with 368 additions and 296 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

### API Changes

- The Runtime- and BuildTime-Configuration have been merged into a single `OptionsConfiguration` script. This allows for programmatic configuration of the SDK in one place using precompile directives. Note, that the current limitation of options for Android and iOS being baked into the project at build time still remains. ([#1888](https://github.com/getsentry/sentry-unity/pull/1888))
This is part of a larger effort to simplify the configuration of the native SDKs and enable users to modify their options at runtime. For more information see https://github.com/getsentry/sentry-unity/issues/1907

### Features

- The SDK now provides a dedicated sentry-cli scriptable config, available on the `Debug Symbols` tab. This allows for programmatic configuration of the used cli-options during build. ([#1887](https://github.com/getsentry/sentry-unity/pull/1887))
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ MonoBehaviour:
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 91e386628575c034e89d0f7632eb69b8, type: 3}
m_Name: RuntimeOptionsConfiguration
m_Script: {fileID: 11500000, guid: 674e271c73eb944c58925ab47108ce41, type: 3}
m_Name: SentryOptionConfiguration
m_EditorClassIdentifier:

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 17 additions & 12 deletions samples/unity-of-bugs/Assets/Resources/Sentry/SentryOptions.asset
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ MonoBehaviour:
m_Name: SentryOptions
m_EditorClassIdentifier:
<Enabled>k__BackingField: 1
<Dsn>k__BackingField: https://[email protected]/4504604988538880
<Dsn>k__BackingField: https://[email protected].us.sentry.io/4504604988538880
<CaptureInEditor>k__BackingField: 1
<EnableLogDebouncing>k__BackingField: 0
<DebounceTimeLog>k__BackingField: 1000
<DebounceTimeWarning>k__BackingField: 1000
<DebounceTimeError>k__BackingField: 1000
<TracesSampleRate>k__BackingField: 1
<TracesSampleRate>k__BackingField: 0
<AutoStartupTraces>k__BackingField: 1
<AutoSceneLoadTraces>k__BackingField: 1
<AutoAwakeTraces>k__BackingField: 1
<AutoAwakeTraces>k__BackingField: 0
<AutoSessionTracking>k__BackingField: 1
<AutoSessionTrackingInterval>k__BackingField: 30000
<ReleaseOverride>k__BackingField:
<EnvironmentOverride>k__BackingField:
<AttachStacktrace>k__BackingField: 0
<AttachScreenshot>k__BackingField: 1
<ScreenshotQuality>k__BackingField: 2
<AttachScreenshot>k__BackingField: 0
<ScreenshotQuality>k__BackingField: 1
<ScreenshotCompression>k__BackingField: 75
<AttachViewHierarchy>k__BackingField: 1
<AttachViewHierarchy>k__BackingField: 0
<MaxViewHierarchyRootObjects>k__BackingField: 100
<MaxViewHierarchyObjectChildCount>k__BackingField: 20
<MaxViewHierarchyDepth>k__BackingField: 10
Expand All @@ -46,25 +46,30 @@ MonoBehaviour:
<IsEnvironmentUser>k__BackingField: 0
<EnableOfflineCaching>k__BackingField: 1
<MaxCacheItems>k__BackingField: 30
<InitCacheFlushTimeout>k__BackingField: 2000
<InitCacheFlushTimeout>k__BackingField: 0
<SampleRate>k__BackingField: 1
<ShutdownTimeout>k__BackingField: 2000
<MaxQueueItems>k__BackingField: 30
<AnrDetectionEnabled>k__BackingField: 1
<AnrTimeout>k__BackingField: 5000
<CaptureFailedRequests>k__BackingField: 1
<FailedRequestStatusCodes>k__BackingField: f401000057020000
<FilterBadGatewayExceptions>k__BackingField: 1
<FilterWebExceptions>k__BackingField: 1
<FilterSocketExceptions>k__BackingField: 1
<IosNativeSupportEnabled>k__BackingField: 1
<AndroidNativeSupportEnabled>k__BackingField: 1
<NdkIntegrationEnabled>k__BackingField: 1
<NdkScopeSyncEnabled>k__BackingField: 1
<PostGenerateGradleProjectCallbackOrder>k__BackingField: 1
<WindowsNativeSupportEnabled>k__BackingField: 1
<MacosNativeSupportEnabled>k__BackingField: 1
<LinuxNativeSupportEnabled>k__BackingField: 1
<Il2CppLineNumberSupportEnabled>k__BackingField: 1
<RuntimeOptionsConfiguration>k__BackingField: {fileID: 11400000, guid: f9a47e8442a604414a84d5ad6da6aa43,
type: 2}
<BuildTimeOptionsConfiguration>k__BackingField: {fileID: 11400000, guid: 1c61999bd2a61408393cfe218d42287e,
<RuntimeOptionsConfiguration>k__BackingField: {fileID: 0}
<BuildTimeOptionsConfiguration>k__BackingField: {fileID: 0}
<OptionsConfiguration>k__BackingField: {fileID: 11400000, guid: cea63afb7c75f429799422326f926abe,
type: 2}
<Debug>k__BackingField: 1
<DebugOnlyInEditor>k__BackingField: 0
<DiagnosticLevel>k__BackingField: 0
<DebugOnlyInEditor>k__BackingField: 1
<DiagnosticLevel>k__BackingField: 2
22 changes: 0 additions & 22 deletions samples/unity-of-bugs/Assets/Scripts/BuildTimeConfiguration.cs

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions samples/unity-of-bugs/Assets/Scripts/Editor.meta

This file was deleted.

42 changes: 0 additions & 42 deletions samples/unity-of-bugs/Assets/Scripts/RuntimeConfiguration.cs

This file was deleted.

11 changes: 0 additions & 11 deletions samples/unity-of-bugs/Assets/Scripts/RuntimeConfiguration.cs.meta

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions samples/unity-of-bugs/Assets/Scripts/SentryOptionConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using Sentry.Unity;
using UnityEngine;
using UnityEngine.SceneManagement;

public class SentryOptionConfiguration : SentryOptionsConfiguration
{
public override void Configure(SentryUnityOptions options)
{
// Here you can programmatically modify the Sentry option properties used for the SDK's initialization

#if UNITY_ANDROID || UNITY_IOS
// NOTE!
// On Android and iOS, ALL options configured here will be "baked" into the exported project
// during the build process.
// Changes to the options at runtime will not affect the native SDKs (Java, C/C++, Objective-C)
// and only apply to the C# layer.

/*
* Sentry Unity SDK - Hybrid Architecture
* ======================================
*
* Build Time Runtime
* ┌─────────────────────────┐ ┌─────────────────────────┐
* │ Unity Editor │ │ Game Startup │
* └──────────┬──────────────┘ └───────────┬─────────────┘
* │ │
* ▼ ▼
* ┌────────────────────────────────────────────────────────────┐
* │ Options Configuration │
* │ (This Method) │
* └─────────────────────────────┬──────────────────────────────┘
* │
* ┌───────────────────────────────────┐
* │ Options used for Init │
* ▼ ▼
* ┌──────────────────────────┐ ┌──────────────────────┐
* │ Native SDK │ │ Unity C# SDK │
* │ Android & iOS │ │ Initialization │
* │ ┌────────────────────┐ │ └──────────────────────┘
* │ │ Options "Baked in" │ │
* │ └────────────────────┘ │
* │ The configure call made │
* │ for this part ran on │
* │ your build-machine │
* └──────────────────────────┘
* │
* ▼
* ┌──────────────────────────┐
* │ Native SDK │
* │ Android & iOS │
* └──────────────────────────┘
*/

// Works as expected and will enable all debug logging
// options.Debug = true;

// Will NOT work as expected.
// This will run twice.
// 1. Once during the build, being baked into the native SDKs
// 2. And a second time every time when the game starts
// options.Release = ComputeVersion();
#endif

Debug.Log("OptionConfigure started.");

// Making sure the SDK is not already initialized during tests
var sceneName = SceneManager.GetActiveScene().name;
if (sceneName != null && sceneName.Contains("TestScene"))
{
Debug.Log("Disabling the SDK while running tests.");
options.Enabled = false;
}

// BeforeSend is only relevant at runtime. It wouldn't hurt to be set at build time, just wouldn't do anything.
options.SetBeforeSend((sentryEvent, _) =>
{
if (sentryEvent.Tags.ContainsKey("SomeTag"))
{
// Don't send events with a tag SomeTag to Sentry
return null;
}
return sentryEvent;
});

Debug.Log("OptionConfigure finished.");
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3c6d1a0

Please sign in to comment.