Skip to content

Commit adfe00d

Browse files
committed
Update tracking exception and call Flush when shutting down
1 parent 49a9885 commit adfe00d

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public void Dispose()
8383
_httpClient.Dispose();
8484

8585
Log.CloseAndFlush();
86+
Telemetry.CloseAndFlush();
8687
}
8788

8889
public void Initialize(AgentConfig config)

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)