Skip to content

Commit

Permalink
Making EM fire events. (#2769)
Browse files Browse the repository at this point in the history
* Adding more events

* Fixing compilation errors

Co-authored-by: Darren Hoehna <dahoehna@microsoft.com>
  • Loading branch information
dhoehna and Darren Hoehna committed Sep 9, 2022
1 parent 5a11edd commit f223404
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,94 @@
#include "Microsoft.Windows.System.EnvironmentManager.h"
#include <WindowsAppRuntimeInsights.h>

class EnvironmentManagerInsights : public wil::TraceLoggingProvider
DECLARE_TRACELOGGING_CLASS(
EnvironmentManagerTelemetryProvider,
"Microsoft.Windows.System.EnvironmentManager.Insights",
(0xfbce41fa, 0xf7bc, 0x538e, 0x11, 0xf2, 0xab, 0xe1, 0xb9, 0xd2, 0xab, 0x23));

class EnvironmentManagerInsights : public wil::TraceLoggingProvider
{
IMPLEMENT_TRACELOGGING_CLASS(
EnvironmentManagerInsights,
"Microsoft.Windows.System.EnvironmentManager.Insights",
(0xfbce41fa, 0xf7bc, 0x538e, 0x11, 0xf2, 0xab, 0xe1, 0xb9, 0xd2, 0xab, 0x23));
IMPLEMENT_TELEMETRY_CLASS(EnvironmentManagerInsights, EnvironmentManagerTelemetryProvider);

DEFINE_EVENT_METHOD(LogCreateForProcess)() {
TraceLoggingClassWriteMeasure(
"LogCreateForProcess",
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance),
_GENERIC_PARTB_FIELDS_ENABLED);
}

DEFINE_COMPLIANT_MEASURES_EVENT_STRING(LogMessage,
MICROSOFT_KEYWORD_MEASURES, stringvalue);
DEFINE_EVENT_METHOD(LogCreateForUser)() {
TraceLoggingClassWriteMeasure(
"LogCreateForUser",
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance),
_GENERIC_PARTB_FIELDS_ENABLED);
}

static void LogWithScopeAndMessage(winrt::Microsoft::Windows::System::implementation::EnvironmentManager::Scope const& scope,
PCWSTR message)
{
TraceLoggingClassWrite("LogMessageWithScope",
_GENERIC_PARTB_FIELDS_ENABLED,
TraceLoggingValue(ScopeToString(scope), "scope"),
TraceLoggingValue(message, "message"));
DEFINE_EVENT_METHOD(LogCreateForMachine)() {
TraceLoggingClassWriteMeasure(
"LogCreateForMachine",
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance),
_GENERIC_PARTB_FIELDS_ENABLED);
}

DEFINE_EVENT_METHOD(LogGetEnvironmentVariables)(winrt::Microsoft::Windows::System::implementation::EnvironmentManager::Scope scope) {
TraceLoggingClassWriteMeasure(
"LogGetEnvironmentVariables",
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance),
_GENERIC_PARTB_FIELDS_ENABLED,
TraceLoggingWideString(ScopeToString(scope), "Scope"));
}

DEFINE_EVENT_METHOD(LogGetEnvironmentVariable)(winrt::Microsoft::Windows::System::implementation::EnvironmentManager::Scope scope) {
TraceLoggingClassWriteMeasure(
"LogGetEnvironmentVariable",
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance),
_GENERIC_PARTB_FIELDS_ENABLED,
TraceLoggingWideString(ScopeToString(scope), "Scope"));
}

DEFINE_EVENT_METHOD(LogSetEnvironmentVariable)(winrt::Microsoft::Windows::System::implementation::EnvironmentManager::Scope scope) {
TraceLoggingClassWriteMeasure(
"LogSetEnvironmentVariables",
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance),
_GENERIC_PARTB_FIELDS_ENABLED,
TraceLoggingWideString(ScopeToString(scope), "Scope"));
}

DEFINE_EVENT_METHOD(LogAppendToPath)(winrt::Microsoft::Windows::System::implementation::EnvironmentManager::Scope scope) {
TraceLoggingClassWriteMeasure(
"LogAppendToPath",
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance),
_GENERIC_PARTB_FIELDS_ENABLED,
TraceLoggingWideString(ScopeToString(scope), "Scope"));
}

DEFINE_EVENT_METHOD(LogRemoveFromPath)(winrt::Microsoft::Windows::System::implementation::EnvironmentManager::Scope scope) {
TraceLoggingClassWriteMeasure(
"LogRemoveFromPath",
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance),
_GENERIC_PARTB_FIELDS_ENABLED,
TraceLoggingWideString(ScopeToString(scope), "Scope"));
}

DEFINE_EVENT_METHOD(LogAddExecutableFileExtension)(winrt::Microsoft::Windows::System::implementation::EnvironmentManager::Scope scope) {
TraceLoggingClassWriteMeasure(
"LogAddExecutableFileExtension",
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance),
_GENERIC_PARTB_FIELDS_ENABLED,
TraceLoggingWideString(ScopeToString(scope), "Scope"));
}

