diff --git a/src/AppInstallerCommonCore/AppInstallerTelemetry.cpp b/src/AppInstallerCommonCore/AppInstallerTelemetry.cpp index 8f870a5696..2f149a6353 100644 --- 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::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 index b73e5b6968..c794b0ba03 100644 --- 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 CreateSubTraceLogger() const; // Logs the failure info. diff --git a/src/Microsoft.Management.Deployment/PackageManager.cpp b/src/Microsoft.Management.Deployment/PackageManager.cpp index e5313038d9..efbb8e2cc3 100644 --- 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 PackageManager::GetPackageCatalogs() { + LogStartupIfApplicable(); Windows::Foundation::Collections::IVector catalogs{ winrt::single_threaded_vector() }; 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 index d5ced01a46..3b07342be3 100644 --- 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 #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() = default; winrt::Windows::Foundation::Collections::IVectorView 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 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)