Skip to content

Handle telemetry MAC lookup failures when network interfaces are unavailable#54334

Merged
marcpopMSFT merged 3 commits into
mainfrom
copilot/fix-cli-telemetry-networkexception
May 27, 2026
Merged

Handle telemetry MAC lookup failures when network interfaces are unavailable#54334
marcpopMSFT merged 3 commits into
mainfrom
copilot/fix-cli-telemetry-networkexception

Conversation

Copilot AI commented May 15, 2026

Copy link
Copy Markdown
Contributor

CLI startup could fail in telemetry initialization when MAC address retrieval falls back to NetworkInterface.GetAllNetworkInterfaces() on systems where netlink sockets are unavailable. In that environment, NetworkInformationException escaped and crashed commands like dotnet --version.

  • Telemetry machine ID fallback hardening

    • Updated TelemetryCommonProperties.GetMachineId() to catch NetworkInformationException from MAC lookup and fall back to a generated GUID instead of allowing process-terminating initialization failure.
    • This keeps telemetry best-effort while preserving CLI command execution in constrained environments.
  • Targeted regression coverage

    • Added a telemetry test that injects a NetworkInformationException from getMACAddress and verifies both machine ID fields continue to be produced as GUIDs via fallback behavior.
private string GetMachineId()
{
    try
    {
        return _getMACAddress() is { } macAddress ? _hasher(macAddress) : Guid.NewGuid().ToString();
    }
    catch (NetworkInformationException)
    {
        return Guid.NewGuid().ToString();
    }
}

Copilot AI and others added 2 commits May 15, 2026 22:21
Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/a339264f-6100-49f9-ab2d-c8a18347e069

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/a339264f-6100-49f9-ab2d-c8a18347e069

Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix cli telemetry results in NetworkInformationException Handle telemetry MAC lookup failures when network interfaces are unavailable May 15, 2026
Copilot AI requested a review from marcpopMSFT May 15, 2026 22:23
@marcpopMSFT marcpopMSFT marked this pull request as ready for review May 19, 2026 18:49
@marcpopMSFT marcpopMSFT requested review from Copilot and nagilson May 19, 2026 18:49
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

This PR has been labeled with Area-Telemetry. Please ensure that any telemetry changes in this PR

@marcpopMSFT

Copy link
Copy Markdown
Member

Fix looks reasonable to me. We already have fallback logic. This just explicitly catches the network exception and uses the same fallback logic to produce an ID.

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 hardens CLI telemetry initialization so MAC address lookup failures from unavailable network interfaces do not crash CLI startup. It keeps machine ID telemetry best-effort by falling back to generated GUIDs.

Changes:

  • Catches NetworkInformationException during telemetry machine ID generation.
  • Adds regression coverage for MAC lookup throwing NetworkInformationException.

Reviewed changes

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

File Description
src/Cli/dotnet/Telemetry/TelemetryCommonProperties.cs Adds fallback handling for network information failures during machine ID generation.
test/dotnet.Tests/TelemetryTests/TelemetryCommonPropertiesTests.cs Adds a targeted test validating GUID fallback behavior when MAC lookup throws.

@marcpopMSFT marcpopMSFT enabled auto-merge May 27, 2026 18:36
@marcpopMSFT marcpopMSFT merged commit adfd247 into main May 27, 2026
25 checks passed
@marcpopMSFT marcpopMSFT deleted the copilot/fix-cli-telemetry-networkexception branch May 27, 2026 18:40
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone May 28, 2026
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.

cli telemetry results in NetworkInformationException when netlink sockets aren't available.

4 participants