Skip to content
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

feat: Add OptionConfiguration to replace Runtime/BuildTime #1888

Merged
merged 52 commits into from
Nov 21, 2024

Conversation

bitsandfoxes
Copy link
Contributor

@bitsandfoxes bitsandfoxes commented Nov 6, 2024

Fixes #1621

Based on the issue description: The aim is to have users no longer need to know or care about Runtime and BuildTime differences. They write their code in once place, we use the same options at any time.

Platform specifics can be controlled via the Unity precompile directives. We include a sample of those with the generated template:

using Sentry;
using Sentry.Unity;

public class SentryConfiguration : 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 || UNITY_STANDALONE_OSX
        // NOTE!
        // On Android, iOS, and macOS, 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.

        // Examples:

        // Works as expected and will disable all debug logging of the native SDKs
        // options.Debug = false;

        // Will NOT work as expected as this will need to get validated at runtime
        // options.Debug = SystemInfo.deviceName.Contains("Pixel");
#endif
    }
}

The Runtime/BuildTime config got deprecated but will still be called last as keep backwards compatibility. I've updated the config window with a warning label that shows as long as there are either Runtime or BuildTime configs.
ScriptableConfig

Copy link
Contributor

github-actions bot commented Nov 6, 2024

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against dbf1dbf

@bitsandfoxes bitsandfoxes changed the title feat: Add OptionConfiguration feat: Add OptionConfiguration to replace Runtime/BuildTime Nov 15, 2024
options.SampleRate = 1.0f;
// 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.

src/Sentry.Unity/SentryOptionsConfiguration.cs Outdated Show resolved Hide resolved
test/Scripts.Integration.Test/Scripts/CliConfiguration.cs Outdated Show resolved Hide resolved
test/Scripts.Integration.Test/add-sentry.ps1 Outdated Show resolved Hide resolved
Copy link
Collaborator

@vaind vaind left a comment

Choose a reason for hiding this comment

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

The Runtime/BuildTime config got deprecated but will still be called last as keep backwards compatibility. I've updated the config window with a warning label.
Screenshot 2024-11-15 at 11 18 18

What do you think about only showing the new option on the UI by default and only show the original options (i.e. as in the screenshot), when any of the original options are actually set in the existing config?

options.SampleRate = 1.0f;
// Here you can programmatically modify the Sentry option properties used for the SDK's initialization

#if UNITY_ANDROID || UNITY_IOS
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?

Base automatically changed from feat/create-cli-config to main November 18, 2024 11:11
@bitsandfoxes
Copy link
Contributor Author

bitsandfoxes commented Nov 18, 2024

What do you think about only showing the new option on the UI by default and only show the original options (i.e. as in the screenshot), when any of the original options are actually set in the existing config?

After giving it a try I think that's fair. I've updated the window logic.

@bitsandfoxes bitsandfoxes merged commit 3c6d1a0 into main Nov 21, 2024
92 of 94 checks passed
@bitsandfoxes bitsandfoxes deleted the feat/options-config branch November 21, 2024 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify BuildTime and Runtime Options
4 participants