Skip to content

Commit

Permalink
Add Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenquyhy committed Dec 17, 2024
1 parent a971489 commit d60f5fa
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
39 changes: 39 additions & 0 deletions FlightStreamDeck.AddOn/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Sentry;
using Serilog;
using SharpDeck.Connectivity;
using SharpDeck.Extensions.Hosting;
using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;

namespace FlightStreamDeck.AddOn;

Expand All @@ -25,6 +28,8 @@ public partial class App : Application

protected override void OnStartup(StartupEventArgs e)
{
InitializeSentry();

var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
Expand All @@ -48,6 +53,40 @@ protected override void OnStartup(StartupEventArgs e)
}
}

private void InitializeSentry()
{
if (Assembly.GetExecutingAssembly().GetManifestResourceStream("FlightStreamDeck.AddOn.Sentry.txt") is Stream stream)
{
using (stream)
{
using var reader = new StreamReader(stream);
var dsn = reader.ReadLine();
if (!string.IsNullOrWhiteSpace(dsn))
{
DispatcherUnhandledException += App_DispatcherUnhandledException;
SentrySdk.Init(o =>
{
// Tells which project in Sentry to send events to:
o.Dsn = dsn;
// When configuring for the first time, to see what the SDK is doing:
//o.Debug = true;
// Set TracesSampleRate to 1.0 to capture 100% of transactions for tracing.
// We recommend adjusting this value in production.
o.TracesSampleRate = 1.0;
});
}
}
}
}

void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
SentrySdk.CaptureException(e.Exception);

// If you want to avoid the application from crashing:
//e.Handled = true;
}

private IHost? InitializeStreamDeckHost(ServiceCollection serviceCollection)
{
if (Environment.GetCommandLineArgs().Length <= 1)
Expand Down
6 changes: 6 additions & 0 deletions FlightStreamDeck.AddOn/FlightStreamDeck.AddOn.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

<ItemGroup>
<None Remove="icon.ico" />
<None Remove="Sentry.txt" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Sentry.txt" />
</ItemGroup>

<ItemGroup>
Expand All @@ -20,6 +25,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Sentry" Version="4.13.0" />
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.Debug" Version="3.0.0" />
Expand Down
Empty file.

0 comments on commit d60f5fa

Please sign in to comment.