Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct caller name in Com startup telemetry event #3711

Merged
merged 1 commit into from Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/AppInstallerCommonCore/AppInstallerTelemetry.cpp
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/AppInstallerCommonCore/Public/AppInstallerTelemetry.h
Expand Up @@ -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.
Expand Down
24 changes: 16 additions & 8 deletions src/Microsoft.Management.Deployment/PackageManager.cpp
Expand Up @@ -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++)
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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())
{
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 1 addition & 7 deletions src/Microsoft.Management.Deployment/PackageManager.h
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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)
Expand Down