Skip to content

Commit 297c9f1

Browse files
authored
Don't treat the COM subcommands as distinct for telemetry (#2792)
This change treats the `OrchestratorQueueItem` as the command for telemetry purposes. This aligns with the `winget.exe` method of counting success/failure. It also moves to use the same command names as `winget.exe`, making it easier to join/slice the data.
1 parent 7cc5068 commit 297c9f1

4 files changed

Lines changed: 40 additions & 13 deletions

File tree

src/AppInstallerCLICore/Command.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ namespace AppInstaller::CLI
907907
return arguments;
908908
}
909909

910-
int Execute(Execution::Context& context, std::unique_ptr<Command>& command)
910+
void ExecuteWithoutLoggingSuccess(Execution::Context& context, Command* command)
911911
{
912912
try
913913
{
@@ -923,6 +923,11 @@ namespace AppInstaller::CLI
923923
{
924924
context.SetTerminationHR(Workflow::HandleException(context, std::current_exception()));
925925
}
926+
}
927+
928+
int Execute(Execution::Context& context, std::unique_ptr<Command>& command)
929+
{
930+
ExecuteWithoutLoggingSuccess(context, command.get());
926931

927932
if (SUCCEEDED(context.GetTerminationHR()))
928933
{

src/AppInstallerCLICore/Command.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,7 @@ namespace AppInstaller::CLI
140140
return result;
141141
}
142142

143+
void ExecuteWithoutLoggingSuccess(Execution::Context& context, Command* command);
144+
143145
int Execute(Execution::Context& context, std::unique_ptr<Command>& command);
144146
}

src/AppInstallerCLICore/ContextOrchestrator.cpp

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ namespace AppInstaller::CLI::Execution
9191
if (item->IsOnFirstCommand())
9292
{
9393
THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_INSTALL_ALREADY_RUNNING), FindById(item->GetId()));
94+
95+
// Log the beginning of the item
96+
item->GetContext().GetThreadGlobals().GetTelemetryLogger().LogCommand(item->GetItemCommandName());
9497
}
9598

9699
std::string commandQueueName{ GetCommandQueueName(item->GetNextCommand().Name()) };
@@ -246,34 +249,37 @@ namespace AppInstaller::CLI::Execution
246249
}
247250

248251
// Get the item's command and execute it.
249-
HRESULT terminationHR = S_OK;
252+
HRESULT exceptionHR = S_OK;
250253
try
251254
{
252255
std::unique_ptr<Command> command = item->PopNextCommand();
253256

254257
std::unique_ptr<AppInstaller::ThreadLocalStorage::PreviousThreadGlobals> setThreadGlobalsToPreviousState = item->GetContext().SetForCurrentThread();
255258

256-
item->GetContext().GetThreadGlobals().GetTelemetryLogger().LogCommand(command->FullName());
257259
command->ValidateArguments(item->GetContext().Args);
258260

259261
item->GetContext().EnableCtrlHandler();
260262

261-
terminationHR = ::AppInstaller::CLI::Execute(item->GetContext(), command);
263+
::AppInstaller::CLI::ExecuteWithoutLoggingSuccess(item->GetContext(), command.get());
262264
}
263-
WINGET_CATCH_STORE(terminationHR, APPINSTALLER_CLI_ERROR_COMMAND_FAILED);
265+
WINGET_CATCH_STORE(exceptionHR, APPINSTALLER_CLI_ERROR_COMMAND_FAILED);
264266

265-
if (FAILED(terminationHR))
267+
if (FAILED(exceptionHR))
266268
{
267-
// ::Execute sometimes catches exceptions and returns hresults based on those exceptions without the context
268-
// being updated with that hresult. This sets the termination hr directly so that the context always
269+
// Set the termination hr directly from any exception that escaped so that the context always
269270
// has the result of the operation no matter how it failed.
270-
item->GetContext().SetTerminationHR(terminationHR);
271+
item->GetContext().SetTerminationHR(exceptionHR);
271272
}
272273

