Skip to content

Collect Authentication Telemetry #27560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Conversation

msJinLei
Copy link
Contributor

@msJinLei msJinLei commented Apr 14, 2025

Description

The purpose of the PR is to send new property to Azure PowerShell telemetry to collection information of authentication

  • The following figure is what new properties look like
image
  • The details of auth-info-secondary
    [{"TokenCredentialName":"SharedTokenCacheCredential","AuthenticationSuccess":true},{"TokenCredentialName":"SharedTokenCacheCredential","AuthenticationSuccess":false},{"TokenCredentialName":"SharedTokenCacheCredential","AuthenticationSuccess":false},{"TokenCredentialName":"SharedTokenCacheCredential","AuthenticationSuccess":false},{"TokenCredentialName":"SharedTokenCacheCredential","AuthenticationSuccess":true},{"TokenCredentialName":"SharedTokenCacheCredential","AuthenticationSuccess":false},{"TokenCredentialName":"SharedTokenCacheCredential","AuthenticationSuccess":false}]

  • API Change
    Add Interface to Send Auth Info to Telemetry azure-powershell-common#421

Mandatory Checklist

  • SHOULD update ChangeLog.md file(s) appropriately
    • For SDK-based development mode, update src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.
      • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header in the past tense.
    • For autorest-based development mode, include the changelog in the PR description.
    • Should not change ChangeLog.md if no new release is required, such as fixing test case only.
  • SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
  • SHOULD have proper test coverage for changes in pull request.
  • SHOULD NOT adjust version of module manually in pull request

Copy link

Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

@msJinLei msJinLei added this to the Az 13.5.0 (05/06/2025) milestone Apr 14, 2025
@msJinLei msJinLei force-pushed the jinlei/includeLatestCommon branch from f2c75d6 to e90adbf Compare April 22, 2025 20:50
@msJinLei msJinLei marked this pull request as ready for review April 23, 2025 07:52
@msJinLei msJinLei requested review from NoriZC and Copilot April 23, 2025 08:33
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces authentication telemetry collection by adding and passing a new CmdletContext property throughout the authentication workflow. Key changes include:

  • Adding a new public ICmdletContext property in RMProfileClient and updating authentication methods to use it.
  • Updating various components and test files to register and pass the _cmdletContext as part of authentication requests.
  • Modifying methods in ContextAdapter and others to support the additional telemetry context.

Reviewed Changes

Copilot reviewed 52 out of 52 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Accounts/Accounts/Models/RMProfileClient.cs Added ICmdletContext property and updated Authenticate method.
src/Accounts/Accounts/Environment/GetAzureRMEnvironment.cs Instantiated RMProfileClient with new CmdletContext property.
src/Accounts/Accounts/Default/SetAzureRMDefault.cs Updated GetServiceClientCredentials call to include _cmdletContext.
src/Accounts/Accounts/Default/GetAzureRmDefault.cs Updated GetServiceClientCredentials call to include _cmdletContext.
src/Accounts/Accounts/Context/GetAzureRMContext.cs Modified RefreshContextsFromCache to pass _cmdletContext.
src/Accounts/Accounts/CommonModule/EnvironmentExtensions.cs Minor update to use default literal for improved readability.
src/Accounts/Accounts/CommonModule/ContextAdapter.cs Extended authentication helper methods to accept and pass cmdletContext.
src/Accounts/Accounts/Common/AzureContextModificationCmdlet.cs Updated object initialization to include CmdletContext property.
Test Files Updated tests to register AuthenticationTelemetry component.
src/Accounts/Accounts/ChangeLog.md Updated changelog to document telemetry changes.

@msJinLei msJinLei requested a review from dolauli April 24, 2025 02:40
{
optionalParameters.Add(AuthenticationFactory.CmdletContextParameterName, extensibleParameters[AuthenticationFactory.CmdletContextParameterName]);
}
var authToken = _authenticator.Authenticate(context.Account, context.Environment, context.Tenant.Id, null, "Never", null, optionalParameters);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please explain the change here?

{
{ TokenCacheParameterName, tokenCache },
{ ResourceIdParameterName, resourceId }
};
Copy link
Contributor

Choose a reason for hiding this comment

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

why are these 2 parameters set as optional parameters? Especially when tokenCache do not have a default value.

@@ -118,7 +121,12 @@ internal void AddAuthorizeRequestHandler(
{
endpointResourceIdKey = endpointResourceIdKey ?? AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId;
var context = GetDefaultContext(_provider, invocationInfo);
return await AuthenticationHelper(context, endpointResourceIdKey, endpointSuffixKey, request, cancelToken, cancelAction, signal, next);
ICmdletContext cmdletContext = AzureCmdletContext.CmdletNone;
Copy link
Contributor

Choose a reason for hiding this comment

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

AddAuthorizeRequestHandler is used in Autogen Data plane module. But extensibleParameters is actually not populated when this function is called in autogen module. So for autogen modules, we will not generate telemetry for authentication, is it right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Another question is whether we need to add similar logic for onnewrequest, which is used by manage plane modules.

@@ -342,7 +342,7 @@ internal static void CheckAndEnqueue<T>(this ConcurrentQueue<T> queue, T item)

internal static bool TryDequeueIfNotNull<T>(this ConcurrentQueue<T> queue, out T result)
{
result = default(T);
result = default;
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to change this?

@@ -72,7 +72,7 @@ private void UpdateStorage(KeyStoreNotificationArgs args)
helper.WriteToCachedStorage(args.KeyCache);
}

public void Clear()
public virtual void Clear()
Copy link
Contributor

@NoriZC NoriZC Apr 24, 2025

Choose a reason for hiding this comment

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

Could you please explain here? Who is inheriting current class and overriding current function?

options.DisableInstanceDiscovery = spParameters.DisableInstanceDiscovery ?? options.DisableInstanceDiscovery;
options.Diagnostics.IsTelemetryEnabled = false; // disable telemetry to avoid error thrown from Azure.Core that AssemblyInformationalVersion is null
TokenCredential tokenCredential = new ClientAssertionCredential(tenantId, spParameters.ClientId, () => GetClientAssertion(spParameters), options);

base.CollectTelemetry(tokenCredential);
CheckTokenCachePersistanceEnabled = () =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Just questioning - If CheckTokenCachePersistanceEnabled is implemented in most authenticators, can we define this function in a more common place?

@@ -75,7 +78,7 @@ public void OnNewRequest(InvocationInfo invocationInfo, string correlationId, st
{
prependStep(UniqueId.Instance.SendAsync);
appendStep(new UserAgent(invocationInfo).SendAsync);
appendStep(this.SendHandler(GetDefaultContext(_provider, invocationInfo), AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId));
appendStep(this.SendHandler(GetDefaultContext(_provider, invocationInfo), AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId, new AzureCmdletContext(correlationId)));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

double check correlationId

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants