diff --git a/dev/RuntimeCompatibilityOptions/RuntimeCompatibilityOptions.cpp b/dev/RuntimeCompatibilityOptions/RuntimeCompatibilityOptions.cpp index 65310ff775..4d7c6b794a 100644 --- a/dev/RuntimeCompatibilityOptions/RuntimeCompatibilityOptions.cpp +++ b/dev/RuntimeCompatibilityOptions/RuntimeCompatibilityOptions.cpp @@ -6,6 +6,7 @@ #include "Microsoft.Windows.ApplicationModel.WindowsAppRuntime.RuntimeCompatibilityOptions.g.cpp" #include "AssemblyInfo.h" #include +#include "RuntimeCompatibilityOptions_TraceLogger.h" namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implementation { @@ -16,6 +17,14 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem void RuntimeCompatibilityOptions::Apply() { + std::wstring patchLevel1Str = std::to_wstring(m_patchLevel1.Major) + L"." + + std::to_wstring(m_patchLevel1.Minor) + L"." + + std::to_wstring(m_patchLevel1.Patch); + std::wstring patchLevel2Str = std::to_wstring(m_patchLevel2.Major) + L"." + + std::to_wstring(m_patchLevel2.Minor) + L"." + + std::to_wstring(m_patchLevel2.Patch); + RuntimeCompatibilityOptions_TraceLogger::ApplyCalled(patchLevel1Str.c_str(), patchLevel2Str.c_str()); + WinAppSdk::Containment::WinAppSDKRuntimeConfiguration config; // If both patch levels are set to the same major.minor version, error out if the patch versions are different. @@ -24,6 +33,10 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem { if (m_patchLevel1.Patch != m_patchLevel2.Patch) { + RuntimeCompatibilityOptions_TraceLogger::ApplyFailed( + E_INVALIDARG, + L"Patch levels should target different Major.Minor versions or match Patch version." + ); throw hresult_invalid_argument(L"Patch levels should target different Major.Minor versions or match Patch version."); } } @@ -44,9 +57,10 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem std::vector disabledChanges; for (auto changeId : m_disabledChanges) { - // TODO: Telemetry! Log the changeId that was disabled. // UINT32 is used internally for the changeId, so cast from the enum's Int32 to that. - disabledChanges.push_back(static_cast(changeId)); + auto id = static_cast(changeId); + RuntimeCompatibilityOptions_TraceLogger::ChangeDisabled(id); + disabledChanges.push_back(id); } config.disabledChanges = disabledChanges.data(); config.disabledChangesCount = static_cast(disabledChanges.size()); @@ -56,8 +70,17 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem { if (hr == E_ILLEGAL_STATE_CHANGE) { + RuntimeCompatibilityOptions_TraceLogger::ApplyFailed( + hr, + L"Configuration already set or locked." + ); throw winrt::hresult_illegal_state_change(L"Configuration already set or locked."); } + + RuntimeCompatibilityOptions_TraceLogger::ApplyFailed( + hr, + L"SetConfiguration failed." + ); winrt::throw_hresult(hr); } } diff --git a/dev/RuntimeCompatibilityOptions/RuntimeCompatibilityOptions_TraceLogger.h b/dev/RuntimeCompatibilityOptions/RuntimeCompatibilityOptions_TraceLogger.h new file mode 100644 index 0000000000..742389332e --- /dev/null +++ b/dev/RuntimeCompatibilityOptions/RuntimeCompatibilityOptions_TraceLogger.h @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation and Contributors. +// Licensed under the MIT License. + +#pragma once + +#include "pch.h" +#include <../WindowsAppRuntime_Insights/WindowsAppRuntimeInsights.h> + +class RuntimeCompatibilityOptions_TraceLogger final : public wil::TraceLoggingProvider +{ + IMPLEMENT_TRACELOGGING_CLASS( + RuntimeCompatibilityOptions_TraceLogger, + "Microsoft.WindowsAppRuntime.RuntimeCompatibilityOptions", + // {1741c54b-ba96-4540-867b-29830307d0cc} + (0x1741c54b, 0xba96, 0x4540, 0x86, 0x7b, 0x29, 0x83, 0x03, 0x07, 0xd0, 0xcc)); + +public: + + DEFINE_COMPLIANT_CRITICAL_DATA_EVENT_PARAM1( + ChangeDisabled, + PDT_ProductAndServicePerformance, + UINT32, changeId + ); + + DEFINE_COMPLIANT_CRITICAL_DATA_EVENT_PARAM2( + ApplyCalled, + PDT_ProductAndServicePerformance, + PCWSTR, patchLevel1, + PCWSTR, patchLevel2 + ); + + DEFINE_COMPLIANT_CRITICAL_DATA_EVENT_PARAM2( + ApplyFailed, + PDT_ProductAndServicePerformance, + HRESULT, hresult, + PCWSTR, message + ); +}; \ No newline at end of file