commit 80fcb9bd9d44b193492d2278578df7ba3477125c parent 984b7c13c138a25bb587c74c3128e2d529059d6b Author: Ashwini Patil <47225815+ashpatil-msft@users.noreply.github.com> Date: Mon, 27 Sep 2021 13:05:52 -0700 Use correct Subexecution id when working on multiple packages (#1504) * Fix subexecution id Diffstat:
6 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/src/AppInstallerCLICore/ExecutionContextData.h b/src/AppInstallerCLICore/ExecutionContextData.h @@ -63,8 +63,9 @@ namespace AppInstaller::CLI::Execution std::shared_ptr<Repository::IPackageVersion>&& installedPackageVersion, Manifest::Manifest&& manifest, Manifest::ManifestInstaller&& installer, - Manifest::ScopeEnum scope = Manifest::ScopeEnum::Unknown) - : PackageVersion(std::move(packageVersion)), InstalledPackageVersion(std::move(installedPackageVersion)), Manifest(std::move(manifest)), Installer(std::move(installer)), Scope(scope) { } + Manifest::ScopeEnum scope = Manifest::ScopeEnum::Unknown, + uint32_t packageSubExecutionId = 0) + : PackageVersion(std::move(packageVersion)), InstalledPackageVersion(std::move(installedPackageVersion)), Manifest(std::move(manifest)), Installer(std::move(installer)), Scope(scope), PackageSubExecutionId(packageSubExecutionId) { } std::shared_ptr<Repository::IPackageVersion> PackageVersion; @@ -77,6 +78,10 @@ namespace AppInstaller::CLI::Execution Manifest::ManifestInstaller Installer; Manifest::ScopeEnum Scope = Manifest::ScopeEnum::Unknown; + + // Use this sub execution id when installing this package so that + // install telemetry is captured with the same sub execution id as other events in Search phase. + uint32_t PackageSubExecutionId = 0; }; namespace details diff --git a/src/AppInstallerCLICore/Workflows/ImportExportFlow.cpp b/src/AppInstallerCLICore/Workflows/ImportExportFlow.cpp @@ -325,7 +325,8 @@ namespace AppInstaller::CLI::Workflow std::move(searchContext.Get<Execution::Data::InstalledPackageVersion>()), std::move(searchContext.Get<Execution::Data::Manifest>()), std::move(searchContext.Get<Execution::Data::Installer>().value()), - packageRequest.Scope); + packageRequest.Scope, + subExecution.GetCurrentSubExecutionId()); } } diff --git a/src/AppInstallerCLICore/Workflows/InstallFlow.cpp b/src/AppInstallerCLICore/Workflows/InstallFlow.cpp @@ -656,7 +656,7 @@ namespace AppInstaller::CLI::Workflow bool allSucceeded = true; for (auto package : context.Get<Execution::Data::PackagesToInstall>()) { - Logging::SubExecutionTelemetryScope subExecution; + Logging::SubExecutionTelemetryScope subExecution{ package.PackageSubExecutionId }; // We want to do best effort to install all packages regardless of previous failures auto installContextPtr = context.Clone(); diff --git a/src/AppInstallerCLICore/Workflows/UpdateFlow.cpp b/src/AppInstallerCLICore/Workflows/UpdateFlow.cpp @@ -112,11 +112,14 @@ namespace AppInstaller::CLI::Workflow updateAllFoundUpdate = true; - packagesToInstall.emplace_back( + Execution::PackageToInstall package{ std::move(updateContext.Get<Execution::Data::PackageVersion>()), std::move(updateContext.Get<Execution::Data::InstalledPackageVersion>()), std::move(updateContext.Get<Execution::Data::Manifest>()), - std::move(updateContext.Get<Execution::Data::Installer>().value())); + std::move(updateContext.Get<Execution::Data::Installer>().value()) }; + package.PackageSubExecutionId = subExecution.GetCurrentSubExecutionId(); + + packagesToInstall.emplace_back(std::move(package)); } if (!updateAllFoundUpdate) diff --git a/src/AppInstallerCommonCore/AppInstallerTelemetry.cpp b/src/AppInstallerCommonCore/AppInstallerTelemetry.cpp @@ -62,7 +62,7 @@ namespace AppInstaller::Logging { std::ignore = CoCreateGuid(&m_activityId); } - + const GUID* TelemetryTraceLogger::GetActivityId() const { return &m_activityId; @@ -590,6 +590,18 @@ namespace AppInstaller::Logging "Cannot create a sub execution telemetry session when a previous session exists."); } + SubExecutionTelemetryScope::SubExecutionTelemetryScope(uint32_t sessionId) + { + auto expected = s_RootExecutionId; + THROW_HR_IF_MSG(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), !s_subExecutionId.compare_exchange_strong(expected, sessionId), + "Cannot create a sub execution telemetry session when a previous session exists."); + } + + uint32_t SubExecutionTelemetryScope::GetCurrentSubExecutionId() const + { + return (uint32_t)s_subExecutionId; + } + SubExecutionTelemetryScope::~SubExecutionTelemetryScope() { s_subExecutionId = s_RootExecutionId; diff --git a/src/AppInstallerCommonCore/Public/AppInstallerTelemetry.h b/src/AppInstallerCommonCore/Public/AppInstallerTelemetry.h @@ -187,12 +187,16 @@ namespace AppInstaller::Logging { SubExecutionTelemetryScope(); + SubExecutionTelemetryScope(uint32_t sessionId); + SubExecutionTelemetryScope(const SubExecutionTelemetryScope&) = delete; SubExecutionTelemetryScope& operator=(const SubExecutionTelemetryScope&) = delete; SubExecutionTelemetryScope(SubExecutionTelemetryScope&&) = default; SubExecutionTelemetryScope& operator=(SubExecutionTelemetryScope&&) = default; + uint32_t GetCurrentSubExecutionId() const; + ~SubExecutionTelemetryScope(); private: