Deployment API Telemetry & TraceLogging (#2364)

* DeploymentTelemetry

Co-authored-by: Santosh Chintalapati <sachinta@ntdev.microsoft.com>
This commit is contained in:
sachintaMSFT 2022-04-14 11:43:37 -07:00 коммит произвёл GitHub
Родитель 77f691f236
Коммит 03ddaa9091
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
12 изменённых файлов: 554 добавлений и 53 удалений

Просмотреть файл

@ -21,17 +21,21 @@
<Midl Include="$(MSBuildThisFileDirectory)Deployment.idl" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)DeploymentTraceLogging.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)DeploymentInitializeOptions.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)DeploymentManager.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)DeploymentResult.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)DeploymentActivityContext.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)PackageDefinitions.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)DeploymentTraceLogging.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)DeploymentInitializeOptions.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)DeploymentManager.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)DeploymentResult.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)DeploymentActivityContext.cpp" />
</ItemGroup>
<ItemGroup>
<PublicHeaders Include="$(MSBuildThisFileDirectory)..\common\TerminalVelocityFeatures-DeploymentAPI.h" />
</ItemGroup>
</Project>
</Project>

Просмотреть файл

@ -0,0 +1,65 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
#include <pch.h>
#include "DeploymentActivityContext.h"
WindowsAppRuntime::Deployment::Activity::Context& WindowsAppRuntime::Deployment::Activity::Context::Get()
{
return g_DeploymentActivityContext;
}
void WindowsAppRuntime::Deployment::Activity::Context::Reset()
{
m_installStage = DeploymentStage::None;
m_currentResourceId.clear();
m_deploymentErrorExtendedHresult = S_OK;
m_deploymentErrorText.clear();
m_deploymentErrorActivityId = GUID{};
}
void WindowsAppRuntime::Deployment::Activity::Context::SetDeploymentErrorInfo(
const HRESULT& deploymentErrorExtendedHresult,
const std::wstring& deploymentErrorText,
const GUID& deploymentErrorActivityId)
{
m_deploymentErrorExtendedHresult = deploymentErrorExtendedHresult;
m_deploymentErrorText = deploymentErrorText;
SetDeploymentErrorActivityId(deploymentErrorActivityId);
}
void WindowsAppRuntime::Deployment::Activity::Context::SetLastFailure(const wil::FailureInfo& failure)
{
m_lastFailure.type = failure.type;
m_lastFailure.hr = failure.hr;
if (failure.pszFile)
{
m_lastFailure.file = *failure.pszFile;
}
else
{
m_lastFailure.file.clear();
}
m_lastFailure.lineNumer = failure.uLineNumber;
if (failure.pszMessage)
{
m_lastFailure.message = *failure.pszMessage;
}
else
{
m_lastFailure.message.clear();
}
if (failure.pszModule)
{
m_lastFailure.module = *failure.pszModule;
}
else
{
m_lastFailure.module.clear();
}
}

Просмотреть файл

@ -0,0 +1,109 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
#pragma once
#include "DeploymentTracelogging.h"
namespace WindowsAppRuntime::Deployment::Activity
{
enum class DeploymentStage
{
None = 0x0,
GetLicensePath = 0x1,
InstallLicense = 0x2,
GetPackagePath = 0x3,
AddPackage = 0x4,
RestartPushNotificationsLRP = 0x5,
};
struct WilFailure
{
wil::FailureType type;
HRESULT hr;
std::string file;
unsigned int lineNumer;
std::wstring message;
std::string module;
};
class Context
{
DeploymentStage m_installStage{};
std::wstring m_currentResourceId;
HRESULT m_deploymentErrorExtendedHresult{};
std::wstring m_deploymentErrorText;
GUID m_deploymentErrorActivityId{};
WindowsAppRuntimeDeployment_TraceLogger::Initialize m_activity;
WilFailure m_lastFailure;
public:
static WindowsAppRuntime::Deployment::Activity::Context& Get();
void Reset();
const DeploymentStage& GetInstallStage() const
{
return m_installStage;
}
const std::wstring& GetCurrentResourceId() const
{
return m_currentResourceId;
}
const HRESULT& GetDeploymentErrorExtendedHResult() const
{
return m_deploymentErrorExtendedHresult;
}
const std::wstring& GetDeploymentErrorText() const
{
return m_deploymentErrorText;
}
const GUID& GetDeploymentErrorActivityId() const
{
return m_deploymentErrorActivityId;
}
WindowsAppRuntimeDeployment_TraceLogger::Initialize GetActivity() const
{
return m_activity;
}
const WilFailure& GetLastFailure() const
{
return m_lastFailure;
}
void SetInstallStage(const DeploymentStage& installStage)
{
m_installStage = installStage;
}
void SetCurrentResourceId(const std::wstring& currentResourceId)
{
m_currentResourceId = currentResourceId;
}
void SetDeploymentErrorInfo(
const HRESULT& deploymentErrorExtendedHresult,
const std::wstring& deploymentErrorText,
const GUID& deploymentErrorActivityId);
void SetDeploymentErrorActivityId(const GUID& deploymentErrorActivityId)
{
m_deploymentErrorActivityId = deploymentErrorActivityId;
}
void SetActivity(const WindowsAppRuntimeDeployment_TraceLogger::Initialize& activity)
{
m_activity = activity;
}
void SetLastFailure(const wil::FailureInfo& failure);
};
static WindowsAppRuntime::Deployment::Activity::Context g_DeploymentActivityContext;
}

