Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/azure-cli-core/azure/cli/core/auth/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ def check_result(result, **kwargs):
if not result:
raise AuthenticationError("Can't find token from MSAL cache.",
recommendation="To re-authenticate, please run:\naz login")

# msal_telemetry should be sent no matter if the MSAL response is a success or an error
if 'msal_telemetry' in result:
from azure.cli.core.telemetry import set_msal_telemetry
set_msal_telemetry(result['msal_telemetry'])

if 'error' in result:
aad_error_handler(result, **kwargs)

Expand Down
8 changes: 8 additions & 0 deletions src/azure-cli-core/azure/cli/core/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __init__(self, correlation_id=None, application=None):
self.poll_start_time = None
self.poll_end_time = None
self.allow_broker = None
self.msal_telemetry = None

def add_event(self, name, properties):
for key in self.instrumentation_key:
Expand Down Expand Up @@ -217,6 +218,7 @@ def _get_azure_cli_properties(self):
set_custom_properties(result, 'RegionInput', self.region_input)
set_custom_properties(result, 'RegionIdentified', self.region_identified)
set_custom_properties(result, 'AllowBroker', str(self.allow_broker))
set_custom_properties(result, 'MsalTelemetry', self.msal_telemetry)

return result

Expand Down Expand Up @@ -459,6 +461,12 @@ def set_broker_info(allow_broker):
_session.allow_broker = allow_broker


@decorators.suppress_all_exceptions()
def set_msal_telemetry(msal_telemetry):
if not _session.msal_telemetry:
_session.msal_telemetry = msal_telemetry
Comment on lines +466 to +467
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a CLI command makes several MSAL calls, only the first telemetry record is preserved.

The most special command is az login which calls acquire_token_interactive first, then several subsequent acquire_token_silent_with_errors:

  1. acquire_token_interactive: initial login
  2. acquire_token_silent_with_error: list tenants
  3. acquire_token_silent_with_error: list subscriptions in tenant 1
  4. acquire_token_silent_with_error: list subscriptions in tenant 2
  5. ...

If step 1 fails, its telemetry will be sent and az login will fail. If step 1 succeeds, its telemetry will be sent, and step 2 and following steps' telemetry will be discarded, no matter if they fail or not.

For long running operation commands such as az storage account create, only the MSAL telemetry for the initial PUT request is sent. Following MSAL telemetry for GET polling requests is discarded.



@decorators.suppress_all_exceptions()
def add_dedicated_instrumentation_key(dedicated_instrumentation_key):
if not dedicated_instrumentation_key:
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
'jmespath',
'knack~=0.10.1',
'msal-extensions~=1.0.0',
'msal[broker]==1.22.0',
'msal[broker]==1.24.0b1',
'msrestazure~=0.6.4',
'packaging>=20.9',
'paramiko>=2.0.8,<4.0.0',
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.Darwin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jsondiff==2.0.0
knack==0.10.1
MarkupSafe==2.0.1
msal-extensions==1.0.0
msal[broker]==1.22.0
msal[broker]==1.24.0b1
msrest==0.7.1
msrestazure==0.6.4
oauthlib==3.2.2
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.Linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jsondiff==2.0.0
knack==0.10.1
MarkupSafe==2.0.1
msal-extensions==1.0.0
msal[broker]==1.22.0
msal[broker]==1.24.0b1
msrest==0.7.1
msrestazure==0.6.4
oauthlib==3.2.2
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jsondiff==2.0.0
knack==0.10.1
MarkupSafe==2.0.1
msal-extensions==1.0.0
msal[broker]==1.22.0
msal[broker]==1.24.0b1
msrest==0.7.1
msrestazure==0.6.4
oauthlib==3.2.2
Expand Down