Skip to content

Include ManagedIdentitySource in managed identity error messages and request-failure logs#6098

Closed
Robbie-Microsoft with Copilot wants to merge 2 commits into
mainfrom
copilot/add-managed-identity-source-error-messages
Closed

Include ManagedIdentitySource in managed identity error messages and request-failure logs#6098
Robbie-Microsoft with Copilot wants to merge 2 commits into
mainfrom
copilot/add-managed-identity-source-error-messages

Conversation

Copilot AI commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Managed identity auth failures surface a host-issued correlation ID, but neither the error message nor the request-failure log identified which managed identity source (AppService, Imds, ServiceFabric, etc.) produced it — making live-site triage ambiguous across host telemetry systems.

Changes proposed in this request

  • AbstractManagedIdentity.cs

    • Request-failure log line now includes _sourceType:
      [Managed Identity] request failed, Source: AppService, HttpStatusCode: 500 Error message: ...
      
    • Correlation ID message now attributes the ID to the specific host:
      Managed Identity Correlation ID: <id> (issued by the 'AppService' managed identity source; search that source's telemetry with this correlation ID). Use this Correlation ID for further investigation.
      
    • Source is taken from the existing _sourceType field — no hardcoding, reflects the host detected at runtime.
  • CHANGELOG.md — added ### Changes entry under the in-progress version.

Testing

  • Updated two [DataRow] entries in ManagedIdentityTestErrorResponseParsing to assert the new source attribution phrase appears in the error message for correlation-ID-bearing responses.
  • Added ManagedIdentityErrorMessageAttributesCorrelationIdToSourceAsync — parametrized over AppService and Imds sources — to guard the correlation-ID attribution branch against regression across non-AppService sources. Asserts the full composed phrase (not just the source name) to prevent false passes from echoed error bodies.

No behavioral or auth changes — message/log content only. No public API surface changes.

Performance impact

None — string interpolation on an already-allocated error path.

Documentation

  • All relevant documentation is updated.

Co-authored-by: juliovi-1 126522119+juliovi-1@users.noreply.github.com

Copilot AI requested review from Copilot and removed request for Copilot July 1, 2026 19:14
Copilot AI requested review from Copilot and removed request for Copilot July 1, 2026 19:17
Copilot AI changed the title [WIP] Add ManagedIdentitySource to managed identity error messages and request-failure logs Include ManagedIdentitySource in managed identity error messages and request-failure logs Jul 1, 2026
Copilot AI requested a review from Robbie-Microsoft July 1, 2026 19:18
@Robbie-Microsoft
Robbie-Microsoft marked this pull request as ready for review July 1, 2026 19:24
@Robbie-Microsoft
Robbie-Microsoft requested a review from a team as a code owner July 1, 2026 19:24
Copilot AI review requested due to automatic review settings July 1, 2026 19:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves managed identity failure diagnostics by including the detected ManagedIdentitySource (e.g., AppService, Imds) in both request-failure logs and correlation-ID-bearing error messages, making it easier to route the host-issued correlation ID to the correct telemetry system during incident triage.

Changes:

  • Added managed identity source information to the managed identity “request failed” log line.
  • Enhanced correlation-ID error message text to attribute the correlation ID to the detected managed identity source.
  • Updated/added unit tests to assert the new attribution text for both AppService and IMDS sources, and documented the change in the changelog.

Reviewed changes

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

File Description
tests/Microsoft.Identity.Test.Unit/ManagedIdentityTests/ManagedIdentityTests.cs Updates existing parsing assertions and adds a new parametrized regression test to validate correlation-ID attribution across MI sources.
src/client/Microsoft.Identity.Client/ManagedIdentity/AbstractManagedIdentity.cs Includes _sourceType in the failure log and in the correlation-ID error-message branch.
CHANGELOG.md Documents the diagnostic-message/log enhancement under the current version section.

@Robbie-Microsoft
Robbie-Microsoft enabled auto-merge (squash) July 1, 2026 19:46

@bgavrilMS bgavrilMS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doesn't preserve attribution.

@Robbie-Microsoft

Copy link
Copy Markdown
Contributor

Superseded by #6101, which carries @juliovi-1's original commits cherry-picked unchanged so he remains the git author (this PR rewrote the code and did not preserve authorship). Closing in favor of #6101.

auto-merge was automatically disabled July 1, 2026 20:43

Pull request was closed

@Robbie-Microsoft
Robbie-Microsoft deleted the copilot/add-managed-identity-source-error-messages branch July 1, 2026 20:46
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.

4 participants