@@ -55,63 +55,76 @@ public static class SentryInitialization
55
55
#endif
56
56
public static void Init ( )
57
57
{
58
- var sentryUnityInfo = new SentryUnityInfo ( ) ;
59
- var options = ScriptableSentryUnityOptions . LoadSentryUnityOptions ( sentryUnityInfo ) ;
58
+ var unityInfo = new SentryUnityInfo ( ) ;
59
+ // Loading the options invokes the ScriptableOption`Configure` callback. Users can disable the SDK via code.
60
+ var options = ScriptableSentryUnityOptions . LoadSentryUnityOptions ( unityInfo ) ;
60
61
if ( options != null && options . ShouldInitializeSdk ( ) )
61
62
{
63
+ // Certain integrations require access to preprocessor directives so we provide them as `.cs` and
64
+ // compile them with the game instead of precompiling them with the rest of the SDK.
65
+ // i.e. SceneManagerAPI requires UNITY_2020_3_OR_NEWER
62
66
SentryIntegrations . Configure ( options ) ;
67
+ // Configures scope sync and (by default) initializes the native SDK.
68
+ SetupNativeSdk ( options , unityInfo ) ;
69
+ SentryUnity . Init ( options ) ;
70
+ SetupStartupTracing ( options ) ;
71
+ }
72
+ else
73
+ {
74
+ // If the SDK is not `enabled` we're closing down the native layer as well. This is especially relevant
75
+ // in a `built-time-initialization` scenario where the native SDKs self-initialize.
76
+ #if SENTRY_NATIVE_COCOA
77
+ SentryNativeCocoa . Close ( options , unityInfo ) ;
78
+ #elif SENTRY_NATIVE_ANDROID
79
+ SentryNativeAndroid . Close ( options , unityInfo ) ;
80
+ #endif
81
+ }
82
+ }
63
83
64
- try
65
- {
84
+ private static void SetupNativeSdk ( SentryUnityOptions options , SentryUnityInfo unityInfo )
85
+ {
86
+ try
87
+ {
66
88
#if SENTRY_NATIVE_COCOA
67
- SentryNativeCocoa . Configure ( options , sentryUnityInfo ) ;
89
+ SentryNativeCocoa . Configure ( options , unityInfo ) ;
68
90
#elif SENTRY_NATIVE_ANDROID
69
- SentryNativeAndroid . Configure ( options , sentryUnityInfo ) ;
91
+ SentryNativeAndroid . Configure ( options , unityInfo ) ;
70
92
#elif SENTRY_NATIVE
71
- SentryNative . Configure ( options , sentryUnityInfo ) ;
93
+ SentryNative . Configure ( options , unityInfo ) ;
72
94
#elif SENTRY_WEBGL
73
- SentryWebGL . Configure ( options ) ;
95
+ SentryWebGL . Configure ( options ) ;
74
96
#endif
75
- }
76
- catch ( DllNotFoundException e )
77
- {
78
- options . DiagnosticLogger ? . LogError ( e ,
79
- "Sentry native-error capture configuration failed to load a native library. This usually " +
80
- "means the library is missing from the application bundle or the installation directory." ) ;
81
- }
82
- catch ( Exception e )
83
- {
84
- options . DiagnosticLogger ? . LogError ( e , "Sentry native error capture configuration failed." ) ;
85
- }
86
-
87
- SentryUnity . Init ( options ) ;
97
+ }
98
+ catch ( DllNotFoundException e )
99
+ {
100
+ options . DiagnosticLogger ? . LogError ( e ,
101
+ "Sentry native-error capture configuration failed to load a native library. This usually " +
102
+ "means the library is missing from the application bundle or the installation directory." ) ;
103
+ }
104
+ catch ( Exception e )
105
+ {
106
+ options . DiagnosticLogger ? . LogError ( e , "Sentry native error capture configuration failed." ) ;
107
+ }
108
+ }
88
109
110
+ private static void SetupStartupTracing ( SentryUnityOptions options )
111
+ {
89
112
#if ! SENTRY_WEBGL
90
- if ( options . TracesSampleRate > 0.0f && options . AutoStartupTraces )
91
- {
92
- options . DiagnosticLogger ? . LogInfo ( "Creating '{0}' transaction for runtime initialization." ,
93
- StartupTransactionOperation ) ;
94
-
95
- var runtimeStartTransaction =
96
- SentrySdk . StartTransaction ( "runtime.initialization" , StartupTransactionOperation ) ;
97
- SentrySdk . ConfigureScope ( scope => scope . Transaction = runtimeStartTransaction ) ;
98
-
99
- options . DiagnosticLogger ? . LogDebug ( "Creating '{0}' span." , InitSpanOperation ) ;
100
- InitSpan = runtimeStartTransaction . StartChild ( InitSpanOperation , "runtime initialization" ) ;
101
- options . DiagnosticLogger ? . LogDebug ( "Creating '{0}' span." , SubSystemSpanOperation ) ;
102
- SubSystemRegistrationSpan = InitSpan . StartChild ( SubSystemSpanOperation , "subsystem registration" ) ;
103
- }
104
- #endif
105
- }
106
- else
113
+ if ( options . TracesSampleRate > 0.0f && options . AutoStartupTraces )
107
114
{
108
- // Closing down the native layer that are set up during build and self-initialize
109
- #if SENTRY_NATIVE_COCOA
110
- SentryNativeCocoa . Close ( options , sentryUnityInfo ) ;
111
- #elif SENTRY_NATIVE_ANDROID
112
- SentryNativeAndroid . Close ( options , sentryUnityInfo ) ;
113
- #endif
115
+ options . DiagnosticLogger ? . LogInfo ( "Creating '{0}' transaction for runtime initialization." ,
116
+ StartupTransactionOperation ) ;
117
+
118
+ var runtimeStartTransaction =
119
+ SentrySdk . StartTransaction ( "runtime.initialization" , StartupTransactionOperation ) ;
120
+ SentrySdk . ConfigureScope ( scope => scope . Transaction = runtimeStartTransaction ) ;
121
+
122
+ options . DiagnosticLogger ? . LogDebug ( "Creating '{0}' span." , InitSpanOperation ) ;
123
+ InitSpan = runtimeStartTransaction . StartChild ( InitSpanOperation , "runtime initialization" ) ;
124
+ options . DiagnosticLogger ? . LogDebug ( "Creating '{0}' span." , SubSystemSpanOperation ) ;
125
+ SubSystemRegistrationSpan = InitSpan . StartChild ( SubSystemSpanOperation , "subsystem registration" ) ;
114
126
}
127
+ #endif
115
128
}
116
129
}
117
130
0 commit comments