Skip to content
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

Updating extension telemetry #4996

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

Conversation

trwalke
Copy link
Member

@trwalke trwalke commented Nov 15, 2024

Fixes #

Changes proposed in this request
Updating telemetry to always record the operation time used by the classes that implement IAuthenticationOperation.
Enabling the telemetry data to add histograms to telemetry based on the telemetry token type reported by IAuthenticationOperation.

Testing
Updated tests to cover new scenario

Performance impact
Negligible

Documentation

  • All relevant documentation is updated.

trwalke and others added 2 commits November 17, 2024 23:27
Removing TokenType and replacing the values with string
@trwalke trwalke marked this pull request as ready for review November 18, 2024 07:27
@trwalke trwalke requested a review from a team as a code owner November 18, 2024 07:27
/// <summary>
/// Specifies the token type to log to telemetry.
/// </summary>
internal enum TokenType
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 for removing the enum? I liked the enum better, they are more readable and separates out the token types from all the other constants.

/// <summary>
///
/// </summary>
public string TelemetryTokenType { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add in the comment how this is different from the token type in authentication result?

@@ -245,7 +245,7 @@ private ApiEvent InitializeApiEvent(string accountId)
AuthenticationRequestParameters.RequestContext.ServiceBundle.Config.LegacyCacheCompatibilityEnabled;

apiEvent.CacheInfo = CacheRefreshReason.NotApplicable;
apiEvent.TokenType = (TokenType)AuthenticationRequestParameters.AuthenticationScheme.TelemetryTokenType;
apiEvent.TokenType = AuthenticationRequestParameters.AuthenticationScheme.TelemetryTokenType;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we might want to capture both TokenType and TelemetryTokenType in telemetry? I am a bit confused on what combinations are for these 2 values. Can you list some examples to help understand?

Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding is that the values are different only when the TelemetryTokenType is external. In that case, what will be the possible TokenTypes from ests?


private void LogExtensionMetrics(AuthenticationResultMetadata authenticationResultMetadata, string platform, ApiEvent.ApiIds apiId)
{
if (authenticationResultMetadata.DurationCreatingExtendedTokenInUs <= 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it the case when this metrics is not captured? Can the condition be something like if TelemetryTokenType != Extension instead? Maybe 0 is a valid value in certain cases and should be captured?

@@ -30,7 +31,8 @@ internal class OtelInstrumentation : IOtelInstrumentation
private const string DurationInL1CacheHistogramName = "MsalDurationInL1CacheInUs.1B";
private const string DurationInL2CacheHistogramName = "MsalDurationInL2Cache.1A";
private const string DurationInHttpHistogramName = "MsalDurationInHttp.1A";
private const string DurationInExtensionInMsHistogram = "MsalDurationInExtensionInMs.1B";

private static Lazy<Dictionary<string, Histogram<long>>> ExtensionCounters = new(() => new Dictionary<string, Histogram<long> > ());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private static Lazy<Dictionary<string, Histogram<long>>> ExtensionCounters = new(() => new Dictionary<string, Histogram<long> > ());
private static Lazy<Dictionary<string, Histogram<long>>> ExtensionHistogram = new(() => new Dictionary<string, Histogram<long> > ());

Counters and histograms are 2 different concepts in otel. Naming a histogram as counter is confusing

else
{
Histogram<long> newHistogram = Meter.CreateHistogram<long>(
$"MsalDuration{authenticationResultMetadata.TelemetryTokenType}Operation.1B",
Copy link
Contributor

Choose a reason for hiding this comment

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

How many histograms are we expecting to create? I am expecting only with the TelemetryTokenType as Extention?

Copy link
Contributor

Choose a reason for hiding this comment

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

Did you consider capturing token type as a tag instead? I think that should give you similar results instead of creating different histograms considering you are capturing same data in all of them.

return;
}

if (ExtensionCounters.Value.TryGetValue(authenticationResultMetadata.TelemetryTokenType, out Histogram<long> tokenCounter))
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename tokenCounter to extensionHistogram or something similar?

LogExtensionMetrics(authResultMetadata, platform, apiId);
}

private void LogExtensionMetrics(AuthenticationResultMetadata authenticationResultMetadata, string platform, ApiEvent.ApiIds apiId)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add comment on possible histograms being created here?

{
get => TokenType.HasValue ? TokenType.Value.ToString("D") : null;
}
public string TokenType { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a breaking change. The current value that is recorded in the server side telemetry is a numeric value of the enum. For example: 5|1004,2,,,|0,1,1. This change will break all the queries checking this value.

Copy link
Contributor

@neha-bhargava neha-bhargava left a comment

Choose a reason for hiding this comment

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

Mainly, the token type is changed from enum to string which is a breaking change for server side telemetry. Also, would like to understand which histograms are created as part of this change. Can those be combined into a single histogram with tokenType as a tag?

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