Skip to content

Commit 1d3089b

Browse files
authored
feat (Unity): Updated options (#12636)
1 parent fdea552 commit 1d3089b

File tree

10 files changed

+146
-32
lines changed

10 files changed

+146
-32
lines changed
99.4 KB
Loading
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: Sentry CLI Options
3+
description: "Learn more about how to configure the options used by Sentry CLI."
4+
sidebar_order: 30
5+
---
6+
7+
The Unity SDK includes [Sentry CLI](/product/cli/) as a tool to upload debug symbols to Sentry. These debug symbols are used in processing events sent to Sentry to provide stacktraces and linenumbers. This page describes the options available to configure the Sentry CLI.
8+
9+
## Programmatic Configuration
10+
11+
Similar to the [programmatic configuration](/platforms/unity/configuration/options/programmatic-configuration/) of the SDK itself, the debug symbol upload via Sentry CLI also supports programmatic configuration.
12+
13+
![Options Configuration](./img/sentry-cli-option-configuration.png)
14+
15+
The `Configure` callback gets invoked during the build process and allows you to modify the options used by Sentry CLI.
16+
17+
## Sentry CLI Options
18+
19+
<ConfigKey name="upload-symbols" supported={["dotnet"]}>
20+
21+
Whether the SDK should automatically upload debug symbols to Sentry. This requires a valid auth token, organization, and project.
22+
23+
</ConfigKey>
24+
25+
<ConfigKey name="upload-development-symbols" supported={["dotnet"]}>
26+
27+
Whether the SDK should automatically upload debug symbols to Sentry for development builds.
28+
29+
</ConfigKey>
30+
31+
<ConfigKey name="upload-sources" supported={["dotnet"]}>
32+
33+
Whether the SDK should automatically upload sources to Sentry; this enables Sentry to provide source-context on events.
34+
35+
</ConfigKey>
36+
37+
<ConfigKey name="url-override" supported={["dotnet"]}>
38+
39+
This option allows you to override the default Sentry URL in case you are using a self-hosted Sentry instance or a custom domain.
40+
41+
</ConfigKey>
42+
43+
<ConfigKey name="auth" supported={["dotnet"]}>
44+
45+
The auth token to use when uploading symbols to Sentry.
46+
47+
</ConfigKey>
48+
49+
<ConfigKey name="organization" supported={["dotnet"]}>
50+
51+
The organization to use when uploading symbols to Sentry.
52+
53+
</ConfigKey>
54+
55+
<ConfigKey name="project" supported={["dotnet"]}>
56+
57+
The project to use when uploading symbols to Sentry.
58+
59+
</ConfigKey>
60+
61+
<ConfigKey name="ignore-cli-errors" supported={["dotnet"]}>
62+
63+
If set to true, the Sentry CLI will not exit with an error code if it encounters an error. **BE AWARE** you might have unminified/unsymbolicated crashes in production if the debug symbol upload fails. When using this flag, you should store built sourcemaps and debug files, to re-run the upload symbols command at a later point.
64+
65+
</ConfigKey>

docs/platforms/unity/configuration/options.mdx renamed to docs/platforms/unity/configuration/options/index.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ sidebar_order: 1
44
description: "Learn more about how the SDK can be configured via options. These are being passed to the init function and therefore set when the SDK is first initialized."
55
---
66

7-
<PlatformContent includePath="configuration/config-intro" />
7+
## Programmatic Configuration
8+
9+
The SDK provides a configuration window that allows you to set most of Sentry's options directly in the Unity Editor. Some options, like the `BeforeSend` callback, can only be set programmatically. Take a look at our documentation about <PlatformLink to="/configuration/options/programmatic-configuration/"> how to configure the SDK programmatically</PlatformLink> for more information.
810

911
## Core Options
1012

72.3 KB
Loading
104 KB
Loading
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: Programmatic Configuration
3+
description: "Learn more about how to configure the Unity SDK programmatically."
4+
sidebar_order: 20
5+
---
6+
7+
We've added `Sentry Options Configuration` to the `Options Config` tab in the Sentry editor window to provide a way to modify options programmatically.
8+
9+
![Options Configuration](./img/unity-options-configuration.png)
10+
11+
## Programmatic Configuration
12+
13+
The Sentry SDK for Unity includes [platform-specific (that is, Native)](/platforms/unity/native-support/) SDKs, such as [Android](/platforms/android/), [Apple](/platforms/apple/guides/ios/), and [Native](/platforms/native/) to provide native crash suppport. These SDKs share the options with which they get initialized.
14+
15+
The C# layer self-initializes through the use of the [SubsystemRegistration RuntimeInitializeOnLoadMethodAttribute](https://docs.unity3d.com/ScriptReference/RuntimeInitializeLoadType.SubsystemRegistration.html).
16+
17+
![Flow of initialization](./img/initialization-flow.png)
18+
19+
If provided, the `Option Configuration Script` is executed on each app startup. The options are first used to initialize the native SDKs, then the managed (C#) SDK. This means that the options you set in your `Configure` callback will also apply on the native layer. For example:
20+
21+
```csharp
22+
public override void Configure(SentryUnityOptions options)
23+
{
24+
// BeforeSend is currently limited to C# code. Native errors - such as crashes in C/C++ code - are getting
25+
// captured by the native SDKs, but the native SDKs won't invoke this callback.
26+
options.SetBeforeSend((sentryEvent, _) =>
27+
{
28+
if (sentryEvent.Tags.ContainsKey("SomeTag"))
29+
{
30+
// Don't send events with a tag "SomeTag" to Sentry
31+
return null;
32+
}
33+
34+
return sentryEvent;
35+
});
36+
37+
// Native SDK initialization timing options:
38+
// Build-time initialization:
39+
// + Can capture Unity engine errors
40+
// - Options are fixed at build time
41+
// Runtime initialization:
42+
// + Allows dynamic configuration
43+
// - May miss some early errors
44+
#if UNITY_ANDROID
45+
options.AndroidNativeInitializationType = NativeInitializationType.Runtime;
46+
#elif UNITY_IOS
47+
options.IosNativeInitializationType = NativeInitializationType.Runtime;
48+
#endif
49+
}
50+
```
51+
52+
### Initialize Native SDKs first when targeting iOS or Android
53+
54+
On mobile, the Unity SDK automatically modifies the generated Xcode and Gradle project to also contain the Cocoa and Java SDK respectively. These SDKs are capable of self-initializing before the Unity engine itself is started. This allows us to capture bugs/crashes happening within the engine itself.
55+
There are two initialization types:
56+
57+
- `NativeInitializationType.Runtime`: Native SDKs initialize during runtime alongside the C# SDK
58+
- `NativeInitializationType.BuildTime`: Native SDKs initialize before Unity engine starts
59+
60+
### Runtime Initialization (Default)
61+
With runtime initialization, the native SDKs are initialized at runtime alongside the C# SDK. This allows all options to be dynamically configured through C# code during execution.
62+
63+
### Build Time Initialization
64+
When using build time initialization, the native SDKs are configured during build time and initialize before the Unity engine starts. This means the options are baked into the outputted projects and cannot be modified at runtime via C# code. Changes to properties like `Release` and `Environment` will not apply to events generated by the native SDKs.

docs/platforms/unity/migration/index.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ description: "Learn more about migrating to the current version."
44
sidebar_order: 8000
55
---
66

7+
## Migrating to 3.0.0
8+
9+
### Changes to the initialization behaviour on iOS and Android
10+
11+
The native layer on mobile platforms (iOS and Android) no longer self-initializes before the Unity game engine starts. Previously, the SDK would use the options at build-time and bake them into the native layer. Instead, the SDK will now take the options passed into the Configure callback and use those to initialize the native SDKs. This allows users to modify the native SDK's options at runtime programmatically. The initialization behaviour is controlled by the `IosNativeInitializationType` and `AndroidNativeInitializationType` options.
12+
13+
To restore the previous behaviour, you can set the `IosNativeInitializationType` and `AndroidNativeInitializationType` options to `BuildTime`.
14+
15+
### Changes to the programmatic configuration
16+
17+
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 preprocessor directives instead of having to duplicate setting options in two different files.
18+
19+
You can still use the old configuration classes, but they have been deprecated and will be removed in a future version. Going forward, you should use the new OptionsConfiguration script and make use of the preprocessor directives when setting options for different platforms.
20+
721
## Migrating to 0.28.0
822

923
### Breaking Changes
Binary file not shown.
Binary file not shown.

platform-includes/configuration/config-intro/unity.mdx

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)