[Telemetry][Hosts]Add telemetry to Hosts (#21486)

This commit is contained in:
Jaime Bernardo 2022-10-27 17:21:56 +01:00 committed by GitHub
parent 130561cfbb
commit 429569dcf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 0 deletions

View File

@ -12,6 +12,7 @@ using Hosts.Views;
using ManagedCommon; using ManagedCommon;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.PowerToys.Telemetry;
using Microsoft.UI.Dispatching; using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
@ -104,6 +105,8 @@ namespace Hosts
Logger.LogInfo($"Hosts started detached from PowerToys Runner."); Logger.LogInfo($"Hosts started detached from PowerToys Runner.");
} }
PowerToysTelemetry.Log.WriteEvent(new Hosts.Telemetry.HostsFileEditorOpenedEvent());
_window = new MainWindow(); _window = new MainWindow();
_window.Activate(); _window.Activate();
} }

View File

@ -0,0 +1,16 @@
// 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 Hosts.Telemetry
{
[EventData]
public class HostsFileEditorOpenedEvent : EventBase, IEvent
{
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
}
}

View File

@ -165,6 +165,7 @@ public:
{ {
launch_process(true); launch_process(true);
} }
Trace::ActivateEditor();
} }
catch (std::exception&) catch (std::exception&)
{ {
@ -185,6 +186,7 @@ public:
{ {
Logger::trace("HostsModuleInterface::enable()"); Logger::trace("HostsModuleInterface::enable()");
m_enabled = true; m_enabled = true;
Trace::EnableHostsFileEditor(true);
}; };
virtual void disable() virtual void disable()
@ -196,6 +198,7 @@ public:
} }
m_enabled = false; m_enabled = false;
Trace::EnableHostsFileEditor(false);
} }
}; };

View File

@ -17,3 +17,24 @@ void Trace::UnregisterProvider() noexcept
{ {
TraceLoggingUnregister(g_hProvider); TraceLoggingUnregister(g_hProvider);
} }
// Log if the user has HostsFileEditor enabled or disabled
void Trace::EnableHostsFileEditor(const bool enabled) noexcept
{
TraceLoggingWrite(
g_hProvider,
"HostsFileEditor_EnableHostsFileEditor",
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
TraceLoggingBoolean(enabled, "Enabled"));
}
// Log that the user tried to activate the editor
void Trace::ActivateEditor() noexcept
{
TraceLoggingWrite(
g_hProvider,
"HostsFileEditor_Activate",
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
}

View File

@ -5,4 +5,10 @@ class Trace
public: public:
static void RegisterProvider() noexcept; static void RegisterProvider() noexcept;
static void UnregisterProvider() noexcept; static void UnregisterProvider() noexcept;
// Log if the user has HostsFileEditor enabled or disabled
static void EnableHostsFileEditor(const bool enabled) noexcept;
// Log that the user tried to activate the editor
static void ActivateEditor() noexcept;
}; };