Skip to content

Commit

Permalink
Adding privacy event tags to each telemetry event. (#2879)
Browse files Browse the repository at this point in the history
* Adding privacy event tags to each telemetry event.

* Moving Privacy events to Telemetry base, Removing tag values, and fixing namespaces.

* Adding documentation comments to fix style cop errors in release

* UTCReplace_AppSessionGuid boolean property to all C# telemetry events.

* Adding hardcoded version number to boot events.

* Adding reference to telemetry in settings unittest

* Adding Preview Pane events for loading w/ hardcoded version number

* Adding telemetry.h to msi for svg and markdown events

* removing unused explicit interface exception
  • Loading branch information
ryanbodrug-microsoft committed May 15, 2020
1 parent d4b56f9 commit 34f8147
Show file tree
Hide file tree
Showing 34 changed files with 505 additions and 354 deletions.
1 change: 1 addition & 0 deletions installer/PowerToysSetup/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@
<File Source="$(var.BinX64Dir)modules\FileExplorerPreview\powerpreview.dll" KeyPath="yes" />
<!-- File to include common library used by preview handlers -->
<File Source="$(var.BinX64Dir)modules\FileExplorerPreview\PreviewHandlerCommon.dll" />
<File Source="$(var.BinX64Dir)modules\FileExplorerPreview\Telemetry.dll" />
<!-- File to include dll for Svg Preview Handler -->
<File Source="$(var.BinX64Dir)modules\FileExplorerPreview\SvgPreviewHandler.dll" />
<!-- Files to include dll's for Markdown Preview Handler and it's dependencies -->
Expand Down
16 changes: 16 additions & 0 deletions src/common/ManagedTelemetry/Telemetry/Events/EventBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Text;

namespace Microsoft.PowerToys.Telemetry.Events
{
/// <summary>
/// A base class to implement properties that are common to all telemetry events.
/// </summary>
[EventData]
public class EventBase
{
public bool UTCReplace_AppSessionGuid => true;
}
}
11 changes: 11 additions & 0 deletions src/common/ManagedTelemetry/Telemetry/Events/IEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.PowerToys.Telemetry.Events
{
public interface IEvent
{
PartA_PrivTags PartA_PrivTags { get; }
}
}
8 changes: 5 additions & 3 deletions src/common/ManagedTelemetry/Telemetry/PowerToysTelemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.PowerToys.Telemetry.Events;
using System.Diagnostics.Tracing;
using PreviewHandlerCommon.Telemetry;


namespace Microsoft.PowerToys.Telemetry
{
Expand All @@ -12,7 +13,7 @@ namespace Microsoft.PowerToys.Telemetry
/// </summary>
public class PowerToysTelemetry : TelemetryBase
{

/// <summary>
/// Name for ETW event.
/// </summary>
Expand All @@ -34,7 +35,8 @@ public PowerToysTelemetry()
/// <summary>
/// Publishes ETW event when an action is triggered on
/// </summary>
public void WriteEvent<T>(T telemetryEvent)
public void WriteEvent<T>(T telemetryEvent)
where T : EventBase, IEvent
{
this.Write<T>(null, new EventSourceOptions()
{
Expand Down
2 changes: 1 addition & 1 deletion src/common/ManagedTelemetry/Telemetry/Telemetry.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Platforms>x64</Platforms>
Expand Down
18 changes: 17 additions & 1 deletion src/common/Telemetry/TelemetryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,24 @@

using System.Diagnostics.Tracing;

namespace PreviewHandlerCommon.Telemetry
namespace Microsoft.PowerToys.Telemetry
{
/// <summary>
/// Privacy Tag values
/// </summary>
public enum PartA_PrivTags
: ulong
{
/// <nodoc/>
None = 0,

/// <nodoc/>
ProductAndServicePerformance = 0x0u,

/// <nodoc/>
ProductAndServiceUsage = 0x0u,
}

/// <summary>
/// Base class for telemetry events.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics.Tracing;
using Microsoft.PowerToys.Telemetry;
using Microsoft.PowerToys.Telemetry.Events;

namespace Microsoft.PowerLauncher.Telemetry
{
[EventData]
public class SettingsBootEvent : EventBase, IEvent
{
/// <summary>
/// Gets The version string. TODO: This should be replaced by a P/Invoke call to get_product_version
/// </summary>
public string Version => "v0.18.0";

public double BootTimeMs { get; set; }

public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServicePerformance;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using System.Diagnostics.Tracing;
using Microsoft.PowerToys.Telemetry;
using Microsoft.PowerToys.Telemetry.Events;

namespace Microsoft.PowerToys.Settings.Telemetry
{
[EventData]
public class SettingsEnabledEvent
public class SettingsEnabledEvent : EventBase, IEvent
{
public string Name { get; set; }

public bool Value { get; set; }

public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
}
}
14 changes: 11 additions & 3 deletions src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

using System;
using System.Windows;
using Microsoft.PowerLauncher.Telemetry;
using Microsoft.PowerToys.Settings.UI.Views;
using Microsoft.PowerToys.Telemetry;
using Microsoft.Toolkit.Wpf.UI.XamlHost;
using Windows.UI.Popups;

Expand All @@ -14,8 +16,14 @@ namespace Microsoft.PowerToys.Settings.UI.Runner
public partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
{
var bootTime = new System.Diagnostics.Stopwatch();
bootTime.Start();

this.InitializeComponent();
bootTime.Stop();

PowerToysTelemetry.Log.WriteEvent(new SettingsBootEvent() { BootTimeMs = bootTime.ElapsedMilliseconds });
}

private void WindowsXamlHost_ChildChanged(object sender, EventArgs e)
Expand All @@ -29,7 +37,7 @@ private void WindowsXamlHost_ChildChanged(object sender, EventArgs e)
// send IPC Message
shellPage.SetDefaultSndMessageCallback(msg =>
{
//IPC Manager is null when launching runner directly
// IPC Manager is null when launching runner directly
Program.GetTwoWayIPCManager()?.Send(msg);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@

<ItemGroup>
<ProjectReference Include="..\..\common\interop\interop.vcxproj" />
<ProjectReference Include="..\..\common\ManagedTelemetry\Telemetry\Telemetry.csproj" />
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj" />
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI\Microsoft.PowerToys.Settings.UI.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@
</AdditionalFiles>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\common\ManagedTelemetry\Telemetry\Telemetry.csproj">
<Project>{5d00d290-4016-4cfe-9e41-1e7c724509ba}</Project>
<Name>Telemetry</Name>
</ProjectReference>
<ProjectReference Include="..\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj">
<Project>{b1bcc8c6-46b5-4bfa-8f22-20f32d99ec6a}</Project>
<Name>Microsoft.PowerToys.Settings.UI.Lib</Name>
Expand Down

0 comments on commit 34f8147

Please sign in to comment.