Skip to content

Commit

Permalink
more timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsandfoxes committed Jan 15, 2025
1 parent 6b09f14 commit 416bf2a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,6 @@ 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
// 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
Expand All @@ -83,7 +30,7 @@ public override void Configure(SentryUnityOptions options)
return sentryEvent;
});

options.IosNativeInitializationType = NativeInitializationType.BuildTime;
options.AndroidNativeInitializationType = NativeInitializationType.Runtime;

Debug.Log("OptionConfigure finished.");
}
Expand Down
12 changes: 5 additions & 7 deletions src/Sentry.Unity.Android/SentryJava.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Sentry.Unity.Android;

internal interface ISentryJava
{
public bool IsEnabled(IJniExecutor jniExecutor);
public bool Init(IJniExecutor jniExecutor, SentryUnityOptions options, TimeSpan timeout);
public bool IsEnabled(IJniExecutor jniExecutor, TimeSpan timeout);
public void Init(IJniExecutor jniExecutor, SentryUnityOptions options, TimeSpan timeout);
public string? GetInstallationId(IJniExecutor jniExecutor);
public bool? CrashedLastRun(IJniExecutor jniExecutor);
public void Close(IJniExecutor jniExecutor);
Expand Down Expand Up @@ -45,16 +45,16 @@ internal class SentryJava : ISentryJava
{
private static AndroidJavaObject GetSentryJava() => new AndroidJavaClass("io.sentry.Sentry");

public bool IsEnabled(IJniExecutor jniExecutor)
public bool IsEnabled(IJniExecutor jniExecutor, TimeSpan timeout)
{
return jniExecutor.Run(() =>
{
using var sentry = GetSentryJava();
return sentry.CallStatic<bool>("isEnabled");
});
}, timeout);
}

public bool Init(IJniExecutor jniExecutor, SentryUnityOptions options, TimeSpan timeout)
public void Init(IJniExecutor jniExecutor, SentryUnityOptions options, TimeSpan timeout)
{
jniExecutor.Run(() =>
{
Expand Down Expand Up @@ -97,8 +97,6 @@ public bool Init(IJniExecutor jniExecutor, SentryUnityOptions options, TimeSpan
androidOptions.Call("setEnableScopePersistence", false);
}, options.DiagnosticLogger));
}, timeout);

return IsEnabled(jniExecutor);
}

internal class AndroidOptionsConfiguration : AndroidJavaProxy
Expand Down
10 changes: 7 additions & 3 deletions src/Sentry.Unity.Android/SentryNativeAndroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,20 @@ public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentry

options.DiagnosticLogger?.LogDebug("Checking whether the Android SDK has already been initialized");

if (SentryJava.IsEnabled(JniExecutor))
if (SentryJava.IsEnabled(JniExecutor, TimeSpan.FromMilliseconds(200)))
{
options.DiagnosticLogger?.LogDebug("The Android SDK is already initialized");
}
else
{
options.DiagnosticLogger?.LogDebug("Initializing the Android SDK");
options.DiagnosticLogger?.LogInfo("Initializing the Android SDK");

// Local testing had Init at an average of about 25ms.
if (!SentryJava.Init(JniExecutor, options, TimeSpan.FromMilliseconds(200)))
SentryJava.Init(JniExecutor, options, TimeSpan.FromMilliseconds(200));

options.DiagnosticLogger?.LogDebug("Validating Android SDK initialization");

if (!SentryJava.IsEnabled(JniExecutor, TimeSpan.FromMilliseconds(200)))
{
options.DiagnosticLogger?.LogError("Failed to initialize Android Native Support");
return;
Expand Down
4 changes: 2 additions & 2 deletions test/Sentry.Unity.Android.Tests/TestSentryJava.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ internal class TestSentryJava : ISentryJava
public string? InstallationId { get; set; }
public bool? IsCrashedLastRun { get; set; }

public bool IsEnabled(IJniExecutor jniExecutor) => Enabled;
public bool IsEnabled(IJniExecutor jniExecutor, TimeSpan timeout) => Enabled;

public bool Init(IJniExecutor jniExecutor, SentryUnityOptions options, TimeSpan timeout) => InitSuccessful;
public void Init(IJniExecutor jniExecutor, SentryUnityOptions options, TimeSpan timeout) { }

public string? GetInstallationId(IJniExecutor jniExecutor) => InstallationId;

Expand Down

0 comments on commit 416bf2a

Please sign in to comment.