From 5b2262428ffd87b135ea5f23fcbbb87ea8683407 Mon Sep 17 00:00:00 2001 From: Samrat Banerjee <106741933+SamratB8@users.noreply.github.com> Date: Mon, 13 Jul 2026 21:18:03 +0530 Subject: [PATCH] Add Sentry error monitoring --- src/WslStudio.App/App.xaml.cs | 32 +++++++++++++++++++++++--- src/WslStudio.App/WslStudio.App.csproj | 1 + 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/WslStudio.App/App.xaml.cs b/src/WslStudio.App/App.xaml.cs index f7f08f9..f391034 100644 --- a/src/WslStudio.App/App.xaml.cs +++ b/src/WslStudio.App/App.xaml.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.UI.Xaml; +using Sentry; using WslStudio.App.Services; namespace WslStudio.App; @@ -8,10 +9,27 @@ namespace WslStudio.App; public partial class App : Microsoft.UI.Xaml.Application { private readonly IHost _host; + private readonly IDisposable _sentry; private Window? _window; public App() { + _sentry = SentrySdk.Init(options => + { + // Reads the DSN from the SENTRY_DSN environment variable. + // Sentry remains disabled if the variable is missing or empty. + options.Dsn = Environment.GetEnvironmentVariable("SENTRY_DSN"); + +#if DEBUG + // Useful while initially testing the integration. + options.Debug = true; +#else + options.Debug = false; +#endif + + options.AutoSessionTracking = true; + }); + InitializeComponent(); HostApplicationBuilder builder = Host.CreateApplicationBuilder(); @@ -31,7 +49,15 @@ protected override void OnLaunched(LaunchActivatedEventArgs args) private async void OnMainWindowClosed(object sender, WindowEventArgs args) { - await _host.StopAsync(); - _host.Dispose(); + try + { + await _host.StopAsync(); + await SentrySdk.FlushAsync(TimeSpan.FromSeconds(2)); + } + finally + { + _host.Dispose(); + _sentry.Dispose(); + } } -} +} \ No newline at end of file diff --git a/src/WslStudio.App/WslStudio.App.csproj b/src/WslStudio.App/WslStudio.App.csproj index 84313c9..a90d6db 100644 --- a/src/WslStudio.App/WslStudio.App.csproj +++ b/src/WslStudio.App/WslStudio.App.csproj @@ -21,6 +21,7 @@ +