Просмотреть файл

@ -3,6 +3,7 @@
#include <pch.h>
#include <DeploymentManager.h>
#include <DeploymentResult.h>
#include <DeploymentActivityContext.h>
#include <PackageInfo.h>
#include <PackageId.h>
#include <TerminalVelocityFeatures-DeploymentAPI.h>
@ -10,6 +11,23 @@
#include <PushNotificationsLongRunningPlatform-Startup.h>
#include "WindowsAppRuntime-License.h"
using namespace winrt;
using namespace Windows::Foundation;
#define Initialize_StopSuccessActivity() initializeActivityContext.GetActivity().StopWithResult(\
S_OK,\
static_cast <UINT32>(0),\
static_cast<PCSTR>(nullptr),\
static_cast <unsigned int>(0),\
static_cast<PCWSTR>(nullptr),\
static_cast<PCSTR>(nullptr),\
static_cast <UINT32>(getStatusResult.Status()),\
static_cast<UINT32>(::WindowsAppRuntime::Deployment::Activity::DeploymentStage::None),\
static_cast<PCWSTR>(nullptr),\
S_OK,\
static_cast<PCWSTR>(nullptr),\
GUID_NULL);
namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implementation
{
@ -21,12 +39,16 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::DeploymentResult DeploymentManager::Initialize()
{
::WindowsAppRuntime::Deployment::Activity::Context::Get().GetActivity().Start(false, Security::IntegrityLevel::IsElevated());
FAIL_FAST_HR_IF(HRESULT_FROM_WIN32(APPMODEL_ERROR_NO_PACKAGE), !AppModel::Identity::IsPackagedProcess());
return Initialize(GetCurrentFrameworkPackageFullName());
}
winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::DeploymentResult DeploymentManager::Initialize(winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::DeploymentInitializeOptions const& deploymentInitializeOptions)
{
::WindowsAppRuntime::Deployment::Activity::Context::Get().GetActivity().Start(deploymentInitializeOptions.ForceDeployment(), Security::IntegrityLevel::IsElevated());
FAIL_FAST_HR_IF(HRESULT_FROM_WIN32(APPMODEL_ERROR_NO_PACKAGE), !AppModel::Identity::IsPackagedProcess());
return Initialize(GetCurrentFrameworkPackageFullName(), deploymentInitializeOptions);
}
@ -114,9 +136,12 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::DeploymentResult DeploymentManager::Initialize(hstring const& packageFullName, winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::DeploymentInitializeOptions const& deploymentInitializeOptions)
{
auto& initializeActivityContext{ ::WindowsAppRuntime::Deployment::Activity::Context::Get() };
auto getStatusResult{ DeploymentManager::GetStatus(packageFullName) };
if (getStatusResult.Status() == DeploymentStatus::Ok)
{
Initialize_StopSuccessActivity();
return getStatusResult;
}
@ -126,10 +151,25 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
if (SUCCEEDED(deployPackagesResult))
{
status = DeploymentStatus::Ok;
Initialize_StopSuccessActivity();
}
else
{
status = DeploymentStatus::PackageInstallFailed;
initializeActivityContext.GetActivity().StopWithResult(
deployPackagesResult,
static_cast<UINT32>(initializeActivityContext.GetLastFailure().type),
initializeActivityContext.GetLastFailure().file.c_str(),
initializeActivityContext.GetLastFailure().lineNumer,
initializeActivityContext.GetLastFailure().message.c_str(),
initializeActivityContext.GetLastFailure().module.c_str(),
static_cast<UINT32>(status),
static_cast<UINT32>(initializeActivityContext.GetInstallStage()),
initializeActivityContext.GetCurrentResourceId().c_str(),
initializeActivityContext.GetDeploymentErrorExtendedHResult(),
initializeActivityContext.GetDeploymentErrorText().c_str(),
initializeActivityContext.GetDeploymentErrorActivityId());
}
return winrt::make<implementation::DeploymentResult>(status, deployPackagesResult);
@ -197,7 +237,7 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
CATCH_RETURN()
// Gets the package path, which is a fast and reliable way to check if the package is
// registered for the user, even without package query capabilities.
// at least staged on the device, even without package query capabilities.
std::wstring DeploymentManager::GetPackagePath(std::wstring const& packageFullName)
{
UINT32 pathLength{};
@ -231,8 +271,21 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
const auto options{ GetDeploymentOptions(forceDeployment) };
const auto packagePathUri = winrt::Windows::Foundation::Uri(packagePath.c_str());
const auto deploymentResult{ packageManager.AddPackageAsync(packagePathUri, nullptr, options).get() };
return deploymentResult.ExtendedErrorCode();
const auto deploymentOperation{ packageManager.AddPackageAsync(packagePathUri, nullptr, options) };
deploymentOperation.get();
const auto deploymentResult{ deploymentOperation.GetResults() };
HRESULT hrAddPackage{};
if (deploymentOperation.Status() != AsyncStatus::Completed)
{
hrAddPackage = static_cast<HRESULT>(deploymentOperation.ErrorCode());
::WindowsAppRuntime::Deployment::Activity::Context::Get().SetDeploymentErrorInfo(
deploymentResult.ExtendedErrorCode(),
deploymentResult.ErrorText().c_str(),
deploymentResult.ActivityId());
}
return hrAddPackage;
}
CATCH_RETURN()
@ -247,12 +300,16 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
HRESULT DeploymentManager::InstallLicenses(const std::wstring& frameworkPackageFullName)
{
::WindowsAppRuntime::Deployment::Activity::Context::Get().SetInstallStage(::WindowsAppRuntime::Deployment::Activity::DeploymentStage::GetLicensePath);
// Build path for licenses
auto licensePath{ std::filesystem::path(GetPackagePath(frameworkPackageFullName)) };
licensePath /= WINDOWSAPPRUNTIME_FRAMEWORK_PACKAGE_FOLDER;
auto licenseFilespec{ licensePath };
licenseFilespec /= L"*_license.xml";
::WindowsAppRuntime::Deployment::Activity::Context::Get().SetInstallStage(::WindowsAppRuntime::Deployment::Activity::DeploymentStage::InstallLicense);
// Deploy the licenses (if any)
::Microsoft::Windows::ApplicationModel::Licensing::Installer licenseInstaller;
WIN32_FIND_DATA findFileData{};
@ -269,6 +326,10 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
// Install the license file
auto licenseFilename{ licensePath };
licenseFilename /= findFileData.cFileName;
::WindowsAppRuntime::Deployment::Activity::Context::Get().Reset();
::WindowsAppRuntime::Deployment::Activity::Context::Get().SetCurrentResourceId(licenseFilename);
RETURN_IF_FAILED_MSG(licenseInstaller.InstallLicenseFile(licenseFilename.c_str()),
"LicenseFile:%ls", licenseFilename.c_str());
@ -285,9 +346,14 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
HRESULT DeploymentManager::DeployPackages(const std::wstring& frameworkPackageFullName, bool forceDeployment)
{
::WindowsAppRuntime::Deployment::Activity::Context::Get().SetInstallStage(::WindowsAppRuntime::Deployment::Activity::DeploymentStage::GetPackagePath);
const auto frameworkPath{ std::filesystem::path(GetPackagePath(frameworkPackageFullName)) };
::WindowsAppRuntime::Deployment::Activity::Context::Get().SetInstallStage(::WindowsAppRuntime::Deployment::Activity::DeploymentStage::AddPackage);
for (const auto& package : c_targetPackages)
{
::WindowsAppRuntime::Deployment::Activity::Context::Get().Reset();
::WindowsAppRuntime::Deployment::Activity::Context::Get().SetCurrentResourceId(package.identifier);
// Build path for the packages.
auto packagePath{ frameworkPath };
packagePath /= WINDOWSAPPRUNTIME_FRAMEWORK_PACKAGE_FOLDER;
@ -295,13 +361,14 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
// Deploy package.
RETURN_IF_FAILED(AddPackage(packagePath, forceDeployment));
}
// Restart Push Notifications Long Running Platform when ForceDeployment option is applied.
if (forceDeployment)
{
// wil callback will be set up to log telemetry events for LRP.
THROW_IF_FAILED_MSG(StartupNotificationsLongRunningPlatform(), "Restarting Notifications LRP failed after 3 attempts.");
// Restart Push Notifications Long Running Platform when ForceDeployment option is applied.
if (forceDeployment &&
CompareStringOrdinal(package.identifier.c_str(), -1, WINDOWSAPPRUNTIME_PACKAGE_SUBTYPENAME_SINGLETON, -1, TRUE) == CSTR_EQUAL)
{
// wil callback is set up to log telemetry events for Push Notifications LRP.
LOG_IF_FAILED_MSG(StartupNotificationsLongRunningPlatform(), "Restarting Notifications LRP failed in all 3 attempts.");
}
}
return S_OK;

Просмотреть файл

@ -0,0 +1,98 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
#pragma once
#include <wil/resource.h>
#include <wil/result_macros.h>
#include <WindowsAppRuntimeInsights.h>
void __stdcall wilResultLoggingCallback(const wil::FailureInfo& failure) noexcept;
class WindowsAppRuntimeDeployment_TraceLogger final : public wil::TraceLoggingProvider
{
IMPLEMENT_TRACELOGGING_CLASS(
WindowsAppRuntimeDeployment_TraceLogger,
"Microsoft.WindowsAppRuntime.Deployment",
// {838d2cc1-0efb-564a-47bf-faba17949992}
(0x838d2cc1, 0x0efb, 0x564a, 0x47, 0xbf, 0xfa, 0xba, 0x17, 0x94, 0x99, 0x92));
public:
BEGIN_COMPLIANT_CRITICAL_DATA_ACTIVITY_CLASS(Initialize, PDT_ProductAndServicePerformance);
void StartActivity(bool forceDeployment, bool isElevated)
{
// Clear the process-wide callback set in Start
wil::SetResultLoggingCallback(nullptr);
// Set a process-wide callback function for WIL to call each time it logs a failure.
wil::SetResultLoggingCallback(wilResultLoggingCallback);
TraceLoggingClassWriteStart(Initialize,
_GENERIC_PARTB_FIELDS_ENABLED,
TraceLoggingValue(forceDeployment, "forceDeployment"),
TraceLoggingValue(isElevated, "isElevated"));
}
void StopWithResult(
HRESULT hresult,
UINT32 failureType,
PCSTR failureFile,
unsigned int failureLineNumber,
PCWSTR failureMessage,
PCSTR failureModule,
UINT32 preInitializeStatus,
UINT32 installStage,
PCWSTR currentResourceId,
HRESULT deploymentErrorExtendedHResult,
PCWSTR deploymentErrorText,
GUID deploymentErrorActivityId)
{
// Set a process-wide callback function for WIL to call each time it logs a failure.
wil::SetResultLoggingCallback(nullptr);
SetStopResult(hresult);
if (hresult)
{
TraceLoggingClassWriteStop(Initialize,
_GENERIC_PARTB_FIELDS_ENABLED,
TraceLoggingValue(failureType, "WilFailureType"),
TraceLoggingValue(failureFile, "FailureFile"),
TraceLoggingValue(failureLineNumber, "FailureLineNumber"),
TraceLoggingValue(failureMessage, "FailureMessage"),
TraceLoggingValue(failureModule, "FailureModule"),
TraceLoggingValue(installStage, "FailedInstallStage"),
TraceLoggingValue(currentResourceId, "CurrentResourceId"),
TraceLoggingValue(deploymentErrorExtendedHResult, "DeploymentErrorExtendedHResult"),
TraceLoggingValue(deploymentErrorText, "DeploymentErrorText"),
TraceLoggingValue(deploymentErrorActivityId, "DeploymentErrorActivityId"));
}
else
{
TraceLoggingClassWriteStop(Install,
_GENERIC_PARTB_FIELDS_ENABLED,
TraceLoggingValue(preInitializeStatus, "preInitializeStatus"));
}
}
END_ACTIVITY_CLASS();
};
#define WindowsAppRuntimeDeployment_TraceLoggingWString(_wstring_, _name_) \
TraceLoggingCountedWideString(\
_wstring_.c_str(),\
static_cast<ULONG>(_wstring_.size()), _name_)
// In the future, if the project includes multiple modules and threads, we could log that data as well from FailureInfo
// In the future and on need basis, we could log call stack as well
#define WindowsAppRuntimeDeployment_WriteEventWithActivity(_eventname_,...) TraceLoggingWriteActivity(\
WindowsAppRuntimeDeployment_TraceLogger::Provider(),\
_eventname_,\
WindowsAppRuntime::Deployment::Activity::Context::Get().GetActivity().Id(),\
nullptr,\
TraceLoggingValue(static_cast<uint32_t>(failure.type), "Type"),\
TraceLoggingValue(failure.hr, "HResult"),\
TraceLoggingValue(failure.pszFile, "File"),\
TraceLoggingValue(failure.uLineNumber, "Line"),\
TraceLoggingValue(failure.pszMessage, "Message"),\
TraceLoggingValue(failure.pszModule, "Module"),\
__VA_ARGS__)

Просмотреть файл

@ -0,0 +1,106 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
#pragma once
#include <pch.h>
#include "DeploymentActivityContext.h"
#include <winrt\Microsoft.Windows.ApplicationModel.WindowsAppRuntime.h>
using namespace WindowsAppRuntime::Deployment::Activity;
// A process-wide callback function for WIL Error Handlers
void __stdcall wilResultLoggingCallback(const wil::FailureInfo& failure) noexcept
{
if (WindowsAppRuntimeDeployment_TraceLogger::IsEnabled())
{
auto& deploymentActivityContext{ WindowsAppRuntime::Deployment::Activity::Context::Get() };
if (deploymentActivityContext.GetActivity().IsRunning())
{
switch (failure.type)
{
case wil::FailureType::Log:
{
if (deploymentActivityContext.GetInstallStage() == DeploymentStage::RestartPushNotificationsLRP)
{
// Failure in restarting PushNotificationsLRP is non-blocking to the installer functionality
WindowsAppRuntimeDeployment_WriteEventWithActivity(
"RestartPushNotificationsLRPFailed",
_GENERIC_PARTB_FIELDS_ENABLED,
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance),
TraceLoggingKeyword(MICROSOFT_KEYWORD_CRITICAL_DATA));
}
else
{
WindowsAppRuntimeDeployment_WriteEventWithActivity("FailureLog",
TraceLoggingCountedWideString(
deploymentActivityContext.GetCurrentResourceId().c_str(),
static_cast<ULONG>(deploymentActivityContext.GetCurrentResourceId().size()), "currentResource"));
}
break;
}
case wil::FailureType::Exception:
{
WindowsAppRuntimeDeployment_WriteEventWithActivity(
"Exception",
TraceLoggingCountedWideString(
deploymentActivityContext.GetCurrentResourceId().c_str(),
static_cast<ULONG>(deploymentActivityContext.GetCurrentResourceId().size()), "currentResource"));
// Don't stop the Deployment activity here. Instead, give the failing API a chance to Stop the Activity before returning error to the caller.
// Hence, save the wil failure info here for later use.
deploymentActivityContext.SetLastFailure(failure);
break;
}
case wil::FailureType::FailFast:
{
WindowsAppRuntimeDeployment_WriteEventWithActivity(
"FailFast",
TraceLoggingCountedWideString(
deploymentActivityContext.GetCurrentResourceId().c_str(),
static_cast<ULONG>(deploymentActivityContext.GetCurrentResourceId().size()), "currentResource"));
deploymentActivityContext.GetActivity().StopWithResult(
failure.hr,
static_cast<UINT32>(failure.type),
failure.pszFile,
failure.uLineNumber,
failure.pszMessage,
failure.pszModule,
static_cast<UINT32>(winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::DeploymentStatus::PackageInstallRequired),
static_cast<UINT32>(deploymentActivityContext.GetInstallStage()),
deploymentActivityContext.GetCurrentResourceId().c_str(),
deploymentActivityContext.GetDeploymentErrorExtendedHResult(),
deploymentActivityContext.GetDeploymentErrorText().c_str(),
deploymentActivityContext.GetDeploymentErrorActivityId());
break;
}
case wil::FailureType::Return:
{
// THROW_*** error handling combined with CATCH_RETURN in the code may log the same failure twice.
// That's ok and we can live with that redundancy but don't want to lose failure info from RETURN_*** wil macros.
WindowsAppRuntimeDeployment_WriteEventWithActivity(
"FailureReturn",
TraceLoggingCountedWideString(
deploymentActivityContext.GetCurrentResourceId().c_str(),
static_cast<ULONG>(deploymentActivityContext.GetCurrentResourceId().size()), "currentResource"));
// If this is due to CATCH_RETURN(), we want to keep the failure info from THROW* and not overwrite that from RETURN*
if (!(deploymentActivityContext.GetLastFailure().type == wil::FailureType::Exception &&
FAILED(deploymentActivityContext.GetLastFailure().hr)))
{
// Don't stop the Deployment activity here. Instead, give the Installer main a chance to Stop the Activity before returning error to the caller.
// Hence, save the wil failure info here for later use.
deploymentActivityContext.SetLastFailure(failure);
}
break;
}
default:
break;
}
}
return;
}
}

Просмотреть файл

@ -52,13 +52,4 @@ void WindowsAppRuntimeInstaller::InstallActivity::Context::SetLastFailure(const
{
m_lastFailure.message.clear();
}
if (failure.pszCode)
{
m_lastFailure.code = *failure.pszCode;
}
else
{
m_lastFailure.code.clear();
}
}

Просмотреть файл

@ -23,15 +23,14 @@ namespace WindowsAppRuntimeInstaller::InstallActivity
{
wil::FailureType type;
HRESULT hr;
std::wstring file;
std::string file;
unsigned int lineNumer;
std::wstring message;
std::wstring code;
};
class Context
{
InstallStage m_installStage{ InstallStage::None };
InstallStage m_installStage{};
std::wstring m_currentResourceId;
HRESULT m_deploymentErrorExtendedHresult{};
std::wstring m_deploymentErrorText;

Просмотреть файл

@ -300,16 +300,17 @@ namespace WindowsAppRuntimeInstaller
}
CATCH_RETURN()
// RestartPushNotificationsLRP is best effort and non-blocking to Installer functionality
// RestartPushNotificationsLRP is best effort and non-blocking to Installer functionality.
// Any failures in this helper method will be logged in Telemetry but will not return error to the caller.
void RestartPushNotificationsLRP()
{
WindowsAppRuntimeInstaller::InstallActivity::Context::Get().SetInstallStage(WindowsAppRuntimeInstaller::InstallActivity::InstallStage::RestartPushNotificationsLRP);
IID pushNotificationsIMPL_CLSID;
THROW_IF_FAILED(CLSIDFromString(PUSHNOTIFICATIONS_IMPL_CLSID_WSTRING, &pushNotificationsIMPL_CLSID));
LOG_IF_FAILED(CLSIDFromString(PUSHNOTIFICATIONS_IMPL_CLSID_WSTRING, &pushNotificationsIMPL_CLSID));
IID pushNotificationsLRP_IID;
THROW_IF_FAILED(CLSIDFromString(PUSHNOTIFICATIONS_LRP_CLSID_WSTRING, &pushNotificationsLRP_IID));
LOG_IF_FAILED(CLSIDFromString(PUSHNOTIFICATIONS_LRP_CLSID_WSTRING, &pushNotificationsLRP_IID));
wil::com_ptr<::IUnknown> pNotificationsLRP{};
@ -329,7 +330,7 @@ namespace WindowsAppRuntimeInstaller
}
retries++;
}
// wil call back is setup to log telemetry event for any failure in restartign Notifications LRP
// wil call back is setup to log telemetry event for any failure in restarting Notifications LRP
LOG_IF_FAILED_MSG(hr, "Restarting Push Notifications LRP failed after 3 attempts.");
}
@ -382,13 +383,14 @@ namespace WindowsAppRuntimeInstaller
{
WindowsAppRuntimeInstaller::InstallActivity::Context::Get().Reset();
DeployPackageFromResource(package, options);
}
}
// Restart Push Notifications Long Running Platform when ForceDeployment option is applied.
if (WI_IsFlagSet(options, WindowsAppRuntimeInstaller::Options::ForceDeployment))
{
RestartPushNotificationsLRP();
// Restart Push Notifications Long Running Platform when ForceDeployment option is applied.
if (WI_IsFlagSet(options, WindowsAppRuntimeInstaller::Options::ForceDeployment) &&
CompareStringOrdinal(package.id.c_str(), package.id.size() - 3, WAR_SINGLETON_X86_ID, package.id.size() - 3, TRUE) == CSTR_EQUAL)
{
RestartPushNotificationsLRP();
}
}
}
return S_OK;

