winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 6dc9b2c5881724e3ff9778fc580f440f3392a020
parent 8d5ca4288dadb2c28b4ee204227a563afd7fcfee
Author: yao-msft <50888816+yao-msft@users.noreply.github.com>
Date:   Fri, 29 Sep 2023 13:28:52 -0700

Use correct caller name in Com startup telemetry event (#3711)


Diffstat:
Msrc/AppInstallerCommonCore/AppInstallerTelemetry.cpp | 5-----
Msrc/AppInstallerCommonCore/Public/AppInstallerTelemetry.h | 2--
Msrc/Microsoft.Management.Deployment/PackageManager.cpp | 24++++++++++++++++--------
Msrc/Microsoft.Management.Deployment/PackageManager.h | 8+-------
4 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/src/AppInstallerCommonCore/AppInstallerTelemetry.cpp b/src/AppInstallerCommonCore/AppInstallerTelemetry.cpp @@ -173,11 +173,6 @@ namespace AppInstaller::Logging m_executionStage = stage; } - void TelemetryTraceLogger::SetUseSummary(bool useSummary) noexcept - { - m_useSummary = useSummary; - } - std::unique_ptr<TelemetryTraceLogger> TelemetryTraceLogger::CreateSubTraceLogger() const { THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), !this->m_isInitialized); diff --git a/src/AppInstallerCommonCore/Public/AppInstallerTelemetry.h b/src/AppInstallerCommonCore/Public/AppInstallerTelemetry.h @@ -168,8 +168,6 @@ namespace AppInstaller::Logging void SetExecutionStage(uint32_t stage) noexcept; - void SetUseSummary(bool useSummary) noexcept; - std::unique_ptr<TelemetryTraceLogger> CreateSubTraceLogger() const; // Logs the failure info. diff --git a/src/Microsoft.Management.Deployment/PackageManager.cpp b/src/Microsoft.Management.Deployment/PackageManager.cpp @@ -39,19 +39,23 @@ using namespace ::AppInstaller::CLI::Execution; namespace winrt::Microsoft::Management::Deployment::implementation { - PackageManager::PackageManager() + namespace { - auto previousThreadGlobals = m_threadGlobals.SetForCurrentThread(); - // Immediately reset as we only want the thread globals for logging within this object. - previousThreadGlobals.reset(); - // TODO: Disable summary until we log more and have meaningful summary to be sent in the future. - m_threadGlobals.GetTelemetryLogger().SetUseSummary(false); - m_threadGlobals.GetTelemetryLogger().SetCaller(GetCallerName()); - m_threadGlobals.GetTelemetryLogger().LogStartup(true); + void LogStartupIfApplicable() + { + static std::once_flag logStartupOnceFlag; + std::call_once(logStartupOnceFlag, + [&]() + { + ::AppInstaller::Logging::Telemetry().SetCaller(GetCallerName()); + ::AppInstaller::Logging::Telemetry().LogStartup(true); + }); + } } winrt::Windows::Foundation::Collections::IVectorView<winrt::Microsoft::Management::Deployment::PackageCatalogReference> PackageManager::GetPackageCatalogs() { + LogStartupIfApplicable(); Windows::Foundation::Collections::IVector<Microsoft::Management::Deployment::PackageCatalogReference> catalogs{ winrt::single_threaded_vector<Microsoft::Management::Deployment::PackageCatalogReference>() }; std::vector<::AppInstaller::Repository::SourceDetails> sources = ::AppInstaller::Repository::Source::GetCurrentSources(); for (uint32_t i = 0; i < sources.size(); i++) @@ -68,6 +72,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation winrt::Microsoft::Management::Deployment::PackageCatalogReference PackageManager::GetPredefinedPackageCatalog(winrt::Microsoft::Management::Deployment::PredefinedPackageCatalog const& predefinedPackageCatalog) { + LogStartupIfApplicable(); ::AppInstaller::Repository::Source source; switch (predefinedPackageCatalog) { @@ -92,6 +97,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation winrt::Microsoft::Management::Deployment::PackageCatalogReference PackageManager::GetLocalPackageCatalog(winrt::Microsoft::Management::Deployment::LocalPackageCatalog const& localPackageCatalog) { + LogStartupIfApplicable(); ::AppInstaller::Repository::Source source; switch (localPackageCatalog) { @@ -113,6 +119,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation winrt::Microsoft::Management::Deployment::PackageCatalogReference PackageManager::GetPackageCatalogByName(hstring const& catalogName) { + LogStartupIfApplicable(); std::string name = winrt::to_string(catalogName); if (name.empty()) { @@ -163,6 +170,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation winrt::Microsoft::Management::Deployment::PackageCatalogReference PackageManager::CreateCompositePackageCatalog(winrt::Microsoft::Management::Deployment::CreateCompositePackageCatalogOptions const& options) { + LogStartupIfApplicable(); if (!options) { // Can't make a composite source if the options aren't specified. diff --git a/src/Microsoft.Management.Deployment/PackageManager.h b/src/Microsoft.Management.Deployment/PackageManager.h @@ -3,7 +3,6 @@ #pragma once #include "PackageManager.g.h" #include "Public/ComClsids.h" -#include <winget/ThreadGlobals.h> #if !defined(INCLUDE_ONLY_INTERFACE_METHODS) // Forward declaration @@ -18,7 +17,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation [uuid(WINGET_OUTOFPROC_COM_CLSID_PackageManager)] struct PackageManager : PackageManagerT<PackageManager> { - PackageManager(); + PackageManager() = default; winrt::Windows::Foundation::Collections::IVectorView<winrt::Microsoft::Management::Deployment::PackageCatalogReference> GetPackageCatalogs(); winrt::Microsoft::Management::Deployment::PackageCatalogReference GetPredefinedPackageCatalog(winrt::Microsoft::Management::Deployment::PredefinedPackageCatalog const& predefinedPackageCatalog); @@ -42,11 +41,6 @@ namespace winrt::Microsoft::Management::Deployment::implementation DownloadPackageAsync(winrt::Microsoft::Management::Deployment::CatalogPackage package, winrt::Microsoft::Management::Deployment::DownloadOptions options); winrt::Windows::Foundation::IAsyncOperationWithProgress<winrt::Microsoft::Management::Deployment::DownloadResult, winrt::Microsoft::Management::Deployment::PackageDownloadProgress> GetDownloadProgress(winrt::Microsoft::Management::Deployment::CatalogPackage package, winrt::Microsoft::Management::Deployment::PackageCatalogInfo catalogInfo); - -#if !defined(INCLUDE_ONLY_INTERFACE_METHODS) - private: - AppInstaller::ThreadLocalStorage::WingetThreadGlobals m_threadGlobals; -#endif }; #if !defined(INCLUDE_ONLY_INTERFACE_METHODS)