@@ -163,9 +163,9 @@ private Telemetry()
163163 _telemetryClient . Context . Cloud . RoleInstance = "Not Available" ;
164164 }
165165
166- private void LogTelemetry ( AzTrace trace , Exception e = null )
166+ private void LogTelemetry ( AzTrace trace , Exception exception )
167167 {
168- Dictionary < string , string > telemetryEvent = new ( )
168+ Dictionary < string , string > properties = new ( )
169169 {
170170 [ "QueryId" ] = trace . QueryId ,
171171 [ "ConversationId" ] = trace . ConversationId ,
@@ -176,8 +176,18 @@ private void LogTelemetry(AzTrace trace, Exception e = null)
176176 [ "Details" ] = GetDetailedMessage ( trace . Details ) ,
177177 } ;
178178
179- _telemetryClient . TrackTrace ( "AIShell" , telemetryEvent ) ;
180- if ( e != null ) { _telemetryClient . TrackException ( e ) ; }
179+ if ( exception is null )
180+ {
181+ _telemetryClient . TrackTrace ( "AIShell" , properties ) ;
182+ }
183+ else
184+ {
185+ _telemetryClient . TrackException ( exception , properties ) ;
186+ }
187+ }
188+
189+ private void Flush ( )
190+ {
181191 _telemetryClient . Flush ( ) ;
182192 }
183193
@@ -216,13 +226,19 @@ internal static void Initialize()
216226
217227 /// <summary>
218228 /// Trace a telemetry metric.
219- /// The method does nothing when it's disabled.
229+ /// The method does nothing when telemetry is disabled.
220230 /// </summary>
221- internal static void Trace ( AzTrace trace ) => s_singleton ? . LogTelemetry ( trace ) ;
231+ internal static void Trace ( AzTrace trace ) => s_singleton ? . LogTelemetry ( trace , exception : null ) ;
222232
223233 /// <summary>
224234 /// Trace a telemetry metric and an Exception with it.
225- /// The method does nothing when it's disabled.
235+ /// The method does nothing when telemetry is disabled.
236+ /// </summary>
237+ internal static void Trace ( AzTrace trace , Exception exception ) => s_singleton ? . LogTelemetry ( trace , exception ) ;
238+
239+ /// <summary>
240+ /// Flush and close the telemetry.
241+ /// The method does nothing when telemetry is disabled.
226242 /// </summary>
227- internal static void Trace ( AzTrace trace , Exception e ) => s_singleton ? . LogTelemetry ( trace , e ) ;
243+ internal static void CloseAndFlush ( ) => s_singleton ? . Flush ( ) ;
228244}
0 commit comments