From 1174b6e386f015e86f56e3ffd71640d5372617eb Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Thu, 31 Jul 2025 16:56:48 -0700 Subject: [PATCH 1/2] Move to 'Azure.Identity' v1.14.2 and replace 'Microsoft.ApplicationInsights.WorkerService' with 'Microsoft.ApplicationInsights' --- .../Microsoft.Azure.Agent.csproj | 4 ++-- .../agents/Microsoft.Azure.Agent/Telemetry.cs | 24 ++++++------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/shell/agents/Microsoft.Azure.Agent/Microsoft.Azure.Agent.csproj b/shell/agents/Microsoft.Azure.Agent/Microsoft.Azure.Agent.csproj index 8f5e7d26..d264f12a 100644 --- a/shell/agents/Microsoft.Azure.Agent/Microsoft.Azure.Agent.csproj +++ b/shell/agents/Microsoft.Azure.Agent/Microsoft.Azure.Agent.csproj @@ -16,8 +16,8 @@ - - + + diff --git a/shell/agents/Microsoft.Azure.Agent/Telemetry.cs b/shell/agents/Microsoft.Azure.Agent/Telemetry.cs index d0b439d1..669537a7 100644 --- a/shell/agents/Microsoft.Azure.Agent/Telemetry.cs +++ b/shell/agents/Microsoft.Azure.Agent/Telemetry.cs @@ -1,8 +1,7 @@ using System.Text.Json; using Microsoft.ApplicationInsights; -using Microsoft.ApplicationInsights.WorkerService; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.ApplicationInsights.Extensibility; namespace Microsoft.Azure.Agent; @@ -198,21 +197,12 @@ internal class Telemetry private Telemetry() { - // Being a regular console app, there is no appsettings.json or configuration providers enabled by default. - // Hence connection string must be specified here. - IServiceCollection services = new ServiceCollection() - .AddApplicationInsightsTelemetryWorkerService((ApplicationInsightsServiceOptions options) => - { - // Application insights in the AME environment. - options.ConnectionString = "InstrumentationKey=7a75c4d0-ae0b-4a63-9fb3-b99271f79537"; - options.EnableHeartbeat = false; - options.EnableDiagnosticsTelemetryModule = false; - }); - - // Obtain TelemetryClient instance from DI, for additional manual tracking or to flush. - _telemetryClient = services - .BuildServiceProvider() - .GetRequiredService(); + // Create TelemetryConfiguration with connection string + var config = TelemetryConfiguration.CreateDefault(); + config.ConnectionString = "InstrumentationKey=7a75c4d0-ae0b-4a63-9fb3-b99271f79537"; + + // Create TelemetryClient with the configuration + _telemetryClient = new TelemetryClient(config); // Suppress the PII recorded by default to reduce risk. _telemetryClient.Context.Cloud.RoleInstance = "Not Available"; From aa82080f7cef52bb15d174dea0f5d38b143dc86e Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Thu, 31 Jul 2025 18:26:58 -0700 Subject: [PATCH 2/2] Update the comment --- shell/agents/Microsoft.Azure.Agent/Telemetry.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/agents/Microsoft.Azure.Agent/Telemetry.cs b/shell/agents/Microsoft.Azure.Agent/Telemetry.cs index 669537a7..9ce8087e 100644 --- a/shell/agents/Microsoft.Azure.Agent/Telemetry.cs +++ b/shell/agents/Microsoft.Azure.Agent/Telemetry.cs @@ -197,8 +197,8 @@ internal class Telemetry private Telemetry() { - // Create TelemetryConfiguration with connection string var config = TelemetryConfiguration.CreateDefault(); + // Application insights in the AME environment. config.ConnectionString = "InstrumentationKey=7a75c4d0-ae0b-4a63-9fb3-b99271f79537"; // Create TelemetryClient with the configuration