Skip to content

feat: Add OptionConfiguration to replace Runtime/BuildTime #1888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 52 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
130b8dd
created programmable config for cli options
bitsandfoxes Nov 6, 2024
56dcc01
.
bitsandfoxes Nov 6, 2024
b0016b8
created native options
bitsandfoxes Nov 6, 2024
445a388
added options configuration
bitsandfoxes Nov 6, 2024
610c042
working state
bitsandfoxes Nov 6, 2024
3d4e8f9
wip
bitsandfoxes Nov 6, 2024
c296280
Format code
getsentry-bot Nov 6, 2024
65cea10
renamed
bitsandfoxes Nov 6, 2024
65fca3d
merged
bitsandfoxes Nov 6, 2024
3c7e7b1
removed native override
bitsandfoxes Nov 7, 2024
08ed47d
samples
bitsandfoxes Nov 7, 2024
2a08a6f
Merge branch 'main' into feat/options-config
bitsandfoxes Nov 13, 2024
78d4a98
logging
bitsandfoxes Nov 13, 2024
0cc186a
Merge branch 'main' into feat/options-config
bitsandfoxes Nov 13, 2024
af5e3ec
Updated CHANGELOG.md
bitsandfoxes Nov 13, 2024
c440582
Merge branch 'main' into feat/create-cli-config
bitsandfoxes Nov 13, 2024
ebfd6fa
Merge branch 'feat/create-cli-config' into feat/options-config
bitsandfoxes Nov 13, 2024
54d956f
.
bitsandfoxes Nov 13, 2024
3405fa1
Updated CHANGELOG.md
bitsandfoxes Nov 13, 2024
d8a455f
script configuration in samples
bitsandfoxes Nov 13, 2024
888b8a8
update smoke test
bitsandfoxes Nov 13, 2024
e434228
fix order and update tests
bitsandfoxes Nov 13, 2024
822adf8
updated snapshot
bitsandfoxes Nov 13, 2024
0d6f704
Merge branch 'feat/create-cli-config' into feat/options-config
bitsandfoxes Nov 13, 2024
915d207
Format code
getsentry-bot Nov 13, 2024
42648e5
Merge branch 'main' into feat/create-cli-config
bitsandfoxes Nov 13, 2024
84371a0
updated snapshot
bitsandfoxes Nov 13, 2024
2162e24
Merge branch 'feat/create-cli-config' of https://github.com/getsentry…
bitsandfoxes Nov 13, 2024
7cbfc65
Updated CHANGELOG.md
bitsandfoxes Nov 13, 2024
efa3c50
Updated CHANGELOG.md
bitsandfoxes Nov 13, 2024
beadc82
merged
bitsandfoxes Nov 13, 2024
20a046d
Updated CHANGELOG.md
bitsandfoxes Nov 13, 2024
a3f535a
Merge branch 'feat/options-config' of https://github.com/getsentry/se…
bitsandfoxes Nov 13, 2024
53108ee
missing box closure
bitsandfoxes Nov 15, 2024
6693c98
clarify comment in template
bitsandfoxes Nov 15, 2024
b67c98c
updated sample
bitsandfoxes Nov 18, 2024
45852f8
bug-config
bitsandfoxes Nov 18, 2024
cf80744
Update test/Scripts.Integration.Test/add-sentry.ps1
bitsandfoxes Nov 18, 2024
cdbe3db
explainer
bitsandfoxes Nov 18, 2024
8bc698d
Merge branch 'feat/options-config' of https://github.com/getsentry/se…
bitsandfoxes Nov 18, 2024
ad9674d
make showing the deprecation warning optional
bitsandfoxes Nov 18, 2024
bc34b5f
merged
bitsandfoxes Nov 18, 2024
cc3d268
remove 'new' for deprecated runtime/buildtime
bitsandfoxes Nov 18, 2024
5b31dc6
dead code
bitsandfoxes Nov 18, 2024
2875076
Update src/Sentry.Unity/SentryOptionsConfiguration.cs
bitsandfoxes Nov 18, 2024
99bcae9
cleanup
bitsandfoxes Nov 20, 2024
729b7e5
Format code
getsentry-bot Nov 20, 2024
5337ea8
comment cleanup
bitsandfoxes Nov 20, 2024
32eb242
Merge branch 'feat/options-config' of https://github.com/getsentry/se…
bitsandfoxes Nov 20, 2024
2ee361c
updated snapshot
bitsandfoxes Nov 21, 2024
1ebf9bc
Updated CHANGELOG.md
bitsandfoxes Nov 21, 2024
dbf1dbf
Updated CHANGELOG.md
bitsandfoxes Nov 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

This file was deleted.

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

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just make the C# layer initialize the native layer by default?

And make this "Native inits first" thing be opt-in? It seems still hard for folks to understand what's going on, even with the comments below. (I don't expect a beginner to get it)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be simpler but we would lose on the ability to catch native exceptions happening at startup. Is that worth it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see a point for: If you've got plugins that might crash the app before the Unity game starts you can opt-in the native first init and still have full coverage.
If you don't then are those native crashes/exceptions be even actionable for you?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see a point for: If you've got plugins that might crash the app before the Unity game starts you can opt-in the native first init and still have full coverage.

Wouldn't that mean we still need to keep the buildtime native configuration generator (which I understand Bruno was suggesting we could remove)?

If you don't then are those native crashes/exceptions be even actionable for you?

Even the information that there are startup crashes is valuable IMO.


Overall, I wouldn't change this - it does provide value (startup crashes) even though it does make things a little more complicated IF users need to adapt these settings programmatically

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've summarized my ideas in #1907
Maybe you can take a look? The idea is to have the auto-init be opt-in. Reduce friction and confusion for those that don't need it but still provide the feature for those that do.

// 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
Loading