Просмотреть файл

@ -85,10 +85,10 @@ int wmain(int argc, wchar_t *argv[])
auto& installActivityContext{ WindowsAppRuntimeInstaller::InstallActivity::Context::Get() };
installActivityContext.SetActivity(WindowsAppRuntimeInstaller_TraceLogger::Install::Start(args.str().c_str(), static_cast<UINT32>(options)));
const bool isElevated{ Security::IntegrityLevel::IsElevated() };
installActivityContext.SetActivity(WindowsAppRuntimeInstaller_TraceLogger::Install::Start(args.str().c_str(), static_cast<UINT32>(options), isElevated));
args.clear();
if (!Security::IntegrityLevel::IsElevated())
if (!isElevated)
{
std::wcout << std::endl << "INFO: Provisioning of WindowsAppSDK packages will be skipped as it requires elevation." << std::endl;
}
@ -102,6 +102,10 @@ int wmain(int argc, wchar_t *argv[])
installActivityContext.GetActivity().StopWithResult(
deployPackagesResult,
static_cast <UINT32>(0),
static_cast<PCSTR>(nullptr),
static_cast <unsigned int>(0),
static_cast<PCWSTR>(nullptr),
static_cast<UINT32>(WindowsAppRuntimeInstaller::InstallActivity::InstallStage::None),
static_cast<PCWSTR>(nullptr),
S_OK,
@ -114,6 +118,10 @@ int wmain(int argc, wchar_t *argv[])
installActivityContext.GetActivity().StopWithResult(
deployPackagesResult,
static_cast<UINT32>(installActivityContext.GetLastFailure().type),
installActivityContext.GetLastFailure().file.c_str(),
installActivityContext.GetLastFailure().lineNumer,
installActivityContext.GetLastFailure().message.c_str(),
static_cast<UINT32>(installActivityContext.GetInstallStage()),
installActivityContext.GetCurrentResourceId().c_str(),
installActivityContext.GetDeploymentErrorExtendedHResult(),

Просмотреть файл

@ -8,7 +8,7 @@
using namespace WindowsAppRuntimeInstaller::InstallActivity;
// A process-wide callback function for WIL to call each time it logs a failure.
// A process-wide callback function for WIL Error Handlers
void __stdcall wilResultLoggingCallback(const wil::FailureInfo& failure) noexcept
{
if (WindowsAppRuntimeInstaller_TraceLogger::IsEnabled())
@ -22,7 +22,6 @@ void __stdcall wilResultLoggingCallback(const wil::FailureInfo& failure) noexcep
case wil::FailureType::Log:
{
// wil Log failure type indicates intention to just log failure but continue with the installation
if (installActivityContext.GetInstallStage() == InstallStage::ProvisionPackage)
{
// Failure in Provisioning package are non-blocking and the installer will continue with installation
@ -31,7 +30,7 @@ void __stdcall wilResultLoggingCallback(const wil::FailureInfo& failure) noexcep
WindowsAppRuntimeInstaller_TraceLoggingWString(installActivityContext.GetCurrentResourceId(), "currentPackage"),
_GENERIC_PARTB_FIELDS_ENABLED,
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES));
TraceLoggingKeyword(MICROSOFT_KEYWORD_CRITICAL_DATA));
}
else if (installActivityContext.GetInstallStage() == InstallStage::RestartPushNotificationsLRP)
{
@ -40,7 +39,11 @@ void __stdcall wilResultLoggingCallback(const wil::FailureInfo& failure) noexcep
"RestartPushNotificationsLRPFailed",
_GENERIC_PARTB_FIELDS_ENABLED,
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES));
TraceLoggingKeyword(MICROSOFT_KEYWORD_CRITICAL_DATA));
}
else
{
WindowsAppRuntimeInstaller_WriteEventWithActivity("FailureLog");
}
break;
}
@ -51,6 +54,10 @@ void __stdcall wilResultLoggingCallback(const wil::FailureInfo& failure) noexcep
TraceLoggingCountedWideString(
installActivityContext.GetCurrentResourceId().c_str(),
static_cast<ULONG>(installActivityContext.GetCurrentResourceId().size()), "currentResource"));
// Don't stop the Install activity here. Instead, give the Installer main a chance to Stop the Activity before returning error to the caller.
// Hence, save the wil failure info here for later use.
installActivityContext.SetLastFailure(failure);
break;
}
case wil::FailureType::FailFast:
@ -60,10 +67,39 @@ void __stdcall wilResultLoggingCallback(const wil::FailureInfo& failure) noexcep
TraceLoggingCountedWideString(
installActivityContext.GetCurrentResourceId().c_str(),
static_cast<ULONG>(installActivityContext.GetCurrentResourceId().size()), "currentResource"));
installActivityContext.GetActivity().StopWithResult(
failure.hr,
static_cast<UINT32>(failure.type),
failure.pszFile,
failure.uLineNumber,
failure.pszMessage,
static_cast<UINT32>(installActivityContext.GetInstallStage()),
installActivityContext.GetCurrentResourceId().c_str(),
installActivityContext.GetDeploymentErrorExtendedHResult(),
installActivityContext.GetDeploymentErrorText().c_str(),
installActivityContext.GetDeploymentErrorActivityId());
break;
}
case wil::FailureType::Return:
{
WindowsAppRuntimeInstaller_WriteEventWithActivity(
"FailureReturn",
TraceLoggingCountedWideString(
installActivityContext.GetCurrentResourceId().c_str(),
static_cast<ULONG>(installActivityContext.GetCurrentResourceId().size()), "currentResource"));
// If this is due to CATCH_RETURN(), we want to keep the failure info from THROW* and not overwrite that from RETURN*
if (!(installActivityContext.GetLastFailure().type == wil::FailureType::Exception &&
FAILED(installActivityContext.GetLastFailure().hr)))
{
// Don't stop the Install activity here. Instead, give the Installer main a chance to Stop the Activity before returning error to the caller.
// Hence, save the wil failure info here for later use.
installActivityContext.SetLastFailure(failure);
}
break;
}
default:
// Exceptions will be followed by Returns due to try...CATCH_RETURN() usage. Hence, avoid logging twice by ignoring wil::FailureType::Return
break;
}
}

