mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Add Sentry Error Tracking (#2670)
* Add Sentry Error Tracking * Omit personally identifiable information and add additional sentry context * Remove debug message * Make sentry opt-out and add related notices and strings Also add Minecraft Version to error context * Update build to send release info to sentry * Adjust sentry error tracking - Send the user-friendly Minecraft Version in the error logs - Capture exceptions in more parts of the application We now capture exceptions from the following locations: - Protocol18 (1.8+) Packet errors - Errors during client initialization phase (When client is about to start, session keys are NEVER sent to sentry) * Make Sentry DSN configurable and repository-specific The Sentry DSN will automatically be filled out on the main repository through the Github Actions build. * Update build-and-release.yml Update sed command * style: change variable name nitpick, just to make it a little bit more descriptive * Add Sentry branding in README. * remove old code (merge conflict)
This commit is contained in:
parent
8756ff5b3c
commit
08551097c6
11 changed files with 148 additions and 24 deletions
|
|
@ -16,6 +16,7 @@ using MinecraftClient.Protocol.ProfileKey;
|
|||
using MinecraftClient.Protocol.Session;
|
||||
using MinecraftClient.Scripting;
|
||||
using MinecraftClient.WinAPI;
|
||||
using Sentry;
|
||||
using Tomlet;
|
||||
using static MinecraftClient.Settings;
|
||||
using static MinecraftClient.Settings.ConsoleConfigHealper.ConsoleConfig;
|
||||
|
|
@ -50,14 +51,31 @@ namespace MinecraftClient
|
|||
public static readonly string? BuildInfo = null;
|
||||
|
||||
private static Tuple<Thread, CancellationTokenSource>? offlinePrompt = null;
|
||||
private static IDisposable _sentrySdk;
|
||||
private static bool useMcVersionOnce = false;
|
||||
private static string settingsIniPath = "MinecraftClient.ini";
|
||||
|
||||
// [SENTRY]
|
||||
// Setting this string to an empty string will disable Sentry
|
||||
private const string SentryDSN = "";
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point of Minecraft Console Client
|
||||
/// </summary>
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// [SENTRY] Initialize Sentry SDK only if the DSN is not empty
|
||||
if (SentryDSN != string.Empty) {
|
||||
_sentrySdk = SentrySdk.Init(options =>
|
||||
{
|
||||
options.Dsn = SentryDSN;
|
||||
options.AutoSessionTracking = true;
|
||||
options.IsGlobalModeEnabled = true;
|
||||
options.EnableTracing = true;
|
||||
options.SendDefaultPii = false;
|
||||
});
|
||||
}
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
// "ToLower" require "CultureInfo" to be initialized on first run, which can take a lot of time.
|
||||
|
|
@ -139,6 +157,12 @@ namespace MinecraftClient
|
|||
if (newlyGenerated)
|
||||
ConsoleIO.WriteLineFormatted("§c" + Translations.mcc_settings_generated);
|
||||
ConsoleIO.WriteLine(Translations.mcc_run_with_default_settings);
|
||||
|
||||
// Only show the Sentry message if the DSN is not empty
|
||||
// as Sentry will not be initialized if the DSN is empty
|
||||
if (SentryDSN != string.Empty) {
|
||||
ConsoleIO.WriteLine(Translations.mcc_sentry_logging);
|
||||
}
|
||||
}
|
||||
else if (!loadSucceed)
|
||||
{
|
||||
|
|
@ -182,6 +206,9 @@ namespace MinecraftClient
|
|||
ConsoleIO.WriteLine(string.Format(Translations.mcc_help_us_translate, Settings.TranslationProjectUrl));
|
||||
WriteBackSettings(true); // format
|
||||
}
|
||||
|
||||
if (!Config.Main.Advanced.EnableSentry)
|
||||
_sentrySdk.Dispose();
|
||||
}
|
||||
|
||||
//Other command-line arguments
|
||||
|
|
@ -632,6 +659,9 @@ namespace MinecraftClient
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// [SENTRY]
|
||||
SentrySdk.CaptureException(e);
|
||||
|
||||
ConsoleIO.WriteLine(e.Message);
|
||||
ConsoleIO.WriteLine(e.StackTrace ?? "");
|
||||
HandleFailure(); // Other error
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue