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:
breadbyte 2024-06-22 06:41:13 +08:00 committed by GitHub
parent 8756ff5b3c
commit 08551097c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 148 additions and 24 deletions

View file

@ -24,6 +24,7 @@ using MinecraftClient.Protocol.ProfileKey;
using MinecraftClient.Protocol.Session;
using MinecraftClient.Proxy;
using MinecraftClient.Scripting;
using Sentry;
using static MinecraftClient.Settings;
using static MinecraftClient.Settings.MainConfigHelper.MainConfig.GeneralConfig;
@ -370,6 +371,10 @@ namespace MinecraftClient.Protocol.Handlers
/// <returns>TRUE if the packet was processed, FALSE if ignored or unknown</returns>
internal bool HandlePacket(int packetId, Queue<byte> packetData)
{
// This copy is necessary because by the time we get to the catch block,
// the packetData queue will have been processed and the data will be lost
var _copy = packetData.ToArray();
try
{
switch (currentState)
@ -430,7 +435,7 @@ namespace MinecraftClient.Protocol.Handlers
World.StoreDimensionList(registryCodec);
break;
case ConfigurationPacketTypesIn.RemoveResourcePack:
if (dataTypes.ReadNextBool(packetData)) // Has UUID
dataTypes.ReadNextUUID(packetData); // UUID
@ -461,7 +466,7 @@ namespace MinecraftClient.Protocol.Handlers
innerException.InnerException is SocketException)
throw; //Thread abort or Connection lost rather than invalid data
throw new System.IO.InvalidDataException(
var exception = new System.IO.InvalidDataException(
string.Format(Translations.exception_packet_process,
packetPalette.GetIncomingTypeById(packetId),
packetId,
@ -469,6 +474,21 @@ namespace MinecraftClient.Protocol.Handlers
currentState == CurrentState.Login,
innerException.GetType()),
innerException);
SentrySdk.AddBreadcrumb(new Breadcrumb("S -> C Packet", "network", new Dictionary<string, string>()
{
{ "Packet ID", packetId.ToString() },
{ "Packet Type ", packetPalette.GetIncomingTypeById(packetId).ToString() },
{ "Protocol Version", protocolVersion.ToString() },
{ "Minecraft Version", ProtocolHandler.ProtocolVersion2MCVer(protocolVersion) },
{ "Current State", currentState.ToString() },
{ "Packet Data", string.Join(" ", _copy.Select(b => b.ToString("X2"))) },
{ "Inner Exception", innerException.GetType().ToString() }
}, "packet", BreadcrumbLevel.Error));
SentrySdk.CaptureException(exception);
throw exception;
}
return true;
@ -4561,4 +4581,4 @@ namespace MinecraftClient.Protocol.Handlers
Configuration,
Play
}
}
}