Skip to content

Commit

Permalink
AppCenter to AppInsights migration. (#562)
Browse files Browse the repository at this point in the history
* Remove AppCenter usage and libraries.

* Remove redundant pacakges and add the app insights sink.

* Diagnostic id support and manipulating telemetries.

* Handling of appdomain unhandled exceptions.

* Remove unused package identity package from mail project.

* Fixing printing.
  • Loading branch information
bkaankose authored Feb 16, 2025
1 parent f0e513b commit c133642
Show file tree
Hide file tree
Showing 27 changed files with 160 additions and 134 deletions.
3 changes: 1 addition & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
<PackageVersion Include="HtmlAgilityPack" Version="1.11.72" />
<PackageVersion Include="Ical.Net" Version="4.3.1" />
<PackageVersion Include="IsExternalInit" Version="1.0.3" />
<PackageVersion Include="Microsoft.AppCenter.Analytics" Version="5.0.6" />
<PackageVersion Include="Microsoft.AppCenter.Crashes" Version="5.0.6" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.2" />
Expand All @@ -42,6 +40,7 @@
<PackageVersion Include="Serilog.Exceptions" Version="8.4.0" />
<PackageVersion Include="Serilog.Sinks.Debug" Version="3.0.0" />
<PackageVersion Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageVersion Include="Serilog.Sinks.ApplicationInsights" Version="4.0.0" />
<PackageVersion Include="SkiaSharp" Version="3.116.1" />
<PackageVersion Include="sqlite-net-pcl" Version="1.9.172" />
<PackageVersion Include="SqlKata" Version="4.0.1" />
Expand Down
5 changes: 5 additions & 0 deletions Wino.Core.Domain/Interfaces/IApplicationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@ public interface IApplicationConfiguration
/// Files here are short-lived and can be deleted by system.
/// </summary>
string ApplicationTempFolderPath { get; set; }

/// <summary>
/// Application insights instrumentation key.
/// </summary>
string ApplicationInsightsInstrumentationKey { get; }
}
}
1 change: 1 addition & 0 deletions Wino.Core.Domain/Interfaces/IPreferencesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public interface IPreferencesService
DayOfWeek WorkingDayStart { get; set; }
DayOfWeek WorkingDayEnd { get; set; }
double HourHeight { get; set; }
string DiagnosticId { get; set; }

CalendarSettings GetCurrentCalendarSettings();

Expand Down
2 changes: 2 additions & 0 deletions Wino.Core.Domain/Translations/en_US/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@
"SettingsDeleteProtection_Title": "Permanent Delete Protection",
"SettingsDiagnostics_Description": "For developers",
"SettingsDiagnostics_Title": "Diagnostics",
"SettingsDiagnostics_DiagnosticId_Title": "Diagnostic Id",
"SettingsDiagnostics_DiagnosticId_Description": "Share this Id with the developers when asked to get help for the issues you experience in Wino Mail.",
"SettingsDiscord_Description": "Get regular development updates, join roadmap discussions and provide feedback.",
"SettingsDiscord_Title": "Discord Channel",
"SettingsElementThemeSelectionDisabled": "Element theme selection is disabled when application theme is selected other than Default.",
Expand Down
6 changes: 6 additions & 0 deletions Wino.Core.UWP/Services/PreferencesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ public ServerBackgroundMode ServerTerminationBehavior
set => SaveProperty(propertyName: nameof(ServerTerminationBehavior), value);
}

public string DiagnosticId
{
get => _configurationService.Get(nameof(DiagnosticId), Guid.NewGuid().ToString());
set => SaveProperty(propertyName: nameof(DiagnosticId), value);
}

