Skip to content

Commit 6dc9b2c

Browse files
authored
Use correct caller name in Com startup telemetry event (#3711)
1 parent 8d5ca42 commit 6dc9b2c

File tree

4 files changed

+17
-22
lines changed

4 files changed

+17
-22
lines changed

Diff for: src/AppInstallerCommonCore/AppInstallerTelemetry.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,6 @@ namespace AppInstaller::Logging
173173
m_executionStage = stage;
174174
}
175175

176-
void TelemetryTraceLogger::SetUseSummary(bool useSummary) noexcept
177-
{
178-
m_useSummary = useSummary;
179-
}
180-
181176
std::unique_ptr<TelemetryTraceLogger> TelemetryTraceLogger::CreateSubTraceLogger() const
182177
{
183178
THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), !this->m_isInitialized);

Diff for: src/AppInstallerCommonCore/Public/AppInstallerTelemetry.h

-2
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ namespace AppInstaller::Logging
168168

169169
void SetExecutionStage(uint32_t stage) noexcept;
170170

171-
void SetUseSummary(bool useSummary) noexcept;
172-
173171
std::unique_ptr<TelemetryTraceLogger> CreateSubTraceLogger() const;
174172

175173
// Logs the failure info.

Diff for: src/Microsoft.Management.Deployment/PackageManager.cpp

+16-8
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,23 @@ using namespace ::AppInstaller::CLI::Execution;
3939

4040
namespace winrt::Microsoft::Management::Deployment::implementation
4141
{
42-
PackageManager::PackageManager()
42+
namespace
4343
{
44-
auto previousThreadGlobals = m_threadGlobals.SetForCurrentThread();
45-
// Immediately reset as we only want the thread globals for logging within this object.
46-
previousThreadGlobals.reset();
47-
// TODO: Disable summary until we log more and have meaningful summary to be sent in the future.
48-
m_threadGlobals.GetTelemetryLogger().SetUseSummary(false);
49-
m_threadGlobals.GetTelemetryLogger().SetCaller(GetCallerName());
50-
m_threadGlobals.GetTelemetryLogger().LogStartup(true);
44+
void LogStartupIfApplicable()
45+
{
46+
static std::once_flag logStartupOnceFlag;
47+
std::call_once(logStartupOnceFlag,
48+
[&]()
49+
{
50+
::AppInstaller::Logging::Telemetry().SetCaller(GetCallerName());
51+
::AppInstaller::Logging::Telemetry().LogStartup(true);
52+
});
53+
}
5154
}
5255

5356
winrt::Windows::Foundation::Collections::IVectorView<winrt::Microsoft::Management::Deployment::PackageCatalogReference> PackageManager::GetPackageCatalogs()
5457
{
58+
LogStartupIfApplicable();
5559
Windows::Foundation::Collections::IVector<Microsoft::Management::Deployment::PackageCatalogReference> catalogs{ winrt::single_threaded_vector<Microsoft::Management::Deployment::PackageCatalogReference>() };
5660
std::vector<::AppInstaller::Repository::SourceDetails> sources = ::AppInstaller::Repository::Source::GetCurrentSources();
5761
for (uint32_t i = 0; i < sources.size(); i++)
@@ -68,6 +72,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
6872

6973
winrt::Microsoft::Management::Deployment::PackageCatalogReference PackageManager::GetPredefinedPackageCatalog(winrt::Microsoft::Management::Deployment::PredefinedPackageCatalog const& predefinedPackageCatalog)
7074
{
75+
LogStartupIfApplicable();
7176
::AppInstaller::Repository::Source source;
7277
switch (predefinedPackageCatalog)
7378
{
@@ -92,6 +97,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
9297

9398
winrt::Microsoft::Management::Deployment::PackageCatalogReference PackageManager::GetLocalPackageCatalog(winrt::Microsoft::Management::Deployment::LocalPackageCatalog const& localPackageCatalog)
9499
{
100+
LogStartupIfApplicable();
95101
::AppInstaller::Repository::Source source;
96102
switch (localPackageCatalog)
97103
{
@@ -113,6 +119,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
113119

114120
winrt::Microsoft::Management::Deployment::PackageCatalogReference PackageManager::GetPackageCatalogByName(hstring const& catalogName)
115121
{
122+
LogStartupIfApplicable();
116123
std::string name = winrt::to_string(catalogName);
117124
if (name.empty())
118125
{
@@ -163,6 +170,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
163170

164171
winrt::Microsoft::Management::Deployment::PackageCatalogReference PackageManager::CreateCompositePackageCatalog(winrt::Microsoft::Management::Deployment::CreateCompositePackageCatalogOptions const& options)
165172
{
173+
LogStartupIfApplicable();
166174
if (!options)
167175
{
168176
// Can't make a composite source if the options aren't specified.

Diff for: src/Microsoft.Management.Deployment/PackageManager.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#pragma once
44
#include "PackageManager.g.h"
55
#include "Public/ComClsids.h"
6-
#include <winget/ThreadGlobals.h>
76

87
#if !defined(INCLUDE_ONLY_INTERFACE_METHODS)
98
// Forward declaration
@@ -18,7 +17,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
1817
[uuid(WINGET_OUTOFPROC_COM_CLSID_PackageManager)]
1918
struct PackageManager : PackageManagerT<PackageManager>
2019
{
21-
PackageManager();
20+
PackageManager() = default;
2221

2322
winrt::Windows::Foundation::Collections::IVectorView<winrt::Microsoft::Management::Deployment::PackageCatalogReference> GetPackageCatalogs();
2423
winrt::Microsoft::Management::Deployment::PackageCatalogReference GetPredefinedPackageCatalog(winrt::Microsoft::Management::Deployment::PredefinedPackageCatalog const& predefinedPackageCatalog);
@@ -42,11 +41,6 @@ namespace winrt::Microsoft::Management::Deployment::implementation
4241
DownloadPackageAsync(winrt::Microsoft::Management::Deployment::CatalogPackage package, winrt::Microsoft::Management::Deployment::DownloadOptions options);
4342
winrt::Windows::Foundation::IAsyncOperationWithProgress<winrt::Microsoft::Management::Deployment::DownloadResult, winrt::Microsoft::Management::Deployment::PackageDownloadProgress>
4443
GetDownloadProgress(winrt::Microsoft::Management::Deployment::CatalogPackage package, winrt::Microsoft::Management::Deployment::PackageCatalogInfo catalogInfo);
45-
46-
#if !defined(INCLUDE_ONLY_INTERFACE_METHODS)
47-
private:
48-
AppInstaller::ThreadLocalStorage::WingetThreadGlobals m_threadGlobals;
49-
#endif
5044
};
5145

5246
#if !defined(INCLUDE_ONLY_INTERFACE_METHODS)

0 commit comments

Comments
 (0)