Skip to content

Commit

Permalink
[Sentry] Use attachment for loaded modules instead
Browse files Browse the repository at this point in the history
Due to breadcrumbs having 8192 char limit
  • Loading branch information
bagusnl committed Jan 2, 2025
1 parent b4a5fb1 commit 2f5ce53
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Hi3Helper.Core/Classes/SentryHelper/SentryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

// ReSharper disable UnusedAutoPropertyAccessor.Global
Expand Down Expand Up @@ -483,8 +485,11 @@ private static Task ExceptionHandlerInner(Exception ex, ExceptionType exT = Exce
}
});

SentrySdk.AddBreadcrumb("Loaded Modules", "AppInfo",
"system.module", modulesInfo.ToDictionary());
var sbModulesInfo = new StringBuilder();
foreach (var (key, value) in modulesInfo)
{
sbModulesInfo.AppendLine($"{key}: {value}");
}

ex.Data[Mechanism.HandledKey] ??= exT == ExceptionType.Handled;

Expand Down Expand Up @@ -513,6 +518,9 @@ private static Task ExceptionHandlerInner(Exception ex, ExceptionType exT = Exce
SentrySdk.CaptureException(ex, s =>
{
s.AddAttachment(LoggerBase.LogPath, AttachmentType.Default, "text/plain");
s.AddAttachment(new MemoryStream(Encoding.UTF8.GetBytes(sbModulesInfo.ToString())),
"LoadedModules.txt", AttachmentType.Default,
"text/plain");
});
}
else
Expand Down

0 comments on commit 2f5ce53

Please sign in to comment.