public DayOfWeek FirstDayOfWeek
{
get => _configurationService.Get(nameof(FirstDayOfWeek), DayOfWeek.Monday);
Expand Down
1 change: 1 addition & 0 deletions Wino.Core.UWP/Styles/Colors.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<SolidColorBrush x:Key="FolderSyncBrush">#1abc9c</SolidColorBrush>

<SolidColorBrush x:Key="DiagnosticIdCopyBrush">#ff7675</SolidColorBrush>
<SolidColorBrush x:Key="AliasUnverifiedBrush">#ff7675</SolidColorBrush>
<SolidColorBrush x:Key="AliasVerifiedBrush">#1abc9c</SolidColorBrush>

Expand Down
1 change: 0 additions & 1 deletion Wino.Core.UWP/Wino.Core.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
<PackageReference Include="CommunityToolkit.Uwp.Extensions" />
<PackageReference Include="CommunityToolkit.WinUI.Notifications" />
<PackageReference Include="CommunityToolkit.Uwp.Controls.TabbedCommandBar" />
<PackageReference Include="Microsoft.AppCenter.Analytics" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" />
<PackageReference Include="Win2D.uwp" />
<PackageReference Include="EmailValidation" />
Expand Down
48 changes: 15 additions & 33 deletions Wino.Core.UWP/WinoApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AppCenter;
using Microsoft.AppCenter.Analytics;
using Microsoft.AppCenter.Crashes;
using Microsoft.Extensions.DependencyInjection;
using Nito.AsyncEx;
using Serilog;
Expand Down Expand Up @@ -40,24 +37,16 @@ public abstract class WinoApplication : Application
protected IDatabaseService DatabaseService { get; }
protected ITranslationService TranslationService { get; }

// Order matters.
private List<IInitializeAsync> initializeServices => new List<IInitializeAsync>()
{
DatabaseService,
TranslationService,
ThemeService,
};

public abstract string AppCenterKey { get; }

protected WinoApplication()
{
ConfigureAppCenter();
ConfigurePrelaunch();

Services = ConfigureServices();

AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
UnhandledException += OnAppUnhandledException;

Resuming += OnResuming;
Suspending += OnSuspending;

Expand All @@ -77,6 +66,18 @@ protected WinoApplication()
ConfigureLogging();
}

private void CurrentDomain_UnhandledException(object sender, System.UnhandledExceptionEventArgs e)
=> Log.Fatal(e.ExceptionObject as Exception, "AppDomain Unhandled Exception");

private void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
=> Log.Error(e.Exception, "Unobserved Task Exception");

private void OnAppUnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
{
Log.Fatal(e.Exception, "Unhandled Exception");
e.Handled = true;
}

protected abstract void OnApplicationCloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e);
protected abstract IEnumerable<ActivationHandler> GetActivationHandlers();
protected abstract ActivationHandler<IActivatedEventArgs> GetDefaultActivationHandler();
Expand Down Expand Up @@ -208,29 +209,12 @@ private void TryRegisterAppCloseChange()
catch { }
}



private void ConfigurePrelaunch()
{
if (ApiInformation.IsMethodPresent("Windows.ApplicationModel.Core.CoreApplication", "EnablePrelaunch"))
CoreApplication.EnablePrelaunch(true);
}

private void OnAppUnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
{
var parameters = new Dictionary<string, string>()
{
{ "BaseMessage", e.Exception.GetBaseException().Message },
{ "BaseStackTrace", e.Exception.GetBaseException().StackTrace },
{ "StackTrace", e.Exception.StackTrace },
{ "Message", e.Exception.Message },
};

Log.Error(e.Exception, "[Wino Crash]");

Crashes.TrackError(e.Exception, parameters);
Analytics.TrackEvent("Wino Crashed", parameters);
}


public virtual async void OnResuming(object sender, object e)
Expand All @@ -255,8 +239,6 @@ public virtual async void OnResuming(object sender, object e)
public virtual void OnSuspending(object sender, SuspendingEventArgs e) { }

public abstract IServiceProvider ConfigureServices();
public void ConfigureAppCenter()
=> AppCenter.Start(AppCenterKey, typeof(Analytics), typeof(Crashes));

