Skip to content
This repository was archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
Added more logging events
Browse files Browse the repository at this point in the history
  • Loading branch information
Avid29 committed May 1, 2022
1 parent 5737d57 commit 6e75dfe
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ public GitHubService(IAnalyticsService analyticsService)
var user = await _gitHubApiService.GetUserAsync(contributor.Name);
return new BindableDeveloper(user, contributor);
}
catch
catch (Exception ex)
{
_analyticsService.Log(LoggedEvent.GitHubRequestFailed, ("Endpoint", "GetDeveloper"), ("Exception", ex.Message));
return null;
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/Quarrel.ViewModels/Services/Analytics/Enums/LoggedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ namespace Quarrel.Services.Analytics.Enums
/// </summary>
public enum LoggedEvent
{
#region App
/// <summary>
/// A subpage opened.
/// </summary>
[StringValue("SubPage Opened")]
SubPageOpened,

/// <summary>
/// A message was sent.
/// </summary>
[StringValue("Message Sent")]
MessageSent,
#endregion

#region Login
/// <summary>
/// The app attempted to login.
Expand All @@ -29,12 +43,16 @@ public enum LoggedEvent
LoginFailed,
#endregion

#region API

/// <summary>
/// Encountered an issue in an http request, but it was handled.
/// </summary>
[StringValue("Http Exception Handled")]
HttpExceptionHandled,

#endregion

#region Gateway
/// <summary>
/// The gateway encountered a known event.
Expand Down Expand Up @@ -87,6 +105,12 @@ public enum LoggedEvent
[StringValue("GitHub Request Failed")]
GitHubRequestFailed,

/// <summary>
/// A request to the Discord Status API failed.
/// </summary>
[StringValue("Discord Status Request Failed")]
DiscordStatusRequestFailed,

#endregion

#region AppServiceConnection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Quarrel.Client.Models.Messages;
using Quarrel.Client.Models.Settings;
using Quarrel.Client.Models.Users;
using Quarrel.Services.Analytics.Enums;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
Expand Down Expand Up @@ -180,6 +181,8 @@ public async Task<Message[]> GetChannelMessagesAsync(IBindableMessageChannel cha
/// <inheritdoc/>
public void SendMessage(ulong channelId, string content)
{
_analyticsService.Log(LoggedEvent.MessageSent);

_quarrelClient.SendMessage(channelId, content);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
using Discord.API.Status.Models;
using Discord.API.Status.Rest;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Quarrel.Services.Analytics;
using Quarrel.Services.Analytics.Enums;
using Quarrel.ViewModels.SubPages.DiscordStatus.Enums;
using Quarrel.ViewModels.SubPages.DiscordStatus.Models;
using Refit;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand All @@ -17,6 +20,8 @@ namespace Quarrel.ViewModels.SubPages.DiscordStatus
/// </summary>
public partial class DiscordStatusViewModel : ObservableObject
{
private readonly IAnalyticsService _analyticsService;

private Index? _status;
private IStatusService? _statusService;

Expand All @@ -29,8 +34,9 @@ public partial class DiscordStatusViewModel : ObservableObject
/// <summary>
/// Initializes a new instance of the <see cref="DiscordStatusViewModel"/> class.
/// </summary>
public DiscordStatusViewModel()
public DiscordStatusViewModel(IAnalyticsService analyticsService)
{
_analyticsService = analyticsService;
_state = DiscordStatusState.Loading;
SetupAndLoad();
}
Expand Down Expand Up @@ -110,8 +116,9 @@ private async void SetupAndLoad()
{
Status = await _statusService.GetStatus();
}
catch
catch (ApiException ex)
{
_analyticsService.Log(LoggedEvent.DiscordStatusRequestFailed, ("Endpoint", "GetStatus"), ("Exception", ex.Message));
}

// Has Data
Expand Down Expand Up @@ -196,7 +203,10 @@ public async void ShowMetrics(string duration)
Guard.IsNotNull(_statusService);
metrics = await _statusService.GetMetrics(duration);
}
catch { }
catch (Exception ex)
{
_analyticsService.Log(LoggedEvent.DiscordStatusRequestFailed, ("Endpoint", "GetMetrics"), ("Exception", ex.Message));
}

if (metrics != null && metrics.Metrics != null && metrics.Metrics.Length > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Microsoft.Toolkit.Mvvm.Input;
using Microsoft.Toolkit.Mvvm.Messaging;
using Quarrel.Messages.Navigation.SubPages;
using Quarrel.Services.Analytics;
using Quarrel.Services.Analytics.Enums;
using System;
using System.Collections.Generic;

Expand All @@ -16,6 +18,7 @@ namespace Quarrel.ViewModels.SubPages.Host
/// </summary>
public partial class SubPageHostViewModel : ObservableRecipient
{
private readonly IAnalyticsService _analyticsService;
private readonly IMessenger _messenger;
private readonly Stack<object> _navStack;

Expand All @@ -24,8 +27,9 @@ public partial class SubPageHostViewModel : ObservableRecipient
/// <summary>
/// Initializes a new instance of the <see cref="SubPageHostViewModel"/> class.
/// </summary>
public SubPageHostViewModel(IMessenger messenger)
public SubPageHostViewModel(IAnalyticsService analyticsService, IMessenger messenger)
{
_analyticsService = analyticsService;
_messenger = messenger;
_navStack = new Stack<object>();

Expand Down Expand Up @@ -69,6 +73,9 @@ private void NavigateToSubPage(Type viewModelType)
_navStack.Push(ContentViewModel);
}

_analyticsService.Log(LoggedEvent.SubPageOpened,
("Type", viewModelType.Name));

ContentViewModel = viewModel;
}

Expand Down

0 comments on commit 6e75dfe

Please sign in to comment.