273274
item->GetContext().EnableCtrlHandler(false);
274275

275-
if (FAILED(terminationHR) || item->IsComplete())
276+
if (FAILED(item->GetContext().GetTerminationHR()) || item->IsComplete())
276277
{
278+
if (SUCCEEDED(item->GetContext().GetTerminationHR()))
279+
{
280+
item->GetContext().GetThreadGlobals().GetTelemetryLogger().LogCommandSuccess(item->GetItemCommandName());
281+
}
282+
277283
RemoveItemInState(*item, OrchestratorQueueItemState::Running, true);
278284
}
279285
else
@@ -334,6 +340,19 @@ namespace AppInstaller::CLI::Execution
334340
(GetSourceId() == comparedId.GetSourceId()));
335341
}
336342

343+
std::string_view OrchestratorQueueItem::GetItemCommandName() const
344+
{
345+
// The goal is that these should match the winget.exe commands for easy correlation.
346+
switch (m_operationType)
347+
{
348+
case PackageOperationType::Search: return "root:search"sv;
349+
case PackageOperationType::Install: return "root:install"sv;
350+
case PackageOperationType::Upgrade: return "root:upgrade"sv;
351+
case PackageOperationType::Uninstall: return "root:uninstall"sv;
352+
default: return "unknown";
353+
}
354+
}
355+
337356
std::unique_ptr<OrchestratorQueueItem> OrchestratorQueueItemFactory::CreateItemForInstall(std::wstring packageId, std::wstring sourceId, std::unique_ptr<COMContext> context, bool isUpgrade)
338357
{
339358
std::unique_ptr<OrchestratorQueueItem> item = std::make_unique<OrchestratorQueueItem>(OrchestratorQueueItemId(std::move(packageId), std::move(sourceId)), std::move(context), isUpgrade ? PackageOperationType::Upgrade : PackageOperationType::Install);
@@ -351,7 +370,7 @@ namespace AppInstaller::CLI::Execution
351370

352371
std::unique_ptr<OrchestratorQueueItem> OrchestratorQueueItemFactory::CreateItemForSearch(std::wstring packageId, std::wstring sourceId, std::unique_ptr<COMContext> context)
353372
{
354-
std::unique_ptr<OrchestratorQueueItem> item = std::make_unique<OrchestratorQueueItem>(OrchestratorQueueItemId(std::move(packageId), std::move(sourceId)), std::move(context), PackageOperationType::None);
373+
std::unique_ptr<OrchestratorQueueItem> item = std::make_unique<OrchestratorQueueItem>(OrchestratorQueueItemId(std::move(packageId), std::move(sourceId)), std::move(context), PackageOperationType::Search);
355374
return item;
356375
}
357376
}

src/AppInstallerCLICore/ContextOrchestrator.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace AppInstaller::CLI::Execution
4242

4343
enum class PackageOperationType
4444
{
45-
None,
45+
Search,
4646
Install,
4747
Upgrade,
4848
Uninstall,
@@ -77,6 +77,7 @@ namespace AppInstaller::CLI::Execution
7777
bool IsComplete() const { return m_commands.empty(); }
7878
bool IsApplicableForInstallingSource() const { return m_operationType == PackageOperationType::Install || m_operationType == PackageOperationType::Upgrade; }
7979
PackageOperationType GetPackageOperationType() const { return m_operationType; }
80+
std::string_view GetItemCommandName() const;
8081

8182
private:
8283
OrchestratorQueueItemState m_state = OrchestratorQueueItemState::NotQueued;
@@ -86,7 +87,7 @@ namespace AppInstaller::CLI::Execution
8687
std::deque<std::unique_ptr<Command>> m_commands;
8788
bool m_isOnFirstCommand = true;
8889
OrchestratorQueue* m_currentQueue = nullptr;
89-
PackageOperationType m_operationType = PackageOperationType::None;
90+
PackageOperationType m_operationType;
9091
};
9192

9293
struct OrchestratorQueueItemFactory

0 commit comments

Comments
 (0)