Skip to content

Move to 'Azure.Identity' v1.14.2 and refactor the telemetry library #404

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

Merged
merged 2 commits into from
Aug 1, 2025

Conversation

daxian-dbw
Copy link
Member

@daxian-dbw daxian-dbw commented Aug 1, 2025

PR Summary

Fix #393

I can reproduce this issue on macOS with the error from AzurePowerShellCredential() being "PowerShell did not return a valid response." This turns out to be an issue with the Azure.Identity library (Azure/azure-sdk-for-net#50578). After moving to the latest 1.14.2 of the package, it works for me on macOS.


However, moving to the 1.14.2 of the Azure.Identity caused a dependency conflict with the Microsoft.ApplicationInsights.WorkerService package, which brings in an older version of Microsoft.Extensions.DependencyInjection that conflicts with the newer version of Microsoft.Extensions.DependencyInjection.Abstractions that comes with Azure.Identity.

In fact, we should not depend on Microsoft.ApplicationInsights.WorkerService, but instead should use Microsoft.ApplicationInsights directly. The WorkerService package was designed for ASP.NET Core applications that need automatic dependency injection, performance counters, and various auto-collectors. For a simple console application that just needs to send traces and exceptions to Application Insights, the core Microsoft.ApplicationInsights package is perfect and much more appropriate.

What were changed: (summarized by GitHub Copilot)

  • Replaced Microsoft.ApplicationInsights.WorkerService with just Microsoft.ApplicationInsights
  • Simplified the telemetry initialization from a complex DI setup to a simple direct instantiation
  • Used modern TelemetryConfiguration.CreateDefault() with connection string instead of deprecated approaches

Benefits of the change: (summarized by GitHub Copilot)

  • Dramatically reduced dependencies - We went from 67+ transitive packages to about 25
  • Eliminated version conflicts - No more conflicting DI framework versions
  • Simpler code - The constructor is now much cleaner and easier to understand
  • Faster build times - Fewer packages to restore and compile
  • Smaller deployment - Much lighter runtime footprint
  • Same functionality - You still get exactly the same telemetry capabilities

…sights.WorkerService' with 'Microsoft.ApplicationInsights'
@daxian-dbw daxian-dbw requested a review from Copilot August 1, 2025 00:32
Copy link

@Copilot Copilot AI left a comment

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 addresses a macOS authentication issue by upgrading Azure.Identity to v1.14.2 and refactors the Application Insights telemetry implementation to resolve dependency conflicts.

  • Upgrades Azure.Identity from v1.11.4 to v1.14.2 to fix AzurePowerShellCredential authentication issues on macOS
  • Replaces Microsoft.ApplicationInsights.WorkerService with the core Microsoft.ApplicationInsights package to eliminate dependency conflicts
  • Simplifies telemetry initialization by removing complex DI setup in favor of direct TelemetryClient instantiation

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
Microsoft.Azure.Agent.csproj Updates package references to Azure.Identity v1.14.2 and Microsoft.ApplicationInsights v2.23.0
Telemetry.cs Refactors telemetry initialization to use direct instantiation instead of dependency injection framework

Copy link
Collaborator

@isra-fel isra-fel left a comment

Choose a reason for hiding this comment

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

LGTM thanks!

@daxian-dbw daxian-dbw merged commit a1125f6 into PowerShell:main Aug 1, 2025
4 checks passed
@daxian-dbw daxian-dbw deleted the csproj branch August 1, 2025 05:09
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.

Azure Agent Unable to Find Access Token For Azure PowerShell
2 participants