Conversation
…ninsights in main process
️✔️AzureCLI-FullTest
|
️✔️AzureCLI-BreakingChangeTest
|
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
There was a problem hiding this comment.
Pull request overview
This PR improves Azure CLI telemetry performance by avoiding an expensive applicationinsights import in the common path of telemetry.save(), only loading it when non-default (“extra”) instrumentation-key events are present.
Changes:
- Move
CliTelemetryClientimport behind anif extra_events:guard insave() - Split events into
cli_eventsvsextra_eventsfirst, then upload extra events only if needed
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for key, event in extra_events.items(): | ||
| client.add(json.dumps({key: event}), flush=True) |
Related command
Description
Problem
The
save()function inazure/cli/telemetry/__init__.pyunconditionally importsCliTelemetryClient, which triggers top-levelfrom applicationinsights import ...intelemetry_client.py. This loads 146 modules — even though the client is only needed for "extra events" with non-default instrumentation keys, which no extension currently uses.Fix
Defer the
CliTelemetryClientimport behind anif extra_events:guard. Events are first split by instrumentation key; only if non-default key events exist does the code import applicationinsights and create a client. The common path (all events useDEFAULT_INSTRUMENTATION_KEY) now skips the import entirely.Time Save (on DevBox)


Before:
The
savemethod takes 111ms in conclude telemetry.After:


The
savemethod takes 22ms in concluding telemetry.The
extension --helpcommand saves about 90 ms.Testing Guide
History Notes
[Component Name 1] BREAKING CHANGE:
az command a: Make some customer-facing breaking change[Component Name 2]
az command b: Add some customer-facing featureThis checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.