-
Notifications
You must be signed in to change notification settings - Fork 432
Use domain name only for telemetry metadata addresses to reduce OpenTelemetry cardinality #3327
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
Copilot
wants to merge
16
commits into
dev
Choose a base branch
from
copilot/fix-d17fdc27-51d2-412f-bc68-4eb999a2a2e3
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e94fddc
Initial plan
Copilot 01a7ffd
Add telemetry domain extraction feature with AppContext switch
Copilot 8d87397
Complete telemetry domain extraction feature implementation with tests
Copilot 4827171
internal method, no reflection in tests
westin-m e36a9b9
remove unnecessary operation
westin-m eee75f3
Fix AppContext switch test interference with ResetAppContextSwitches …
Copilot cb3550b
Merge branch 'dev' into copilot/fix-d17fdc27-51d2-412f-bc68-4eb999a2a2e3
keegan-caruso 621e684
Merge branch 'dev' into copilot/fix-d17fdc27-51d2-412f-bc68-4eb999a2a2e3
keegan-caruso 27828de
avoid tast failures causes by app context switch interference
westin-m 53eab11
Merge branch 'copilot/fix-d17fdc27-51d2-412f-bc68-4eb999a2a2e3' of ht…
westin-m 654c2c7
Merge branch 'dev' into copilot/fix-d17fdc27-51d2-412f-bc68-4eb999a2a2e3
keegan-caruso 1e001b6
Merge branch 'dev' into copilot/fix-d17fdc27-51d2-412f-bc68-4eb999a2a2e3
westin-m 6ee064d
Merge branch 'copilot/fix-d17fdc27-51d2-412f-bc68-4eb999a2a2e3' of ht…
westin-m 6c190a8
pr feedback
westin-m ceeeb25
Merge branch 'dev' into copilot/fix-d17fdc27-51d2-412f-bc68-4eb999a2a2e3
westin-m 65ae428
Merge branch 'dev' into copilot/fix-d17fdc27-51d2-412f-bc68-4eb999a2a2e3
westin-m File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
test/Microsoft.IdentityModel.Tokens.Tests/Telemetry/TelemetryClientDomainExtractionTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using Microsoft.IdentityModel.TestUtils; | ||
| using Microsoft.IdentityModel.Tokens; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.IdentityModel.Telemetry.Tests; | ||
|
|
||
| [ResetAppContextSwitches] | ||
| [Collection("AppContextSwitches")] | ||
| public class TelemetryClientDomainExtractionTests | ||
| { | ||
| [Theory] | ||
| [InlineData("https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration", "login.microsoftonline.com")] | ||
| [InlineData("https://www.login.microsoftonline.com/common/v2.0/.well-known/openid-configuration", "www.login.microsoftonline.com")] | ||
| [InlineData("https://accounts.google.com/.well-known/openid-configuration", "accounts.google.com")] | ||
| [InlineData("https://login.windows.net/common/.well-known/openid-configuration", "login.windows.net")] | ||
| [InlineData("http://localhost:8080/.well-known/openid-configuration", "localhost")] | ||
| [InlineData("https://example.com/path/to/config", "example.com")] | ||
| [InlineData("https://subdomain.example.org/config.json", "subdomain.example.org")] | ||
| public void GetMetadataAddressForTelemetry_SuccessCase_ReturnsExpectedDomain(string fullAddress, string expectedDomain) | ||
| { | ||
| // Act | ||
| var result = TelemetryClient.GetMetadataAddressForTelemetry(fullAddress, true); | ||
|
|
||
| // Assert | ||
| Assert.Equal(expectedDomain, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DebugAppContextSwitch() | ||
| { | ||
| // Check if the AppContext switch is causing issues | ||
| var switchValue = AppContextSwitches.UseFullMetadataAddressForTelemetry; | ||
|
|
||
| var testUrl = "https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration"; | ||
| var result = TelemetryClient.GetMetadataAddressForTelemetry(testUrl); | ||
|
|
||
| // The switch should be false by default, so we should get the host name | ||
| Assert.False(switchValue, $"Switch value: {switchValue}"); | ||
| Assert.Equal("login.microsoftonline.com", result); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration")] | ||
| [InlineData("https://accounts.google.com/.well-known/openid-configuration")] | ||
| [InlineData("https://login.windows.net/common/.well-known/openid-configuration")] | ||
| public void GetMetadataAddressForTelemetry_ErrorCase_ReturnsFullAddress(string fullAddress) | ||
| { | ||
| // Act | ||
| var result = TelemetryClient.GetMetadataAddressForTelemetry(fullAddress, false); | ||
|
|
||
| // Assert | ||
| Assert.Equal(fullAddress, result); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("invalid-url")] | ||
| [InlineData("")] | ||
| [InlineData(null)] | ||
| public void GetMetadataAddressForTelemetry_InvalidUrl_ReturnsOriginalString(string invalidUrl) | ||
| { | ||
| // Act | ||
| var result = TelemetryClient.GetMetadataAddressForTelemetry(invalidUrl, true); | ||
|
|
||
| // Assert | ||
| Assert.Equal(invalidUrl, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetMetadataAddressForTelemetry_WithAppContextSwitch_ReturnsFullAddress() | ||
| { | ||
| // Arrange | ||
| var fullAddress = "https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration"; | ||
|
|
||
| try | ||
| { | ||
| // Enable the switch to use full metadata address | ||
| AppContext.SetSwitch(AppContextSwitches.UseFullMetadataAddressForTelemetrySwitch, true); | ||
|
|
||
| // Act | ||
| var result = TelemetryClient.GetMetadataAddressForTelemetry(fullAddress, true); | ||
|
|
||
| // Assert | ||
| Assert.Equal(fullAddress, result); | ||
| } | ||
| finally | ||
| { | ||
| // Cleanup is handled by ResetAppContextSwitches attribute | ||
| AppContext.SetSwitch(AppContextSwitches.UseFullMetadataAddressForTelemetrySwitch, false); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TelemetryClient_Methods_DoNotThrow() | ||
| { | ||
| // This test ensures that the modified telemetry methods don't break existing functionality | ||
| // We cannot easily verify the exact values sent to the telemetry system without complex setup, | ||
| // but we can ensure the methods don't throw exceptions when called with valid parameters. | ||
|
|
||
| // Arrange | ||
| var telemetryClient = new TelemetryClient(); | ||
| var testAddress = "https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration"; | ||
| var testDuration = TimeSpan.FromMilliseconds(100); | ||
| var testException = new InvalidOperationException("Test exception"); | ||
|
|
||
| // Act & Assert - these should not throw | ||
| var ex1 = Record.Exception(() => telemetryClient.LogConfigurationRetrievalDuration(testAddress, "Retriever", testDuration)); | ||
| var ex2 = Record.Exception(() => telemetryClient.LogConfigurationRetrievalDuration(testAddress, "Retriever", testDuration, testException)); | ||
| var ex3 = Record.Exception(() => telemetryClient.IncrementConfigurationRefreshRequestCounter(testAddress, "FirstRefresh", "Retriever")); | ||
| var ex4 = Record.Exception(() => telemetryClient.IncrementConfigurationRefreshRequestCounter(testAddress, "ConfigurationRetrievalFailed", "Retriever", testException)); | ||
| var ex5 = Record.Exception(() => telemetryClient.LogBackgroundConfigurationRefreshFailure(testAddress, "Retriever", testException)); | ||
|
|
||
| Assert.Null(ex1); | ||
| Assert.Null(ex2); | ||
| Assert.Null(ex3); | ||
| Assert.Null(ex4); | ||
| Assert.Null(ex5); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TelemetryClient_WithAppContextSwitch_DoesNotThrow() | ||
| { | ||
| // Test that telemetry methods work correctly when the backward compatibility switch is enabled | ||
| try | ||
| { | ||
| // Enable the switch to use full metadata address | ||
| AppContext.SetSwitch(AppContextSwitches.UseFullMetadataAddressForTelemetrySwitch, true); | ||
|
|
||
| // Arrange | ||
| var telemetryClient = new TelemetryClient(); | ||
| var testAddress = "https://accounts.google.com/.well-known/openid-configuration"; | ||
| var testDuration = TimeSpan.FromMilliseconds(150); | ||
| var testException = new InvalidOperationException("Test exception"); | ||
|
|
||
| // Act & Assert - these should not throw even with the switch enabled | ||
| var ex1 = Record.Exception(() => telemetryClient.LogConfigurationRetrievalDuration(testAddress, "Retriever", testDuration)); | ||
| var ex2 = Record.Exception(() => telemetryClient.LogConfigurationRetrievalDuration(testAddress, "Retriever", testDuration, testException)); | ||
| var ex3 = Record.Exception(() => telemetryClient.IncrementConfigurationRefreshRequestCounter(testAddress, "FirstRefresh", "Retriever")); | ||
| var ex4 = Record.Exception(() => telemetryClient.IncrementConfigurationRefreshRequestCounter(testAddress, "ConfigurationRetrievalFailed", "Retriever", testException)); | ||
| var ex5 = Record.Exception(() => telemetryClient.LogBackgroundConfigurationRefreshFailure(testAddress, "Retriever", testException)); | ||
|
|
||
| Assert.Null(ex1); | ||
| Assert.Null(ex2); | ||
| Assert.Null(ex3); | ||
| Assert.Null(ex4); | ||
| Assert.Null(ex5); | ||
| } | ||
| finally | ||
| { | ||
| // Cleanup | ||
| AppContext.SetSwitch(AppContextSwitches.UseFullMetadataAddressForTelemetrySwitch, false); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 test kept failing when ran alongside the new ones introduced by this PR. Putting them in the same collection was the most minimal and only effective solution I found.