Skip to content

Commit 2d363f2

Browse files
authored
Merge pull request #24377 from abpframework/salihozkara/telemetry
Ensure telemetry tasks complete on process exit
2 parents e503018 + e886d4a commit 2d363f2

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/TelemetryService.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public async Task AddErrorForActivityAsync(string failingActivity, string errorM
6767

6868
private Task AddActivityAsync(ActivityContext context)
6969
{
70-
_ = Task.Run(async () =>
70+
var telemetryTask = Task.Run(async () =>
7171
{
7272
using var scope = _serviceScopeFactory.CreateScope();
7373

@@ -81,6 +81,30 @@ await BuildAndSendActivityAsync(context,
8181
telemetryActivitySender);
8282
});
8383

84+
AppDomain.CurrentDomain.ProcessExit += (_, _) =>
85+
{
86+
try
87+
{
88+
telemetryTask.Wait(TimeSpan.FromSeconds(10));
89+
}
90+
catch
91+
{
92+
// ignored
93+
}
94+
};
95+
96+
Console.CancelKeyPress += (_, _) =>
97+
{
98+
try
99+
{
100+
telemetryTask.Wait(TimeSpan.FromSeconds(10));
101+
}
102+
catch
103+
{
104+
// ignored
105+
}
106+
};
107+
84108
return Task.CompletedTask;
85109
}
86110

0 commit comments

Comments
 (0)