-
Notifications
You must be signed in to change notification settings - Fork 408
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
base: dev
Are you sure you want to change the base?
Conversation
src/Microsoft.IdentityModel.Logging/IdentityModelTelemetryUtil.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.IdentityModel.Protocols/Configuration/ConfigurationManager.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.IdentityModel.Protocols/Configuration/ConfigurationManager.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.IdentityModel.Protocols/Configuration/ConfigurationManager.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.IdentityModel.Protocols/Configuration/ConfigurationManager.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.IdentityModel.Protocols/Configuration/ConfigurationManager.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.IdentityModel.Logging/IdentityModelTelemetryUtil.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.IdentityModel.Logging/IdentityModelTelemetryUtil.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.IdentityModel.Protocols/Configuration/ConfigurationManager.cs
Outdated
Show resolved
Hide resolved
.../Microsoft.IdentityModel.Protocols.OpenIdConnect.Tests/ConfigurationManagerTelemetryTests.cs
Outdated
Show resolved
Hide resolved
.../Microsoft.IdentityModel.Protocols.OpenIdConnect.Tests/ConfigurationManagerTelemetryTests.cs
Show resolved
Hide resolved
src/Microsoft.IdentityModel.Protocols/Configuration/ConfigurationManager.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.IdentityModel.Logging/IdentityModelTelemetryUtil.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.ValidateToken.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.IdentityModel.Logging/ConfigurationManagerTelemetryInstrumentation.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.IdentityModel.Protocols/Configuration/ConfigurationManager.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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.
src/Microsoft.IdentityModel.Logging/TelemetryInstrumentation.cs
Outdated
Show resolved
Hide resolved
518df9f
to
5e917c9
Compare
Table identitymodelconfigurationmanager_counter Table identitymodelconfigurationrequesttotaldurationinms_histogram |
I can make a doc, good idea
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
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
Milliseconds was recommended to me and it matched other, similar code. I can change it if microseconds is preferred.
same as above, a different taglist is created that contains an exception. right now, unit tests prove that this portion is populated |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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 | ||
{ | ||
|
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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' "> |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this 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?
Addresses client telemetry repair item
Add counter for get configuration requests and histogram for total duration of the same requests.