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

Add request count and duration telemetry #3022

Open
wants to merge 20 commits into
base: dev
Choose a base branch
from
Open

Conversation

westin-m
Copy link
Contributor

@westin-m westin-m commented Nov 20, 2024

Addresses client telemetry repair item

Add counter for get configuration requests and histogram for total duration of the same requests.

@westin-m westin-m linked an issue Nov 20, 2024 that may be closed by this pull request
@westin-m westin-m marked this pull request as ready for review November 21, 2024 23:05
@westin-m westin-m requested a review from a team as a code owner November 21, 2024 23:05
@westin-m westin-m changed the title Add request count and duration telemetry DRAFT Add request count and duration telemetry Nov 21, 2024
build/dependenciesTest.props Outdated Show resolved Hide resolved
Copy link
Member

@brentschmaltz brentschmaltz left a comment

Choose a reason for hiding this comment

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

Asking for laying changes.

@westin-m westin-m force-pushed the westin/clientTelemetry branch from 518df9f to 5e917c9 Compare December 13, 2024 05:51
@skblr2022
Copy link

Table identitymodelconfigurationmanager_counter
1> Could the field net_IdentityModelVersion be named as "net_WilsonVersion" to maintain parity with other tables?
2> Any wiki doc explaining the different values of net_OperationStatus? What does Direct / Automatic / FirstRefresh / LastKnownGood indicate?
3> Does this table capture both data for both successful and failed metadata requests? Ex: In the case of validation failure with msg "SignatureKeyNotFound" there would be an eSTS metadata request. So, wondering how to identify failure requests?
4> Why is the net_MetadataAddress add empty or null for some records?

Table identitymodelconfigurationrequesttotaldurationinms_histogram
1> I am inferring from the table name, as it has inms_ instead of inus_, the net_bounds data in this table is recorded in milliseconds. Why is the data not captured in microseconds?
2> Here again, could the field net_IdentityModelVersion be named as "net_WilsonVersion" to maintain parity with other tables?
3> Similar to #3 above are failed metadata requests captured in this table?

@westin-m
Copy link
Contributor Author

2> Any wiki doc explaining the different values of net_OperationStatus? What does Direct / Automatic / FirstRefresh / LastKnownGood indicate?

I can make a doc, good idea

3> Does this table capture both data for both successful and failed metadata requests? Ex: In the case of validation failure with msg "SignatureKeyNotFound" there would be an eSTS metadata request. So, wondering how to identify failure requests?

failed requests will have an exception message attached, they just aren't in the table right now because I was going for success cases to show all the operations. Unit tests prove the existence of this in the taglist right now

4> Why is the net_MetadataAddress add empty or null for some records?

I added metadata address partway through testing. We weren't sure at first if we wanted it. It is null in some of the LKG entries because I used some unit test-like code to contrive the error which precedes that tag being used. Normally, it will look like the LKG entry that has a metadata address

Table identitymodelconfigurationrequesttotaldurationinms_histogram 1> I am inferring from the table name, as it has inms_ instead of inus_, the net_bounds data in this table is recorded in milliseconds. Why is the data not captured in microseconds?

Milliseconds was recommended to me and it matched other, similar code. I can change it if microseconds is preferred.

3> Similar to #3 above are failed metadata requests captured in this table?

same as above, a different taglist is created that contains an exception. right now, unit tests prove that this portion is populated

Choose a reason for hiding this comment

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

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

Files not reviewed (15)
  • build/dependencies.props: Language not supported
  • build/dependenciesTest.props: Language not supported
  • src/Microsoft.IdentityModel.JsonWebTokens/InternalAPI.Unshipped.txt: Language not supported
  • src/Microsoft.IdentityModel.Logging/Microsoft.IdentityModel.Logging.csproj: Language not supported
  • src/Microsoft.IdentityModel.Protocols/InternalAPI.Unshipped.txt: Language not supported
  • src/Microsoft.IdentityModel.Tokens/InternalAPI.Unshipped.txt: Language not supported
  • src/System.IdentityModel.Tokens.Jwt/InternalAPI.Unshipped.txt: Language not supported
  • test/Microsoft.IdentityModel.Logging.Tests/Microsoft.IdentityModel.Logging.Tests.csproj: Language not supported
  • test/Microsoft.IdentityModel.Protocols.OpenIdConnect.Tests/Microsoft.IdentityModel.Protocols.OpenIdConnect.Tests.csproj: Language not supported
  • src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.ValidateToken.cs: Evaluated as low risk
  • src/Microsoft.IdentityModel.Protocols/Configuration/ConfigurationManager.cs: Evaluated as low risk
  • src/Microsoft.IdentityModel.Protocols/InternalsVisibleTo.cs: Evaluated as low risk
  • src/Microsoft.IdentityModel.Tokens/Telemetry/ITelemetryInstrumentation.cs: Evaluated as low risk
  • src/Microsoft.IdentityModel.Tokens/Telemetry/IdentityModelTelemetry.cs: Evaluated as low risk
  • src/Microsoft.IdentityModel.Tokens/Telemetry/TelemetryConstants.cs: Evaluated as low risk
