Skip to content

Commit

Permalink
Add events for core telemetry (#3546)
Browse files Browse the repository at this point in the history
  • Loading branch information
krschau authored Aug 7, 2024
1 parent d8380da commit 285ff3b
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 13 deletions.
32 changes: 32 additions & 0 deletions common/TelemetryEvents/PageLoadedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Diagnostics.Tracing;
using DevHome.Common.Helpers;
using DevHome.Telemetry;
using Microsoft.Diagnostics.Telemetry;
using Microsoft.Diagnostics.Telemetry.Internal;

namespace DevHome.Common.TelemetryEvents;

[EventData]
public class PageLoadedEvent : EventBase
{
public override PartA_PrivTags PartA_PrivTags => PrivTags.ProductAndServicePerformance;

public Guid DeploymentIdentifier { get; }

public string PageName { get; }

public PageLoadedEvent(string pageName)
{
DeploymentIdentifier = Deployment.Identifier;
PageName = pageName;
}

public override void ReplaceSensitiveStrings(Func<string, string> replaceSensitiveStrings)
{
// No sensitive strings to replace.
}
}
6 changes: 5 additions & 1 deletion src/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using DevHome.SetupFlow.Extensions;
using DevHome.SetupFlow.Services;
using DevHome.Telemetry;
using DevHome.TelemetryEvents;
using DevHome.Utilities.Extensions;
using DevHome.ViewModels;
using DevHome.Views;
Expand Down Expand Up @@ -178,6 +179,9 @@ public App()

UnhandledException += App_UnhandledException;
AppInstance.GetCurrent().Activated += OnActivated;

TelemetryFactory.Get<ITelemetry>().Log("DevHome_Started_Event", LogLevel.Critical, new DevHomeStartedEvent());
Log.Information("Dev Home Started.");
}

public void ShowMainWindow()
Expand Down Expand Up @@ -209,7 +213,7 @@ private async void App_UnhandledException(object sender, Microsoft.UI.Xaml.Unhan
Environment.FailFast(e.Message, e.Exception);
}

