Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
msJinLei committed Jul 26, 2024
1 parent dc2ab92 commit 39e6304
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/Authentication.Abstractions/AuthTelemetryRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class AuthTelemetryRecord : IAuthTelemetryRecord
/// </summary>
public bool AuthenticationSuccess { get; set; } = false;

public bool correlationId { get; set; }

/// <summary>
/// Additional properties for AuthenticationInfo
/// </summary>
Expand Down Expand Up @@ -64,11 +66,11 @@ public AuthTelemetryRecord(IAuthTelemetryRecord other, bool? isSuccess = null)
/// <summary>
/// Prefix of properties of the first record of authentication telemetry record.
/// </summary>
public const string AuthInfoTelemetryHeadKey = "auth-info-head";
public const string AuthTelemetryPropertyHeadPrefix = "auth-info-head";

/// <summary>
/// Key of the left records of authentication telemetry.
/// </summary>
public const string AuthInfoTelemetrySubsequentKey = "auth-info-sub";
public const string AuthTelemetryPropertyTailKey = "auth-info-tail";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ public interface IAuthTelemetryRecord : IExtensibleModel
/// Authentication process succeed or not.
/// </summary>
bool AuthenticationSuccess { get; set; }

bool correlationId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ IAccessToken Authenticate(
IAzureTokenCache tokenCache,
string resourceId = AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId);

/// <summary>
/// Returns IAccessToken if authentication succeeds or throws an exception if authentication fails.
/// </summary>
/// <param name="requestId">the Id of current authentication request</param>
/// <param name="account">The azure account object</param>
/// <param name="environment">The azure environment object</param>
/// <param name="tenant">The AD tenant in most cases should be 'common'</param>
/// <param name="password">The AD account password</param>
/// <param name="promptBehavior">The prompt behavior</param>
/// <param name="promptAction">The prompt action used in DeviceFlow authentication</param>
/// <param name="tokenCache">Token Cache</param>
/// <param name="resourceId">Optional, the AD resource id</param>
/// <returns></returns>
IAccessToken Authenticate(
string requestId,
IAzureAccount account,
IAzureEnvironment environment,
string tenant,
SecureString password,
string promptBehavior,
Action<string> promptAction,
IAzureTokenCache tokenCache,
string resourceId = AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId);

/// <summary>
/// Returns IAccessToken if authentication succeeds or throws an exception if authentication fails.
/// </summary>
Expand Down Expand Up @@ -99,6 +123,6 @@ IAccessToken Authenticate(
/// <summary>
/// Get the information to be recorded in Telemetry
/// </summary>
AuthenticationTelemetry GetDataForTelemetry();
AuthenticationTelemetry GetDataForTelemetry(string requestId);
}
}
2 changes: 1 addition & 1 deletion src/Common/AzurePSCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ protected void LogQosEvent()

_qosEvent.ParameterSetName = this.ParameterSetName;
_qosEvent.FinishQosEvent();
_qosEvent.AuthTelemetry = AzureSession.Instance.AuthenticationFactory.GetDataForTelemetry();
_qosEvent.AuthTelemetry = AzureSession.Instance.AuthenticationFactory.GetDataForTelemetry(_clientRequestId);

if (!IsUsageMetricEnabled && (!IsErrorMetricEnabled || _qosEvent.IsSuccess))
{
Expand Down
8 changes: 4 additions & 4 deletions src/Common/MetricHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,15 @@ public void SetPSHost(PSHost host)
private static void PopulateAuthenticationPropertiesFromQos(AuthenticationTelemetry telemetry, IDictionary<string, string> eventProperties)
{
var record = telemetry.Head;
eventProperties[$"{AuthTelemetryRecord.AuthInfoTelemetryHeadKey}-{nameof(record.TokenCredentialName).ToLower()}"] = record.TokenCredentialName;
eventProperties[$"{AuthTelemetryRecord.AuthInfoTelemetryHeadKey}-{nameof(record.AuthenticationSuccess).ToLower()}"] = record.AuthenticationSuccess.ToString();
eventProperties[$"{AuthTelemetryRecord.AuthTelemetryPropertyHeadPrefix}-{nameof(record.TokenCredentialName).ToLower()}"] = record.TokenCredentialName;
eventProperties[$"{AuthTelemetryRecord.AuthTelemetryPropertyHeadPrefix}-{nameof(record.AuthenticationSuccess).ToLower()}"] = record.AuthenticationSuccess.ToString();

foreach (var property in record.ExtendedProperties)
{
eventProperties[$"{AuthTelemetryRecord.AuthInfoTelemetryHeadKey}-{property.Key.ToLower()}"] = property.Value;
eventProperties[$"{AuthTelemetryRecord.AuthTelemetryPropertyHeadPrefix}-{property.Key.ToLower()}"] = property.Value;
}

eventProperties[AuthTelemetryRecord.AuthInfoTelemetrySubsequentKey] = JsonConvert.SerializeObject(telemetry.Tail);
eventProperties[AuthTelemetryRecord.AuthTelemetryPropertyTailKey] = JsonConvert.SerializeObject(telemetry.Tail);
}

private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary<string, string> eventProperties, bool populateException = false)
Expand Down

0 comments on commit 39e6304

Please sign in to comment.