Просмотреть файл

@ -37,17 +37,22 @@ class WindowsAppRuntimeInstaller_TraceLogger final : public wil::TraceLoggingPro
public:
BEGIN_COMPLIANT_MEASURES_ACTIVITY_CLASS(Install, PDT_ProductAndServicePerformance);
void StartActivity(PCWSTR args, UINT32 options)
BEGIN_COMPLIANT_CRITICAL_DATA_ACTIVITY_CLASS(Install, PDT_ProductAndServicePerformance);
void StartActivity(PCWSTR args, UINT32 options, bool isElevated)
{
TraceLoggingClassWriteStart(Install,
_GENERIC_PARTB_FIELDS_ENABLED,
TraceLoggingValue(args, "cmdLineArgs"),
TraceLoggingValue(options, "options"));
TraceLoggingValue(options, "options"),
TraceLoggingValue(isElevated, "isElevated"));
}
void StopWithResult(
HRESULT hresult,
UINT32 installStage,
UINT32 failureType,
PCSTR failureFile,
UINT32 failureLineNumber,
PCWSTR failureMessage,
UINT32 failedInstallStage,
PCWSTR currentResourceId,
HRESULT deploymentErrorExtendedHResult,
PCWSTR deploymentErrorText,
@ -55,13 +60,25 @@ public:
{
SetStopResult(hresult);
TraceLoggingClassWriteStop(Install,
_GENERIC_PARTB_FIELDS_ENABLED,
TraceLoggingValue(installStage, "FailedInstallStage"),
TraceLoggingValue(currentResourceId, "CurrentResourceId"),
TraceLoggingValue(deploymentErrorExtendedHResult, "DeploymentErrorExtendedHResult"),
TraceLoggingValue(deploymentErrorText, "DeploymentErrorText"),
TraceLoggingValue(deploymentErrorActivityId, "DeploymentErrorActivityId"));
if (hresult)
{
TraceLoggingClassWriteStop(Install,
_GENERIC_PARTB_FIELDS_ENABLED,
TraceLoggingValue(failureType, "WilFailureType"),
TraceLoggingValue(failureFile, "FailureFile"),
TraceLoggingValue(failureLineNumber, "FailureLineNumber"),
TraceLoggingValue(failureMessage, "FailureMessage"),
TraceLoggingValue(failedInstallStage, "FailedInstallStage"),
TraceLoggingValue(currentResourceId, "CurrentResourceId"),
TraceLoggingValue(deploymentErrorExtendedHResult, "DeploymentErrorExtendedHResult"),
TraceLoggingValue(deploymentErrorText, "DeploymentErrorText"),
TraceLoggingValue(deploymentErrorActivityId, "DeploymentErrorActivityId"));
}
else
{
TraceLoggingClassWriteStop(Install,
_GENERIC_PARTB_FIELDS_ENABLED);
}
}
END_ACTIVITY_CLASS();
};
@ -78,10 +95,9 @@ public:
_eventname_,\
WindowsAppRuntimeInstaller::InstallActivity::Context::Get().GetActivity().Id(),\
nullptr,\
TraceLoggingValue(static_cast<uint32_t>(failure.type), "Type"),\
TraceLoggingValue(static_cast<UINT32>(failure.type), "Type"),\
TraceLoggingValue(failure.hr, "HResult"),\
TraceLoggingValue(failure.pszFile, "File"),\
TraceLoggingValue(failure.uLineNumber,"Line"),\
TraceLoggingValue(failure.pszMessage,"Message"),\
TraceLoggingValue(failure.pszCode,"pszCode"),\
__VA_ARGS__)