-
-
Notifications
You must be signed in to change notification settings - Fork 56
Rework Initialization #2227
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
base: main
Are you sure you want to change the base?
Rework Initialization #2227
Changes from 48 commits
14427b6
bb4dbc0
0f97f0b
a76e957
e494279
df211a3
19c4e78
00e788a
bfcd0f1
4448334
232833c
bcbb551
deb6aa7
a66a5a6
857e492
eefad70
16c9fcf
6542706
b48e60d
76e05b2
3fa372c
1f5e5cc
83deeec
011ba1d
2a46b5f
7ac68be
43f5ae9
ad0ae02
bb6f80a
c53ccb5
d100d4f
7faafb9
490e033
2f42440
d2709d1
326dc32
1183370
f1388b4
594dc4a
3bfc5fa
0843ba5
a4cbc59
32876ac
c6cbb0c
3a2328b
2e4b3db
99bbb4d
d67b2b9
ac366e7
76868b8
1f520ee
a47872d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,9 @@ | |
#endif | ||
|
||
using System; | ||
using Sentry.Unity; | ||
using Sentry.Extensibility; | ||
using Sentry.Unity.NativeUtils; | ||
#if UNITY_2020_3_OR_NEWER | ||
using System.Buffers; | ||
using System.Runtime.InteropServices; | ||
|
@@ -39,91 +41,56 @@ | |
|
||
namespace Sentry.Unity | ||
{ | ||
public static class SentryInitialization | ||
internal static class SentryInitialization | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can safely make this |
||
{ | ||
public const string StartupTransactionOperation = "app.start"; | ||
public static ISpan InitSpan; | ||
private const string InitSpanOperation = "runtime.init"; | ||
public static ISpan SubSystemRegistrationSpan; | ||
private const string SubSystemSpanOperation = "runtime.init.subsystem"; | ||
|
||
/// <summary> | ||
/// This is intended for internal use only. | ||
/// The SDK relies on <c>SetupPlatformServices</c> getting called as the very first thing during the game's | ||
/// startup. This ensures that features like line number and native support are set up and configured properly. | ||
/// This is also the case when initializing manually from code. | ||
/// </summary> | ||
#if SENTRY_WEBGL | ||
// On WebGL SubsystemRegistration is too early for the UnityWebRequestTransport and errors with 'URI empty' | ||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] | ||
#else | ||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] | ||
#endif | ||
public static void Init() | ||
private static void Init() | ||
{ | ||
var unityInfo = new SentryUnityInfo(); | ||
// We're setting up `UnityInfo` and the platform specific configure callbacks as the very first thing. | ||
// These are required to be available during initialization. | ||
SetupPlatformServices(); | ||
|
||
// Loading the options invokes the ScriptableOption`Configure` callback. Users can disable the SDK via code. | ||
var options = ScriptableSentryUnityOptions.LoadSentryUnityOptions(unityInfo); | ||
var options = ScriptableSentryUnityOptions.LoadSentryUnityOptions(); | ||
if (options != null && options.ShouldInitializeSdk()) | ||
{ | ||
// Certain integrations require access to preprocessor directives so we provide them as `.cs` and | ||
// compile them with the game instead of precompiling them with the rest of the SDK. | ||
// i.e. SceneManagerAPI requires UNITY_2020_3_OR_NEWER | ||
SentryIntegrations.Configure(options); | ||
// Configures scope sync and (by default) initializes the native SDK. | ||
SetupNativeSdk(options, unityInfo); | ||
SentryUnity.Init(options); | ||
SetupStartupTracing(options); | ||
SentrySdk.Init(options); | ||
} | ||
else | ||
{ | ||
// If the SDK is not `enabled` we're closing down the native layer as well. This is especially relevant | ||
// in a `built-time-initialization` scenario where the native SDKs self-initialize. | ||
#if SENTRY_NATIVE_COCOA | ||
SentryNativeCocoa.Close(options, unityInfo); | ||
SentryNativeCocoa.Close(options); | ||
#elif SENTRY_NATIVE_ANDROID | ||
SentryNativeAndroid.Close(options, unityInfo); | ||
SentryNativeAndroid.Close(options); | ||
#endif | ||
} | ||
} | ||
|
||
private static void SetupNativeSdk(SentryUnityOptions options, SentryUnityInfo unityInfo) | ||
private static void SetupPlatformServices() | ||
{ | ||
try | ||
{ | ||
SentryPlatformServices.UnityInfo = new SentryUnityInfo(); | ||
|
||
#if SENTRY_NATIVE_COCOA | ||
SentryNativeCocoa.Configure(options, unityInfo); | ||
SentryPlatformServices.PlatformConfiguration = SentryNativeCocoa.Configure; | ||
#elif SENTRY_NATIVE_ANDROID | ||
SentryNativeAndroid.Configure(options, unityInfo); | ||
SentryPlatformServices.PlatformConfiguration = SentryNativeAndroid.Configure; | ||
#elif SENTRY_NATIVE | ||
SentryNative.Configure(options, unityInfo); | ||
SentryPlatformServices.PlatformConfiguration = SentryNative.Configure; | ||
#elif SENTRY_WEBGL | ||
SentryWebGL.Configure(options); | ||
#endif | ||
} | ||
catch (DllNotFoundException e) | ||
{ | ||
options.DiagnosticLogger?.LogError(e, | ||
"Sentry native-error capture configuration failed to load a native library. This usually " + | ||
"means the library is missing from the application bundle or the installation directory."); | ||
} | ||
catch (Exception e) | ||
{ | ||
options.DiagnosticLogger?.LogError(e, "Sentry native error capture configuration failed."); | ||
} | ||
} | ||
|
||
private static void SetupStartupTracing(SentryUnityOptions options) | ||
{ | ||
#if !SENTRY_WEBGL | ||
if (options.TracesSampleRate > 0.0f && options.AutoStartupTraces) | ||
{ | ||
options.DiagnosticLogger?.LogInfo("Creating '{0}' transaction for runtime initialization.", | ||
StartupTransactionOperation); | ||
|
||
var runtimeStartTransaction = | ||
SentrySdk.StartTransaction("runtime.initialization", StartupTransactionOperation); | ||
SentrySdk.ConfigureScope(scope => scope.Transaction = runtimeStartTransaction); | ||
|
||
options.DiagnosticLogger?.LogDebug("Creating '{0}' span.", InitSpanOperation); | ||
InitSpan = runtimeStartTransaction.StartChild(InitSpanOperation, "runtime initialization"); | ||
options.DiagnosticLogger?.LogDebug("Creating '{0}' span.", SubSystemSpanOperation); | ||
SubSystemRegistrationSpan = InitSpan.StartChild(SubSystemSpanOperation, "subsystem registration"); | ||
} | ||
SentryPlatformServices.PlatformConfiguration = SentryWebGL.Configure; | ||
#endif | ||
} | ||
} | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,7 +86,7 @@ public void SendFeedback() | |
else | ||
{ | ||
// Since there is no screenshot added we can capture the feedback right away | ||
SentryUnity.CaptureFeedback(_description.text, _email.text, _name.text, addScreenshot: false); | ||
SentrySdk.CaptureFeedback(_description.text, _email.text, _name.text, addScreenshot: false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the desired effect. All things reside within |
||
} | ||
} | ||
|
||
|
@@ -99,7 +99,7 @@ private IEnumerator HideFormAndCaptureFeedback() | |
// We're waiting for the EndOfFrame so the FeedbackForm gets updated before capturing the screenshot | ||
yield return new WaitForEndOfFrame(); | ||
|
||
SentryUnity.CaptureFeedback(_description.text, _email.text, _name.text, addScreenshot: true); | ||
SentrySdk.CaptureFeedback(_description.text, _email.text, _name.text, addScreenshot: true); | ||
|
||
ResetUserFeedback(); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.