2025-02-22 20:14:56 +01:00
|
|
|
|
using Microsoft.ApplicationInsights;
|
|
|
|
|
|
using Microsoft.ApplicationInsights.Channel;
|
|
|
|
|
|
|
|
|
|
|
|
namespace PlanTempus.Core.Telemetry
|
|
|
|
|
|
{
|
2025-03-07 16:17:30 +01:00
|
|
|
|
public class SeqTelemetryChannel(IMessageChannel<ITelemetry> messageChannel, TelemetryClient telemetryClient)
|
|
|
|
|
|
: InMemoryChannel, ITelemetryChannel
|
2025-02-22 20:14:56 +01:00
|
|
|
|
{
|
|
|
|
|
|
public new void Send(ITelemetry telemetry)
|
|
|
|
|
|
{
|
2025-03-07 16:17:30 +01:00
|
|
|
|
if (telemetry.Context.GlobalProperties.TryGetValue("OmitSeqTelemetryChannel", out var value))
|
2025-02-27 17:41:21 +01:00
|
|
|
|
if (value == "true")
|
2025-02-22 20:14:56 +01:00
|
|
|
|
{
|
2025-02-27 17:41:21 +01:00
|
|
|
|
base.Send(telemetry);
|
|
|
|
|
|
return;
|
2025-02-22 20:14:56 +01:00
|
|
|
|
}
|
2025-02-27 17:41:21 +01:00
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2025-03-07 16:17:30 +01:00
|
|
|
|
var writeTask = messageChannel.Writer.WriteAsync(telemetry).AsTask();
|
2025-02-27 17:41:21 +01:00
|
|
|
|
writeTask.ContinueWith(t =>
|
2025-02-22 20:14:56 +01:00
|
|
|
|
{
|
2025-02-27 17:41:21 +01:00
|
|
|
|
if (t.Exception != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw t.Exception;
|
|
|
|
|
|
}
|
|
|
|
|
|
}, TaskContinuationOptions.OnlyOnFaulted);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
2025-03-07 16:17:30 +01:00
|
|
|
|
telemetryClient.TrackException(e,
|
|
|
|
|
|
new Dictionary<string, string> { { "OmitSeqTelemetryChannel", "true" } });
|
2025-02-27 17:41:21 +01:00
|
|
|
|
}
|
2025-03-07 16:17:30 +01:00
|
|
|
|
|
2025-02-22 20:14:56 +01:00
|
|
|
|
base.Send(telemetry);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-07 16:17:30 +01:00
|
|
|
|
}
|