|
1 | 1 | using System.Text.Json;
|
2 | 2 |
|
3 | 3 | using Microsoft.ApplicationInsights;
|
4 |
| -using Microsoft.ApplicationInsights.WorkerService; |
5 |
| -using Microsoft.Extensions.DependencyInjection; |
| 4 | +using Microsoft.ApplicationInsights.Extensibility; |
6 | 5 |
|
7 | 6 | namespace Microsoft.Azure.Agent;
|
8 | 7 |
|
@@ -198,21 +197,12 @@ internal class Telemetry
|
198 | 197 |
|
199 | 198 | private Telemetry()
|
200 | 199 | {
|
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); |
216 | 206 |
|
217 | 207 | // Suppress the PII recorded by default to reduce risk.
|
218 | 208 | _telemetryClient.Context.Cloud.RoleInstance = "Not Available";
|
|
0 commit comments