Skip to content

Commit 71d9d67

Browse files
committed
Add Sentry
1 parent a971489 commit 71d9d67

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

FlightStreamDeck.AddOn/App.xaml.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
using Microsoft.Extensions.Configuration;
55
using Microsoft.Extensions.DependencyInjection;
66
using Microsoft.Extensions.Hosting;
7+
using Sentry;
78
using Serilog;
89
using SharpDeck.Connectivity;
910
using SharpDeck.Extensions.Hosting;
1011
using System;
1112
using System.IO;
13+
using System.Reflection;
1214
using System.Threading.Tasks;
1315
using System.Windows;
16+
using System.Windows.Threading;
1417

1518
namespace FlightStreamDeck.AddOn;
1619

@@ -23,6 +26,11 @@ public partial class App : Application
2326

2427
private MainWindow? mainWindow = null;
2528

29+
public App()
30+
{
31+
InitializeSentry();
32+
}
33+
2634
protected override void OnStartup(StartupEventArgs e)
2735
{
2836
var builder = new ConfigurationBuilder()
@@ -48,6 +56,44 @@ protected override void OnStartup(StartupEventArgs e)
4856
}
4957
}
5058

59+
private void InitializeSentry()
60+
{
61+
if (Assembly.GetExecutingAssembly().GetManifestResourceStream("FlightStreamDeck.AddOn.Sentry.txt") is Stream stream)
62+
{
63+
using (stream)
64+
{
65+
using var reader = new StreamReader(stream);
66+
var dsn = reader.ReadLine();
67+
if (!string.IsNullOrWhiteSpace(dsn))
68+
{
69+
DispatcherUnhandledException += App_DispatcherUnhandledException;
70+
SentrySdk.Init(o =>
71+
{
72+
// Tells which project in Sentry to send events to:
73+
o.Dsn = dsn;
74+
// When configuring for the first time, to see what the SDK is doing:
75+
//o.Debug = true;
76+
// Set TracesSampleRate to 1.0 to capture 100% of transactions for tracing.
77+
// We recommend adjusting this value in production.
78+
o.TracesSampleRate = 1.0;
79+
// Enable Global Mode since this is a client app
80+
o.IsGlobalModeEnabled = true;
81+
82+
o.AutoSessionTracking = true;
83+
});
84+
}
85+
}
86+
}
87+
}
88+
89+
void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
90+
{
91+
SentrySdk.CaptureException(e.Exception);
92+
93+
// If you want to avoid the application from crashing:
94+
//e.Handled = true;
95+
}
96+
5197
private IHost? InitializeStreamDeckHost(ServiceCollection serviceCollection)
5298
{
5399
if (Environment.GetCommandLineArgs().Length <= 1)

FlightStreamDeck.AddOn/FlightStreamDeck.AddOn.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
<ItemGroup>
1414
<None Remove="icon.ico" />
15+
<None Remove="Sentry.txt" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<EmbeddedResource Include="Sentry.txt" />
1520
</ItemGroup>
1621

1722
<ItemGroup>
@@ -20,6 +25,7 @@
2025
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.0" />
2126
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
2227
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
28+
<PackageReference Include="Sentry" Version="4.13.0" />
2329
<PackageReference Include="Serilog" Version="4.2.0" />
2430
<PackageReference Include="Serilog.Extensions.Hosting" Version="9.0.0" />
2531
<PackageReference Include="Serilog.Sinks.Debug" Version="3.0.0" />

FlightStreamDeck.AddOn/Sentry.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)