Skip to content

Commit a1125f6

Browse files
authored
Move to 'Azure.Identity' v1.14.2 and refactor the telemetry library (#404)
Getting access token from Azure PowerShell fails with the error `"PowerShell did not return a valid response."`. This turns out to be an issue with the `Azure.Identity` library. After moving to the latest v1.14.2, it works again. However, moving `Azure.Identity` to v1.14.2 causes a dependency conflict with the `Microsoft.ApplicationInsights.WorkerService` package, so this change also refactors the telemetry code a bit to depend on the `Microsoft.ApplicationInsights` package instead, which is lightweight and much more appropriate for this application.
1 parent 5f9d0b8 commit a1125f6

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

shell/agents/Microsoft.Azure.Agent/Microsoft.Azure.Agent.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
</PropertyGroup>
1717

1818
<ItemGroup>
19-
<PackageReference Include="Azure.Identity" Version="1.11.4" />
20-
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
19+
<PackageReference Include="Azure.Identity" Version="1.14.2" />
20+
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.23.0" />
2121
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
2222
<PackageReference Include="Serilog.Sinks.Async" Version="2.0.0" />
2323
<PackageReference Include="System.Management.Automation" Version="7.4.7">

shell/agents/Microsoft.Azure.Agent/Telemetry.cs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using System.Text.Json;
22

33
using Microsoft.ApplicationInsights;
4-
using Microsoft.ApplicationInsights.WorkerService;
5-
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.ApplicationInsights.Extensibility;
65

76
namespace Microsoft.Azure.Agent;
87

@@ -198,21 +197,12 @@ internal class Telemetry
198197

199198
private Telemetry()
200199
{
201-
// Being a regular console app, there is no appsettings.json or configuration providers enabled by default.
202-
// Hence connection string must be specified here.
203-
IServiceCollection services = new ServiceCollection()
204-
.AddApplicationInsightsTelemetryWorkerService((ApplicationInsightsServiceOptions options) =>
205-
{
206-
// Application insights in the AME environment.
207-
options.ConnectionString = "InstrumentationKey=7a75c4d0-ae0b-4a63-9fb3-b99271f79537";
208-
options.EnableHeartbeat = false;
209-
options.EnableDiagnosticsTelemetryModule = false;
210-
});
211-
212-
// Obtain TelemetryClient instance from DI, for additional manual tracking or to flush.
213-
_telemetryClient = services
214-
.BuildServiceProvider()
215-
.GetRequiredService<TelemetryClient>();
200+
var config = TelemetryConfiguration.CreateDefault();
201+
// Application insights in the AME environment.
202+
config.ConnectionString = "InstrumentationKey=7a75c4d0-ae0b-4a63-9fb3-b99271f79537";
203+
204+
// Create TelemetryClient with the configuration
205+
_telemetryClient = new TelemetryClient(config);
216206

217207
// Suppress the PII recorded by default to reduce risk.
218208
_telemetryClient.Context.Cloud.RoleInstance = "Not Available";

0 commit comments

Comments
 (0)