Skip to content

Commit

Permalink
Add Sentry Error Tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
breadbyte committed Feb 10, 2024
1 parent 1e60b61 commit 59a0aed
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions MinecraftClient/McClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using MinecraftClient.Protocol.Session;
using MinecraftClient.Proxy;
using MinecraftClient.Scripting;
using Sentry;
using static MinecraftClient.Settings;

namespace MinecraftClient
Expand Down Expand Up @@ -190,6 +191,22 @@ public McClient(SessionToken session, PlayerKeyPair? playerKeyPair, string serve
Log.WarnEnabled = Config.Logging.WarningMessages;
Log.ErrorEnabled = Config.Logging.ErrorMessages;

// SENTRY: Send our client version and server version to Sentry
SentrySdk.ConfigureScope(scope =>
{
scope.SetTag("Server Version", protocolversion.ToString());
if (Program.BuildInfo != null)
scope.SetTag("MCC Build", Program.BuildInfo);
if (forgeInfo != null)
scope.SetTag("Forge Version", forgeInfo?.Version.ToString());
scope.Contexts["Client Information"] = new {
TerrainAndMovementsEnabled = terrainAndMovementsEnabled,
InventoryHandlingEnabled = inventoryHandlingEnabled,
EntityHandlingEnabled = entityHandlingEnabled
};
});

/* Load commands from Commands namespace */
LoadCommands();

Expand Down
1 change: 1 addition & 0 deletions MinecraftClient/MinecraftClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0.3" />
<PackageReference Include="Samboy063.Tomlet" Version="5.0.1" />
<PackageReference Include="Sentry" Version="4.1.0" />
<PackageReference Include="SingleFileExtractor.Core" Version="1.0.1" />
<PackageReference Include="starksoft.aspen" Version="1.1.8">
<NoWarn>NU1701</NoWarn>
Expand Down
9 changes: 9 additions & 0 deletions MinecraftClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using MinecraftClient.Protocol.Session;
using MinecraftClient.Scripting;
using MinecraftClient.WinAPI;
using Sentry;
using Tomlet;
using static MinecraftClient.Settings;
using static MinecraftClient.Settings.ConsoleConfigHealper.ConsoleConfig;
Expand Down Expand Up @@ -58,6 +59,14 @@ static class Program
/// </summary>
static void Main(string[] args)
{
// SENTRY: Initialize Sentry SDK
SentrySdk.Init(options => {
options.Dsn = "https://a64e21ac3d5a52e1d98893a251bba89d@o405596.ingest.sentry.io/4506723841015808";
options.AutoSessionTracking = true;
options.IsGlobalModeEnabled = true;
options.EnableTracing = true;
});

Task.Run(() =>
{
// "ToLower" require "CultureInfo" to be initialized on first run, which can take a lot of time.
Expand Down

0 comments on commit 59a0aed

Please sign in to comment.