public void ConfigureLogging()
{
Expand Down
19 changes: 19 additions & 0 deletions Wino.Core.ViewModels/AboutPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Input;
using Serilog;
using Wino.Core.Domain;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
Expand All @@ -13,6 +14,7 @@ public partial class AboutPageViewModel : CoreBaseViewModel
private readonly IMailDialogService _dialogService;
private readonly INativeAppService _nativeAppService;
private readonly IApplicationConfiguration _appInitializerService;
private readonly IClipboardService _clipboardService;
private readonly IFileService _fileService;
private readonly ILogInitializer _logInitializer;

Expand All @@ -29,6 +31,7 @@ public AboutPageViewModel(IStoreRatingService storeRatingService,
INativeAppService nativeAppService,
IPreferencesService preferencesService,
IApplicationConfiguration appInitializerService,
IClipboardService clipboardService,
IFileService fileService,
ILogInitializer logInitializer)
{
Expand All @@ -37,6 +40,7 @@ public AboutPageViewModel(IStoreRatingService storeRatingService,
_nativeAppService = nativeAppService;
_logInitializer = logInitializer;
_appInitializerService = appInitializerService;
_clipboardService = clipboardService;
_fileService = fileService;

PreferencesService = preferencesService;
Expand Down Expand Up @@ -65,6 +69,21 @@ private void PreferencesChanged(object sender, string e)
}
}

[RelayCommand]
private async Task CopyDiagnosticId()
{
try
{
await _clipboardService.CopyClipboardAsync(PreferencesService.DiagnosticId);
_dialogService.InfoBarMessage(Translator.Buttons_Copy, string.Format(Translator.ClipboardTextCopied_Message, "Id"), InfoBarMessageType.Success);
}
catch (Exception ex)
{
_dialogService.InfoBarMessage(Translator.GeneralTitle_Error, string.Format(Translator.ClipboardTextCopyFailed_Message, "Id"), InfoBarMessageType.Error);
Log.Error(ex, "Failed to copy diagnostic id to clipboard.");
}
}

[RelayCommand]
private async Task ShareWinoLogAsync()
{
Expand Down
1 change: 0 additions & 1 deletion Wino.Core.ViewModels/Wino.Core.ViewModels.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AppCenter.Crashes" />
<PackageReference Include="Microsoft.Identity.Client" />
<PackageReference Include="System.Reactive" />
</ItemGroup>
Expand Down
4 changes: 0 additions & 4 deletions Wino.Core/Wino.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
<PackageReference Include="morelinq" />
<PackageReference Include="Nito.AsyncEx.Tasks" />
<PackageReference Include="NodaTime" />
<PackageReference Include="Serilog" />
<PackageReference Include="Serilog.Exceptions" />
<PackageReference Include="Serilog.Sinks.Debug" />
<PackageReference Include="Serilog.Sinks.File" />
<PackageReference Include="SkiaSharp" />
<PackageReference Include="SqlKata" />
<PackageReference Include="System.Text.Encoding.CodePages" />
Expand Down
42 changes: 0 additions & 42 deletions Wino.Core/WinoErrors.cs

This file was deleted.

5 changes: 1 addition & 4 deletions Wino.Mail.ViewModels/AccountManagementViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.AppCenter.Crashes;
using Serilog;
using Wino.Core;
using Wino.Core.Domain;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
Expand Down Expand Up @@ -274,8 +272,7 @@ private async Task AddNewAccountAsync()
}
catch (Exception ex)
{
Log.Error(ex, WinoErrors.AccountCreation);
Crashes.TrackError(ex);
Log.Error(ex, "Failed to create account.");

DialogService.InfoBarMessage(Translator.Info_AccountCreationFailedTitle, ex.Message, InfoBarMessageType.Error);

Expand Down
8 changes: 3 additions & 5 deletions Wino.Mail.ViewModels/AppShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.AppCenter.Crashes;
using MoreLinq;
using MoreLinq.Extensions;
using Serilog;
using Wino.Core;
using Wino.Core.Domain;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
Expand Down Expand Up @@ -301,7 +299,7 @@ private async Task ConfigureBackgroundTasksAsync()
}
catch (Exception ex)
{
Crashes.TrackError(ex);
Log.Error(ex, "Failed to configure background tasks.");

_dialogService.InfoBarMessage(Translator.Info_BackgroundExecutionUnknownErrorTitle, Translator.Info_BackgroundExecutionUnknownErrorMessage, InfoBarMessageType.Error);
}
Expand Down Expand Up @@ -373,7 +371,7 @@ private async Task ProcessLaunchOptionsAsync()
}
catch (Exception ex)
{
Log.Error(ex, WinoErrors.StartupAccountExtendFail);
Log.Error(ex, "Failed to process launch options.");
}
}

Expand Down Expand Up @@ -474,7 +472,7 @@ private async Task NavigateSpecialFolderAsync(MailAccount account, SpecialFolder
}
catch (Exception ex)
{
Log.Error(ex, WinoErrors.AccountNavigateInboxFail);
Log.Error(ex, "Failed to navigate to Inbox.");
}
}

Expand Down
8 changes: 2 additions & 6 deletions Wino.Mail.ViewModels/MailListPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.AppCenter.Crashes;
using MoreLinq;
using Nito.AsyncEx;
using Serilog;
using Wino.Core;
using Wino.Core.Domain;
using Wino.Core.Domain.Entities.Mail;
using Wino.Core.Domain.Entities.Shared;
Expand Down Expand Up @@ -844,11 +842,9 @@ private async Task InitializeFolderAsync()
Debugger.Break();

if (IsInSearchMode)
Log.Error(ex, WinoErrors.SearchFailed);
Log.Error(ex, "Failed to perform search.");
else
Log.Error(ex, WinoErrors.MailListRefreshFolder);

Crashes.TrackError(ex);
Log.Error(ex, "Failed to refresh listed mails.");
}
finally
{
Expand Down
Loading

0 comments on commit c133642

Please sign in to comment.