protected async override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
protected async override void OnLaunched(LaunchActivatedEventArgs args)
{
base.OnLaunched(args);
await Task.WhenAll(
Expand Down
10 changes: 2 additions & 8 deletions src/TelemetryEvents/DevHomeClosedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@ namespace DevHome.TelemetryEvents;
[EventData]
public class DevHomeClosedEvent : EventBase
{
public double ElapsedTime
{
get;
}
public double ElapsedTime { get; }

public Guid DeploymentIdentifier
{
get;
}
public Guid DeploymentIdentifier { get; }

public override PartA_PrivTags PartA_PrivTags => PrivTags.ProductAndServiceUsage;

Expand Down
31 changes: 31 additions & 0 deletions src/TelemetryEvents/DevHomeInitializationEndedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Diagnostics.Tracing;
using DevHome.Common.Helpers;
using DevHome.Telemetry;
using Microsoft.Diagnostics.Telemetry;
using Microsoft.Diagnostics.Telemetry.Internal;
using Serilog;

namespace DevHome.TelemetryEvents;

[EventData]
public class DevHomeInitializationEndedEvent : EventBase
{
public Guid DeploymentIdentifier { get; }

public override PartA_PrivTags PartA_PrivTags => PrivTags.ProductAndServicePerformance;

public DevHomeInitializationEndedEvent()
{
DeploymentIdentifier = Deployment.Identifier;
var log = Log.ForContext("SourceContext", nameof(DevHomeInitializationEndedEvent));
log.Debug($"DevHome Initialization Started Event, Identifier: {DeploymentIdentifier}");
}

public override void ReplaceSensitiveStrings(Func<string, string> replaceSensitiveStrings)
{
// No sensitive strings to replace.
}
}
31 changes: 31 additions & 0 deletions src/TelemetryEvents/DevHomeInitializationStartedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Diagnostics.Tracing;
using DevHome.Common.Helpers;
using DevHome.Telemetry;
using Microsoft.Diagnostics.Telemetry;
using Microsoft.Diagnostics.Telemetry.Internal;
using Serilog;

namespace DevHome.TelemetryEvents;

[EventData]
public class DevHomeInitializationStartedEvent : EventBase
{
public Guid DeploymentIdentifier { get; }

public override PartA_PrivTags PartA_PrivTags => PrivTags.ProductAndServicePerformance;

public DevHomeInitializationStartedEvent()
{
DeploymentIdentifier = Deployment.Identifier;
var log = Log.ForContext("SourceContext", nameof(DevHomeInitializationStartedEvent));
log.Debug($"DevHome Initialization Started Event, Identifier: {DeploymentIdentifier}");
}

public override void ReplaceSensitiveStrings(Func<string, string> replaceSensitiveStrings)
{
// No sensitive strings to replace.
}
}
35 changes: 35 additions & 0 deletions src/TelemetryEvents/DevHomeShellLoadedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Diagnostics.Tracing;
using DevHome.Common.Helpers;
using DevHome.Telemetry;
using Microsoft.Diagnostics.Telemetry;
using Microsoft.Diagnostics.Telemetry.Internal;
using Microsoft.Windows.AppLifecycle;
using Serilog;

namespace DevHome.TelemetryEvents;

[EventData]
public class DevHomeShellLoadedEvent : EventBase
{
public Guid DeploymentIdentifier { get; }

public ExtendedActivationKind ActivationKind { get; }

public override PartA_PrivTags PartA_PrivTags => PrivTags.ProductAndServicePerformance;

public DevHomeShellLoadedEvent(ExtendedActivationKind activationKind)
{
ActivationKind = activationKind;
DeploymentIdentifier = Deployment.Identifier;
var log = Log.ForContext("SourceContext", nameof(DevHomeShellLoadedEvent));
log.Debug($"DevHome Startup Event, Identifier: {DeploymentIdentifier}");
}

public override void ReplaceSensitiveStrings(Func<string, string> replaceSensitiveStrings)
{
// No sensitive strings to replace.
}
}
31 changes: 31 additions & 0 deletions src/TelemetryEvents/DevHomeStartedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Diagnostics.Tracing;
using DevHome.Common.Helpers;
using DevHome.Telemetry;
using Microsoft.Diagnostics.Telemetry;
using Microsoft.Diagnostics.Telemetry.Internal;
using Serilog;

namespace DevHome.TelemetryEvents;

[EventData]
public class DevHomeStartedEvent : EventBase
{
public Guid DeploymentIdentifier { get; }

public override PartA_PrivTags PartA_PrivTags => PrivTags.ProductAndServicePerformance;

public DevHomeStartedEvent()
{
DeploymentIdentifier = Deployment.Identifier;
var log = Log.ForContext("SourceContext", nameof(DevHomeStartedEvent));
log.Debug($"DevHome Launched Event, Identifier: {DeploymentIdentifier}");
}

public override void ReplaceSensitiveStrings(Func<string, string> replaceSensitiveStrings)
{
// No sensitive strings to replace.
}
}
8 changes: 8 additions & 0 deletions src/ViewModels/InitializationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using DevHome.Contracts.Services;
using DevHome.Dashboard.Services;
using DevHome.Services.Core.Contracts;
using DevHome.Telemetry;
using DevHome.TelemetryEvents;
using DevHome.Views;
using Microsoft.UI.Xaml;
using Serilog;
Expand Down Expand Up @@ -46,6 +48,9 @@ public InitializationViewModel(

public async void OnPageLoaded()
{
TelemetryFactory.Get<ITelemetry>().Log("DevHome_Initialization_Started_Event", LogLevel.Critical, new DevHomeInitializationStartedEvent());
_log.Information("Dev Home Initialization starting.");

// Install the widget service if we're on Windows 10 and it's not already installed.
try
{
Expand Down Expand Up @@ -88,6 +93,9 @@ public async void OnPageLoaded()
App.MainWindow.Content = Application.Current.GetService<ShellPage>();

_themeSelector.SetRequestedTheme();

TelemetryFactory.Get<ITelemetry>().Log("DevHome_Initialization_Ended_Event", LogLevel.Critical, new DevHomeInitializationEndedEvent());
_log.Information("Dev Home Initialization ended.");
}

private bool HasDevHomeGitHubExtensionInstalled()
Expand Down
9 changes: 8 additions & 1 deletion src/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
using DevHome.Common.Helpers;
using DevHome.Common.Services;
using DevHome.Contracts.Services;
using DevHome.Telemetry;
using DevHome.TelemetryEvents;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.Windows.AppLifecycle;
using Serilog;

namespace DevHome.ViewModels;

Expand Down Expand Up @@ -52,7 +55,11 @@ public ShellViewModel(

public async Task OnLoaded()
{
switch (AppInstance.GetCurrent().GetActivatedEventArgs().Kind)
var activationKind = AppInstance.GetCurrent().GetActivatedEventArgs().Kind;
Log.Information($"Activated with kind {activationKind}");
TelemetryFactory.Get<ITelemetry>().Log("DevHome_Shell_Loaded_Event", LogLevel.Critical, new DevHomeShellLoadedEvent(activationKind));

switch (activationKind)
{
case ExtendedActivationKind.File:
// Allow the file activation handler to navigate to the appropriate page.
Expand Down
3 changes: 0 additions & 3 deletions src/Views/InitializationPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

namespace DevHome.Views;

/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class InitializationPage : Page
{
public InitializationViewModel ViewModel
Expand Down
5 changes: 5 additions & 0 deletions src/Views/WhatsNewPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ private async void OnLoaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
ViewModel.NumberOfBigCards = whatsNewBigCards.Count();

MoveBigCardsIfNeeded(this.ActualWidth);

TelemetryFactory.Get<ITelemetry>().Log(
"Page_Loaded_Event",
LogLevel.Critical,
new PageLoadedEvent(GetType().Name));
}

private async void Button_ClickAsync(object sender, RoutedEventArgs e)
Expand Down
5 changes: 5 additions & 0 deletions tools/Dashboard/DevHome.Dashboard/Views/DashboardView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using DevHome.Common.Extensions;
using DevHome.Common.Helpers;
using DevHome.Common.Services;
using DevHome.Common.TelemetryEvents;
using DevHome.Common.Views;
using DevHome.Dashboard.ComSafeWidgetObjects;
using DevHome.Dashboard.Controls;
Expand Down Expand Up @@ -133,6 +134,10 @@ private async void HandleRendererUpdated(object sender, object args)
private async Task OnLoadedAsync()
{
await InitializeDashboard();
TelemetryFactory.Get<ITelemetry>().Log(
"Page_Loaded_Event",
LogLevel.Critical,
new PageLoadedEvent(GetType().Name));
}

[RelayCommand]
Expand Down

0 comments on commit 285ff3b

Please sign in to comment.