Skip to content

Commit

Permalink
Switch to GlitchTip provider
Browse files Browse the repository at this point in the history
Also add a way to disable log uploading. This is due to a bug(?) where log upload length reported as 0 and causes BadRequest error. See getsentry/sentry-dotnet#3747
  • Loading branch information
bagusnl committed Nov 14, 2024
1 parent 6180077 commit 2391610
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 29 deletions.
5 changes: 2 additions & 3 deletions CollapseLauncher/XAMLs/MainApp/Pages/RepairPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using CollapseLauncher.Helper;
using CollapseLauncher.Statics;
using Hi3Helper;
using Hi3Helper.SentryHelper;
using Hi3Helper.Shared.ClassStruct;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
Expand Down Expand Up @@ -38,7 +37,7 @@ private void StartGameCheckSplitButton(SplitButton sender, SplitButtonClickEvent

private void StartGameCheck(object sender, RoutedEventArgs e)
{
string tag = (string)(sender as ButtonBase).Tag;
string tag = (string)(sender as ButtonBase)?.Tag;
bool isFast = tag == "Fast";

RunCheckRoutine(sender, isFast, false);
Expand Down Expand Up @@ -247,7 +246,7 @@ private void InitializeLoaded(object sender, RoutedEventArgs e)
else
{
#if !DISABLEDISCORD
InnerLauncherConfig.AppDiscordPresence.SetActivity(ActivityType.Repair);
InnerLauncherConfig.AppDiscordPresence?.SetActivity(ActivityType.Repair);
#endif
}
}
Expand Down
84 changes: 58 additions & 26 deletions Hi3Helper.Core/Classes/SentryHelper/SentryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using System.Threading.Tasks;
using Hi3Helper.Shared.Region;
using Sentry.Protocol;

// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable HeuristicUnreachableCode
// ReSharper disable RedundantIfElseBlock
#nullable enable
namespace Hi3Helper.SentryHelper
{
Expand All @@ -14,12 +16,17 @@ public static class SentryHelper
/// <summary>
/// DSN (Data Source Name a.k.a. upstream server) to be used for error reporting.
/// </summary>
private const string SentryDsn = "https://2acc39f86f2b4f5a99bac09494af13c6@bugsink.bagelnl.my.id/1";
private const string SentryDsn = "https://38ac2201fe414e719a5b8297cc5f1aa0@glitchtip.bagelnl.my.id/1";

/// <summary>
/// <inheritdoc cref="SentryOptions.MaxAttachmentSize"/>

Check warning on line 22 in Hi3Helper.Core/Classes/SentryHelper/SentryHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Invalid XML documentation comment

Cannot resolve symbol 'SentryOptions'
/// </summary>
private const long SentryMaxAttachmentSize = 2 * 1024 * 1024; // 2 MB

/// <summary>
/// Whether to upload log file when exception is caught.
/// </summary>
private const bool SentryUploadLog = false;


/// <summary>
Expand Down Expand Up @@ -74,14 +81,15 @@ public static void InitializeSentrySdk()
o.Dsn = SentryDsn;
o.AddEventProcessor(new SentryEventProcessor());
o.CacheDirectoryPath = LauncherConfig.AppDataFolder;

#if DEBUG
o.Debug = true;
o.DiagnosticLogger = new ConsoleAndTraceDiagnosticLogger(SentryLevel.Debug);
o.DiagnosticLevel = SentryLevel.Debug;
o.Distribution = "Debug";
#else
o.Debug = false;
o.DiagnosticLevel = SentryLevel.Error;
o.Distribution = IsPreview ? "Preview" : "Stable";
#endif
o.AutoSessionTracking = true;
o.StackTraceMode = StackTraceMode.Enhanced;
Expand All @@ -91,11 +99,6 @@ public static void InitializeSentrySdk()
o.DisableWinUiUnhandledExceptionIntegration(); // Use this for trimmed/NativeAOT published app
o.StackTraceMode = StackTraceMode.Enhanced;
o.SendDefaultPii = false;
#if DEBUG
o.Distribution = "Debug";
#else
o.Distribution = IsPreview ? "Preview" : "Stable";
#endif
o.MaxAttachmentSize = SentryMaxAttachmentSize;
o.DeduplicateMode = DeduplicateMode.All;
});
Expand Down Expand Up @@ -167,13 +170,22 @@ public static void ExceptionHandler(Exception ex, ExceptionType exT = ExceptionT
ex.Data[Mechanism.MechanismKey] = "Application.XamlUnhandledException";
else if (exT == ExceptionType.UnhandledOther)
ex.Data[Mechanism.MechanismKey] = "Application.UnhandledException";
if ((bool)(ex.Data[Mechanism.HandledKey] ?? false))
SentrySdk.CaptureException(ex);
if (SentryUploadLog) // Upload log file if enabled
#pragma warning disable CS0162 // Unreachable code detected
{
if ((bool)(ex.Data[Mechanism.HandledKey] ?? false))
SentrySdk.CaptureException(ex);
else
SentrySdk.CaptureException(ex, s =>
{
s.AddAttachment(LoggerBase.LogPath, AttachmentType.Default, "text/plain");
});
}
#pragma warning restore CS0162 // Unreachable code detected
else
SentrySdk.CaptureException(ex, s =>
{
s.AddAttachment(LoggerBase.LogPath, AttachmentType.Default, "text/plain");
});
{
SentrySdk.CaptureException(ex);
}
}