DEFINE_EVENT_METHOD(LogRemoveExecutableFileExtension)(winrt::Microsoft::Windows::System::implementation::EnvironmentManager::Scope scope) {
TraceLoggingClassWriteMeasure(
"LogRemoveExecutableFileExtension",
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance),
_GENERIC_PARTB_FIELDS_ENABLED,
TraceLoggingWideString(ScopeToString(scope), "Scope"));
}



static constexpr PCWSTR ScopeToString(winrt::Microsoft::Windows::System::implementation::EnvironmentManager::Scope scope)
{
if (scope == winrt::Microsoft::Windows::System::implementation::EnvironmentManager::Scope::Process)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace winrt::Microsoft::Windows::System::implementation

Microsoft::Windows::System::EnvironmentManager EnvironmentManager::GetForProcess()
{
EnvironmentManagerInsights::LogMessage(L"Making EM for process");
EnvironmentManagerInsights::LogCreateForProcess();

Microsoft::Windows::System::EnvironmentManager environmentManager{ nullptr };
environmentManager = winrt::make<implementation::EnvironmentManager>(Scope::Process);
Expand All @@ -32,7 +32,7 @@ namespace winrt::Microsoft::Windows::System::implementation

Microsoft::Windows::System::EnvironmentManager EnvironmentManager::GetForUser()
{
EnvironmentManagerInsights::LogMessage(L"Making EM for User");
EnvironmentManagerInsights::LogCreateForUser();

Microsoft::Windows::System::EnvironmentManager environmentManager{ nullptr };
environmentManager = winrt::make<implementation::EnvironmentManager>(Scope::User);
Expand All @@ -41,7 +41,7 @@ namespace winrt::Microsoft::Windows::System::implementation

Microsoft::Windows::System::EnvironmentManager EnvironmentManager::GetForMachine()
{
EnvironmentManagerInsights::LogMessage(L"Making EM for Machine");
EnvironmentManagerInsights::LogCreateForMachine();

Microsoft::Windows::System::EnvironmentManager environmentManager{ nullptr };
environmentManager = winrt::make<implementation::EnvironmentManager>(Scope::Machine);
Expand Down Expand Up @@ -80,7 +80,7 @@ namespace winrt::Microsoft::Windows::System::implementation

IMapView<hstring, hstring> EnvironmentManager::GetEnvironmentVariables()
{
EnvironmentManagerInsights::LogWithScopeAndMessage(m_Scope, L"Calling GetEnvironmentVariables");
EnvironmentManagerInsights::LogGetEnvironmentVariables(m_Scope);
StringMap environmentVariables;

if (!IsSupported())
Expand All @@ -102,7 +102,7 @@ namespace winrt::Microsoft::Windows::System::implementation

hstring EnvironmentManager::GetEnvironmentVariable(hstring const& variableName)
{
EnvironmentManagerInsights::LogWithScopeAndMessage(m_Scope, L"Calling GetEnvironmentVariable");
EnvironmentManagerInsights::LogGetEnvironmentVariable(m_Scope);

if (!IsSupported())
{
Expand All @@ -129,7 +129,8 @@ namespace winrt::Microsoft::Windows::System::implementation

void EnvironmentManager::SetEnvironmentVariable(hstring const& name, hstring const& value)
{
EnvironmentManagerInsights::LogWithScopeAndMessage(m_Scope, L"Calling SetEnvironmentVariable");
EnvironmentManagerInsights::LogSetEnvironmentVariable(m_Scope);

if (!IsSupported())
{
return;
Expand Down Expand Up @@ -205,7 +206,7 @@ namespace winrt::Microsoft::Windows::System::implementation

void EnvironmentManager::AppendToPath(hstring const& path)
{
EnvironmentManagerInsights::LogWithScopeAndMessage(m_Scope, L"Calling AppendToPath");
EnvironmentManagerInsights::LogAppendToPath(m_Scope);

if (!IsSupported())
{
Expand Down Expand Up @@ -273,7 +274,7 @@ namespace winrt::Microsoft::Windows::System::implementation

void EnvironmentManager::RemoveFromPath(hstring const& path)
{
EnvironmentManagerInsights::LogWithScopeAndMessage(m_Scope, L"Calling RemoveFromPath");
EnvironmentManagerInsights::LogRemoveFromPath(m_Scope);

if (!IsSupported())
{
Expand Down Expand Up @@ -375,7 +376,7 @@ namespace winrt::Microsoft::Windows::System::implementation

void EnvironmentManager::AddExecutableFileExtension(hstring const& pathExt)
{
EnvironmentManagerInsights::LogWithScopeAndMessage(m_Scope, L"Calling AddExecutableFileExtension");
EnvironmentManagerInsights::LogAddExecutableFileExtension(m_Scope);

if (!IsSupported())
{
Expand Down Expand Up @@ -443,7 +444,7 @@ namespace winrt::Microsoft::Windows::System::implementation

void EnvironmentManager::RemoveExecutableFileExtension(hstring const& pathExt)
{
EnvironmentManagerInsights::LogWithScopeAndMessage(m_Scope, L"Calling RemoveExecutableFileExtension");
EnvironmentManagerInsights::LogRemoveExecutableFileExtension(m_Scope);

if (!IsSupported())
{
Expand Down

0 comments on commit f223404

Please sign in to comment.