Skip to content

Commit 9f6ab14

Browse files
committed
minor fix
1 parent 819cea0 commit 9f6ab14

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/azure-cli-core/azure/cli/core/commands/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ def _what_if(self, args):
719719
if not self._is_command_supported_for_what_if(args):
720720
error_msg = ("\"--what-if\" argument is not supported for this command.")
721721
logger.error(error_msg)
722+
telemetry.set_what_if_summary('what-if-unsupported-command')
722723
telemetry.set_user_fault(summary='what-if-unsupported-command')
723724
return CommandResultItem(None, exit_code=1, error=CLIError(error_msg))
724725

@@ -765,6 +766,7 @@ def _what_if(self, args):
765766
if 'output' not in self.cli_ctx.invocation.data or self.cli_ctx.invocation.data['output'] is None:
766767
self.cli_ctx.invocation.data['output'] = 'json'
767768

769+
telemetry.set_what_if_summary('what-if-completed')
768770
telemetry.set_success(summary='what-if-completed')
769771

770772
# Return the formatted what-if output as the result
@@ -778,6 +780,8 @@ def _what_if(self, args):
778780
except (CLIError, ValueError, KeyError) as ex:
779781
# If what-if service fails, still show an informative message
780782
logger.error("What-if preview failed: %s", str(ex))
783+
telemetry.set_what_if_summary('what-if-failed')
784+
telemetry.set_what_if_exception(ex)
781785
telemetry.set_exception(ex, fault_type='what-if-error')
782786
telemetry.set_failure(summary='what-if-failed')
783787
return CommandResultItem(None, exit_code=1,

src/azure-cli-core/azure/cli/core/telemetry.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ def __init__(self, correlation_id=None, application=None):
7878
self.enable_broker_on_windows = None
7979
self.msal_telemetry = None
8080
self.login_experience_v2 = None
81+
# what-if specific telemetry
82+
self.what_if_summary = None
83+
self.what_if_exception = None
8184

8285
def add_event(self, name, properties):
8386
for key in self.instrumentation_key:
@@ -234,6 +237,9 @@ def _get_azure_cli_properties(self):
234237
set_custom_properties(result, 'EnableBrokerOnWindows', str(self.enable_broker_on_windows))
235238
set_custom_properties(result, 'MsalTelemetry', self.msal_telemetry)
236239
set_custom_properties(result, 'LoginExperienceV2', str(self.login_experience_v2))
240+
# what-if related
241+
set_custom_properties(result, 'WhatIfSummary', self.what_if_summary)
242+
set_custom_properties(result, 'WhatIfException', self.what_if_exception)
237243

238244
return result
239245

@@ -486,6 +492,18 @@ def set_msal_telemetry(msal_telemetry):
486492
@decorators.suppress_all_exceptions()
487493
def set_login_experience_v2(login_experience_v2):
488494
_session.login_experience_v2 = login_experience_v2
495+
496+
497+
@decorators.suppress_all_exceptions()
498+
def set_what_if_summary(summary):
499+
_session.what_if_summary = summary
500+
501+
502+
@decorators.suppress_all_exceptions()
503+
def set_what_if_exception(exception):
504+
# Store exception type and message, limit length to avoid huge payloads
505+
exception_info = f"{exception.__class__.__name__}: {str(exception)[:512]}"
506+
_session.what_if_exception = exception_info
489507
# endregion
490508

491509

src/azure-cli-telemetry/azure/cli/telemetry/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def save(config_dir, payload):
5858
events = json.loads(payload)
5959

6060
logger.info('Begin splitting cli events and extra events, total events: %s', len(events))
61+
logger.debug('events: %s', events)
6162
cli_events = {}
6263
client = CliTelemetryClient()
6364
for key, event in events.items():

0 commit comments

Comments
 (0)