Add MSAL.NET telemetry enrichment#6071
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a per-request extensibility hook (WithOtelTagsEnricher) that lets callers enrich MSAL’s existing OpenTelemetry metrics with additional tags, while also surfacing an ExecutionResult to the enricher for success/failure context.
Changes:
- Introduces a new public fluent API
WithOtelTagsEnricher(...)and plumbs the delegate through request parameters. - Extends OpenTelemetry instrumentation plumbing to pass
ExecutionResult+ enricher into success/failure metric recording paths (foreground + proactive background refresh). - Adds unit tests validating tag enrichment on success/failure and resilience when the enricher throws.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/Microsoft.Identity.Test.Unit/TelemetryTests/OTelInstrumentationTests.cs | Adds coverage for success/failure enrichment and enricher-throws behavior. |
| src/client/Microsoft.Identity.Client/TelemetryCore/OpenTelemetry/IOtelInstrumentation.cs | Extends internal OTel interface to accept ExecutionResult and tag enricher. |
| src/client/Microsoft.Identity.Client/TelemetryCore/OpenTelemetry/NullOtelInstrumentation.cs | Updates no-op instrumentation implementation to match new OTel signatures. |
| src/client/Microsoft.Identity.Client/Platforms/Features/OpenTelemetry/OtelInstrumentation.cs | Implements tag enrichment by applying caller-provided tags during metric recording. |
| src/client/Microsoft.Identity.Client/Internal/Requests/RequestBase.cs | Creates/passes ExecutionResult + enricher into OTel success/failure telemetry. |
| src/client/Microsoft.Identity.Client/Internal/Requests/SilentRequestHelper.cs | Propagates enricher into proactive refresh telemetry (success + failure). |
| src/client/Microsoft.Identity.Client/Internal/Requests/Silent/CacheSilentStrategy.cs | Passes enricher into background refresh helper. |
| src/client/Microsoft.Identity.Client/Internal/Requests/OnBehalfOfRequest.cs | Passes enricher into background refresh helper. |
| src/client/Microsoft.Identity.Client/Internal/Requests/ManagedIdentityAuthRequest.cs | Passes enricher into background refresh helper. |
| src/client/Microsoft.Identity.Client/Internal/Requests/ClientCredentialRequest.cs | Passes enricher into background refresh helper. |
| src/client/Microsoft.Identity.Client/Internal/Requests/AuthenticationRequestParameters.cs | Exposes the configured enricher from common parameters. |
| src/client/Microsoft.Identity.Client/ApiConfig/Parameters/AcquireTokenCommonParameters.cs | Stores the enricher delegate on common request parameters. |
| src/client/Microsoft.Identity.Client/Extensibility/AbstractConfidentialClientAcquireTokenParameterBuilderExtension.cs | Adds the new public WithOtelTagsEnricher(...) extension method. |
| src/client/Microsoft.Identity.Client/PublicApi/netstandard2.0/PublicAPI.Unshipped.txt | Declares the new public API surface for netstandard2.0. |
| src/client/Microsoft.Identity.Client/PublicApi/net8.0/PublicAPI.Unshipped.txt | Declares the new public API surface for net8.0. |
| src/client/Microsoft.Identity.Client/PublicApi/net8.0-ios/PublicAPI.Unshipped.txt | Declares the new public API surface for net8.0-ios. |
| src/client/Microsoft.Identity.Client/PublicApi/net8.0-android/PublicAPI.Unshipped.txt | Declares the new public API surface for net8.0-android. |
| src/client/Microsoft.Identity.Client/PublicApi/net472/PublicAPI.Unshipped.txt | Declares the new public API surface for net472. |
| src/client/Microsoft.Identity.Client/PublicApi/net462/PublicAPI.Unshipped.txt | Declares the new public API surface for net462. |
bgavrilMS
approved these changes
Jun 18, 2026
neha-bhargava
approved these changes
Jun 18, 2026
neha-bhargava
approved these changes
Jun 18, 2026
neha-bhargava
left a comment
Contributor
There was a problem hiding this comment.
Looks good. Thanks for your contributions!
…b.com/AzureAD/microsoft-authentication-library-for-dotnet into ssmelov/add_msal_telemetry_enrichment
bgavrilMS
approved these changes
Jun 18, 2026
This was referenced Jun 24, 2026
Closed
Open
Open
Closed
This was referenced Jul 1, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR proposes an extensibility mechanism to enrich existing MSAL OpenTelemetry metrics with additional dimensions, without changing or replacing MSAL’s canonical metric set.