22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
44using System ;
5- using System . Diagnostics ;
5+ using Microsoft . ApplicationInsights ;
6+ using Microsoft . ApplicationInsights . DataContracts ;
67using Microsoft . ApplicationInsights . Extensibility ;
78using Microsoft . ApplicationInsights . Extensibility . Implementation ;
89using Microsoft . ApplicationInsights . Extensibility . Implementation . Tracing ;
@@ -32,21 +33,28 @@ private static void InitializeTelemetryConfiguration(string instrumentationKey,
3233 TelemetryConfiguration . Active . InstrumentationKey = instrumentationKey ;
3334 TelemetryConfiguration . Active . TelemetryInitializers . Add ( new TelemetryContextInitializer ( ) ) ;
3435
36+ // Construct a TelemetryClient to emit traces so we can track and debug AI initialization.
37+ var telemetryClient = new TelemetryClient ( ) ;
38+
3539 // Configure heartbeat interval if specified.
3640 // When not defined or null, the DiagnosticsTelemetryModule will use its internal defaults (heartbeat enabled, interval of 15 minutes).
3741 if ( heartbeatInterval . HasValue )
3842 {
39- var heartbeatManager = GetHeartbeatPropertyManager ( ) ;
43+ var heartbeatManager = GetHeartbeatPropertyManager ( telemetryClient ) ;
4044 if ( heartbeatManager != null )
4145 {
4246 heartbeatManager . HeartbeatInterval = heartbeatInterval . Value ;
4347
44- Trace . TraceInformation ( $ "Telemetry initialized using configured heartbeat interval: { heartbeatInterval . Value } .") ;
48+ telemetryClient . TrackTrace (
49+ $ "Telemetry initialized using configured heartbeat interval: { heartbeatInterval . Value } .",
50+ SeverityLevel . Information ) ;
4551 }
4652 }
4753 else
4854 {
49- Trace . TraceInformation ( $ "Telemetry initialized using default heartbeat interval.") ;
55+ telemetryClient . TrackTrace (
56+ "Telemetry initialized using default heartbeat interval." ,
57+ SeverityLevel . Information ) ;
5058 }
5159
5260 Initialized = true ;
@@ -57,7 +65,7 @@ private static void InitializeTelemetryConfiguration(string instrumentationKey,
5765 }
5866 }
5967
60- private static IHeartbeatPropertyManager GetHeartbeatPropertyManager ( )
68+ private static IHeartbeatPropertyManager GetHeartbeatPropertyManager ( TelemetryClient telemetryClient )
6169 {
6270 if ( HeartbeatManager == null )
6371 {
@@ -76,13 +84,15 @@ private static IHeartbeatPropertyManager GetHeartbeatPropertyManager()
7684 catch ( Exception hearbeatManagerAccessException )
7785 {
7886 // An non-critical, unexpected exception occurred trying to access the heartbeat manager.
79- Trace . TraceError ( $ "There was an error accessing heartbeat manager. Details: { hearbeatManagerAccessException . ToInvariantString ( ) } ") ;
87+ telemetryClient . TrackTrace (
88+ $ "There was an error accessing heartbeat manager. Details: { hearbeatManagerAccessException . ToInvariantString ( ) } ",
89+ SeverityLevel . Error ) ;
8090 }
8191
8292 if ( HeartbeatManager == null )
8393 {
8494 // Heartbeat manager unavailable: log warning.
85- Trace . TraceWarning ( "Heartbeat manager unavailable" ) ;
95+ telemetryClient . TrackTrace ( "Heartbeat manager unavailable" , SeverityLevel . Warning ) ;
8696 }
8797 }
8898
0 commit comments