Skip to content

Commit 252813c

Browse files
committed
Add telemetry
1 parent d36baf6 commit 252813c

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -702,20 +702,32 @@ def _what_if(self, args):
702702
if '--what-if' in args:
703703
logger.debug("Entering what-if mode")
704704

705+
# Remove both --what-if and --export-bicep from args for processing
706+
clean_args = [arg for arg in args if arg not in ['--what-if', '--export-bicep']]
707+
command_parts = [arg for arg in clean_args if not arg.startswith('-') and arg != 'az']
708+
command_name = ' '.join(command_parts) if command_parts else 'unknown'
709+
safe_params = AzCliCommandInvoker._extract_parameter_names(args)
710+
711+
# Set command details first so telemetry knows which command was attempted
712+
telemetry.set_command_details(
713+
command_name + ' --what-if',
714+
self.data.get('output', 'json'),
715+
safe_params
716+
)
717+
705718
# Check if command is in whitelist
706719
if not self._is_command_supported_for_what_if(args):
707720
error_msg = ("\"--what-if\" argument is not supported for this command.")
708721
logger.error(error_msg)
722+
telemetry.set_user_fault(summary='what-if-unsupported-command')
709723
return CommandResultItem(None, exit_code=1, error=CLIError(error_msg))
710724

711725
from azure.cli.core.what_if import show_what_if
726+
727+
# Check if --export-bicep is present
728+
export_bicep = '--export-bicep' in args
729+
712730
try:
713-
# Check if --export-bicep is present
714-
export_bicep = '--export-bicep' in args
715-
716-
# Remove both --what-if and --export-bicep from args for processing
717-
clean_args = [arg for arg in args if arg not in ['--what-if', '--export-bicep']]
718-
719731
if export_bicep:
720732
logger.debug("Export bicep mode enabled")
721733

@@ -752,6 +764,8 @@ def _what_if(self, args):
752764
# Default to 'json' if not already set
753765
if 'output' not in self.cli_ctx.invocation.data or self.cli_ctx.invocation.data['output'] is None:
754766
self.cli_ctx.invocation.data['output'] = 'json'
767+
768+
telemetry.set_success(summary='what-if-completed')
755769

756770
# Return the formatted what-if output as the result
757771
# Similar to the normal flow in execute() method
@@ -764,6 +778,8 @@ def _what_if(self, args):
764778
except (CLIError, ValueError, KeyError) as ex:
765779
# If what-if service fails, still show an informative message
766780
logger.error("What-if preview failed: %s", str(ex))
781+
telemetry.set_exception(ex, fault_type='what-if-error', summary=str(ex)[:100])
782+
telemetry.set_failure(summary='what-if-failed')
767783
return CommandResultItem(None, exit_code=1,
768784
error=CLIError(f'What-if preview failed: {str(ex)}'))
769785

0 commit comments

Comments
 (0)