/// <summary>
Expand All @@ -189,13 +201,23 @@ public static async Task ExceptionHandlerAsync(Exception ex, ExceptionType exT =
ex.Data[Mechanism.MechanismKey] = "Application.XamlUnhandledException";
else if (exT == ExceptionType.UnhandledOther)
ex.Data[Mechanism.MechanismKey] = "Application.UnhandledException";
if ((bool)(ex.Data[Mechanism.HandledKey] ?? false))
SentrySdk.CaptureException(ex);
if (SentryUploadLog) // Upload log file if enabled
#pragma warning disable CS0162 // Unreachable code detected
// ReSharper disable once HeuristicUnreachableCode
{
if ((bool)(ex.Data[Mechanism.HandledKey] ?? false))
SentrySdk.CaptureException(ex);
else
SentrySdk.CaptureException(ex, s =>
{
s.AddAttachment(LoggerBase.LogPath, AttachmentType.Default, "text/plain");
});
}
#pragma warning restore CS0162 // Unreachable code detected
else
SentrySdk.CaptureException(ex, s =>
{
s.AddAttachment(LoggerBase.LogPath, AttachmentType.Default, "text/plain");
});
{
SentrySdk.CaptureException(ex);
}

await SentrySdk.FlushAsync(TimeSpan.FromSeconds(10));
}
Expand Down Expand Up @@ -252,13 +274,23 @@ public static async Task ExceptionHandler_ForLoopAsync(Exception ex, ExceptionTy
ExHLoopLastEx_AutoClean(); // Start auto clean loop

Check warning on line 274 in Hi3Helper.Core/Classes/SentryHelper/SentryHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Async method invocation without await expression

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

ex.Data[Mechanism.HandledKey] = exT == ExceptionType.Handled;
if ((bool)(ex.Data[Mechanism.HandledKey] ?? false))
SentrySdk.CaptureException(ex);
if (SentryUploadLog) // Upload log file if enabled
#pragma warning disable CS0162 // Unreachable code detected
// ReSharper disable once HeuristicUnreachableCode
{
if ((bool)(ex.Data[Mechanism.HandledKey] ?? false))
SentrySdk.CaptureException(ex);
else
SentrySdk.CaptureException(ex, s =>
{
s.AddAttachment(LoggerBase.LogPath, AttachmentType.Default, "text/plain");
});
}
#pragma warning restore CS0162 // Unreachable code detected
else
SentrySdk.CaptureException(ex, s =>
{
s.AddAttachment(LoggerBase.LogPath, AttachmentType.Default, "text/plain");
});
{
SentrySdk.CaptureException(ex);
}
}
}
}

0 comments on commit 2391610

Please sign in to comment.