Add Sentry error tracking

This commit is contained in:
Kamil Trzciński 2022-12-12 15:08:00 +01:00
parent 2b89b22d41
commit 10a8598b82
9 changed files with 106 additions and 36 deletions

View file

@ -7,9 +7,20 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<Target Name="SetSourceRevisionId" BeforeTargets="InitializeSourceControlInformation">
<Exec
Command="git describe --long --always --dirty --exclude=* --abbrev=8"
ConsoleToMSBuild="True"
IgnoreExitCode="True"
>
<Output PropertyName="SourceRevisionId" TaskParameter="ConsoleOutput"/>
</Exec>
</Target>
<ItemGroup>
<PackageReference Include="Autoupdater.NET.Official" Version="1.7.6" />
<PackageReference Include="LibreHardwareMonitorLib" Version="0.9.1" />
<PackageReference Include="Sentry" Version="3.24.0" />
<PackageReference Include="TaskScheduler" Version="2.10.1" />
</ItemGroup>

View file

@ -1,6 +1,5 @@
using System.Security.Principal;
using System.Security.AccessControl;
using AutoUpdaterDotNET;
using Microsoft.Win32;
using System.Diagnostics;
@ -157,21 +156,30 @@ namespace CommonHelpers
}
}
public static void WithSentry(Action action)
{
using (Sentry.SentrySdk.Init(Log.SentryOptions))
{
action();
}
}
public static String MachineID
{
get
{
try
{
using (var registryKey = Registry.CurrentUser.OpenSubKey(@"Software\SteamDeckTools"))
using (var registryKey = Registry.CurrentUser.OpenSubKey(@"Software\SteamDeckTools", true))
{
var machineID = registryKey?.GetValue("MachineID") as string;
if (machineID is not null)
return machineID;
if (machineID is null)
{
registryKey?.SetValue("MachineID", Guid.NewGuid().ToString());
machineID = registryKey?.GetValue("MachineID") as string;
}
machineID = Guid.NewGuid().ToString();
registryKey?.SetValue("MachineID", machineID);
return machineID;
return machineID ?? "undefined";
}
}
catch (Exception)

View file

@ -1,9 +1,12 @@
using System.Diagnostics;
using System.Reflection;
namespace CommonHelpers
{
public static class Log
{
internal const String SENTRY_DSN = "https://a6f1925b30fe43529aa7cefd0af7b8a4@o37791.ingest.sentry.io/4504316313993216";
#if DEBUG
private static bool LogToTrace = true;
#else
@ -11,6 +14,22 @@ namespace CommonHelpers
#endif
private static bool LogToConsole = Environment.UserInteractive;
internal static void SentryOptions(Sentry.SentryOptions o)
{
o.Dsn = Log.SENTRY_DSN;
o.Environment = File.Exists("Uninstaller.exe") ? "setup_" : "zip_";
o.Environment += Instance.IsDEBUG ? "debug" : "release";
o.TracesSampleRate = 1.0;
o.IsGlobalModeEnabled = true;
o.DefaultTags.Add("MachineID", Instance.MachineID);
var releaseVersion = typeof(Log).Assembly.GetCustomAttributes<AssemblyInformationalVersionAttribute>().FirstOrDefault();
if (releaseVersion is not null)
{
o.Release = releaseVersion.InformationalVersion;
}
}
public static void TraceLine(string format, params object?[] arg)
{
if (!LogToTrace && !LogToConsole)
@ -22,5 +41,14 @@ namespace CommonHelpers
if (LogToConsole)
Console.WriteLine(line);
}
public static void TraceException(String type, Exception e)
{
TraceLine("{0}: Exception: {1}", type, e);
Sentry.SentrySdk.CaptureException(e, scope =>
{
scope.SetTag("type", type);
});
}
}
}

View file

@ -7,14 +7,16 @@ using LibreHardwareMonitor.Hardware;
using CommonHelpers;
namespace FanControl
{
{
internal class Program
{
static void Main(string[] args)
{
ApplicationConfiguration.Initialize();
Application.Run(new FanControlForm());
Instance.WithSentry(() =>
{
ApplicationConfiguration.Initialize();
Application.Run(new FanControlForm());
});
}
}
}

View file

@ -1,3 +1,4 @@
using CommonHelpers;
using RTSSSharedMemoryNET;
using System.Diagnostics;
@ -8,12 +9,15 @@ namespace PerformanceOverlay
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
using (var controller = new Controller())
Instance.WithSentry(() =>
{
Application.Run();
}
ApplicationConfiguration.Initialize();
using (var controller = new Controller())
{
Application.Run();
}
});
}
}
}

View file

@ -14,24 +14,27 @@ namespace PowerControl
[STAThread]
static void Main()
{
if (Settings.Default.EnableExperimentalFeatures)
Instance.WithSentry(() =>
{
for (int i = 0; !VangoghGPU.IsSupported; i++)
if (Settings.Default.EnableExperimentalFeatures)
{
Instance.WithGlobalMutex(1000, () => VangoghGPU.Detect());
if (VangoghGPU.IsSupported)
Thread.Sleep(300);
for (int i = 0; !VangoghGPU.IsSupported; i++)
{
Instance.WithGlobalMutex(1000, () => VangoghGPU.Detect());
if (VangoghGPU.IsSupported)
Thread.Sleep(300);
}
}
}
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
using (var controller = new Controller())
{
Application.Run();
}
using (var controller = new Controller())
{
Application.Run();
}
});
}
}
}

View file

@ -27,3 +27,4 @@
- Add `Updater.exe` that can update to latest release and debug
- Add `Setup.exe` installer to install all except RTSS
- Fix `Use X360 with Steam` that was broken with `0.5.33`
- Add `Sentry` error tracking

View file

@ -1,3 +1,5 @@
using CommonHelpers;
namespace SteamController
{
internal static class Program
@ -8,14 +10,17 @@ namespace SteamController
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
using (var controller = new Controller())
Instance.WithSentry(() =>
{
Application.Run();
}
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
using (var controller = new Controller())
{
Application.Run();
}
});
}
}
}

View file

@ -17,6 +17,14 @@ namespace Updater
/// </summary>
[STAThread]
static void Main()
{
Instance.WithSentry(() =>
{
Run();
});
}
static void Run()
{
bool firstRun = Environment.GetCommandLineArgs().Contains("-first");
bool userCheck = Environment.GetCommandLineArgs().Contains("-user");