Comments suppressed due to low confidence (2)

src/System.IdentityModel.Tokens.Jwt/JwtSecurityTokenHandler.cs:893

  • Ensure that validationParameters.ConfigurationManager.MetadataAddress is not null or empty before logging it.
_telemetryClient.IncrementConfigurationRefreshRequestCounter(

src/Microsoft.IdentityModel.Tokens/Telemetry/TelemetryInstrumentation.cs:48

  • [nitpick] The method name 'RecordConfigurationRetrievalDurationHistogram' is too long and could be simplified to 'RecordRetrievalDuration' for better readability.
IdentityModelTelemetry.RecordConfigurationRetrievalDurationHistogram(durationInMilliseconds, tagList);
@@ -8,6 +8,7 @@
<MicrosoftSourceLinkGitHubVersion>1.0.0</MicrosoftSourceLinkGitHubVersion>
<NetStandardVersion>2.0.3</NetStandardVersion>
<NewtonsoftVersion>13.0.3</NewtonsoftVersion>
<SystemDiagnosticSourceVersion>8.0.1</SystemDiagnosticSourceVersion>
Copy link
Contributor

@pmaytak pmaytak Dec 20, 2024

Choose a reason for hiding this comment

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

Is this the minimum version we can use? I remember we had issues with this when we added it to MSAL because Azure Functions didn't have this dependency. (I think it was in .NET 6 Azure Functions, so we downgraded to 6.0.1.)

Copy link
Member

Choose a reason for hiding this comment

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

Yep, we have to lower this.

{
internal class TelemetryInstrumentation : ITelemetryInstrumentation
{

Copy link
Member

Choose a reason for hiding this comment

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

could remove this extra line.

@@ -36,6 +37,8 @@ public class JwtSecurityTokenHandler : SecurityTokenHandler
private static string _shortClaimType = _namespace + "/ShortTypeName";
private bool _mapInboundClaims = DefaultMapInboundClaims;

internal ITelemetryInstrumentation _telemetryClient = new TelemetryInstrumentation();
Copy link
Member

Choose a reason for hiding this comment

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

There is a naming oddity here.
Should ITelemetryInstrumentation be ITelemeteryClient?
Then TelemetryInstrumentation be TelemetryClient?

LogMessages.IDX20810,
result.ErrorMessage));

_telemetryClient.IncrementConfigurationRefreshRequestCounter(
Copy link
Member

Choose a reason for hiding this comment

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

This will be double counted as we report the same error in the catch.

@@ -311,6 +352,10 @@ public override void RequestRefresh()
{
DateTimeOffset now = DateTimeOffset.UtcNow;

_telemetryClient.IncrementConfigurationRefreshRequestCounter(
MetadataAddress,
TelemetryConstants.Protocols.Direct);
Copy link
Member

Choose a reason for hiding this comment

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

Using the name Protocols.Direct in a method called RequestRefresh is kind of confusing.

UpdateConfiguration(configuration);
}
catch (Exception ex)
{
fetchMetadataFailure = ex;
_telemetryClient.IncrementConfigurationRefreshRequestCounter(
MetadataAddress,
TelemetryConstants.Protocols.FirstRefresh,
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps this counter should be FirstAutomatic.

@@ -32,6 +32,10 @@
</None>
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' or '$(TargetFramework)' == 'netstandard2.0' ">
Copy link
Member

@brentschmaltz brentschmaltz Dec 21, 2024

Choose a reason for hiding this comment

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

This reference should be in the assembly where the types are used.
Currently this is M.IM.Tokens, which includes this reference, which allows the project to build.

I think the telemetry stuff should be in M.IM.Logging.

using System.Diagnostics;
using System.Diagnostics.Metrics;

namespace Microsoft.IdentityModel.Tokens.Telemetry
Copy link
Member

Choose a reason for hiding this comment

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

Curious why this we didn't put this in M.IM.Logging?


namespace Microsoft.IdentityModel.Tokens.Telemetry
{
internal interface ITelemetryInstrumentation
Copy link
Member

Choose a reason for hiding this comment

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

Since this is all internal, not seeing a strong reason for this interface.
How does it help?

Copy link
Member

@brentschmaltz brentschmaltz left a comment

Choose a reason for hiding this comment

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

Some naming.
Code should live in assembly where dependencies are included.
Why do we need an interface?

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

Successfully merging this pull request may close these issues.

Add metadata request time to client telemetry
7 participants