@@ -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}
0 commit comments