PlanTempusApp/PlanTempus.Components/Users/Create/CreateUserHandlerDecorator.cs

41 lines
1.4 KiB
C#
Raw Normal View History

2025-03-11 00:28:06 +01:00
using System.Diagnostics;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
2025-03-10 15:56:22 +01:00
namespace PlanTempus.Components.Users.Create;
2025-03-11 00:28:06 +01:00
public class CreateUserHandlerDecorator(
ICommandHandler<CreateUserCommand, CreateUserResult> decoratedHandler,
TelemetryClient telemetryClient)
: ICommandHandler<CreateUserCommand, CreateUserResult>, ICommandHandlerDecorator
2025-03-10 15:56:22 +01:00
{
public async Task<CreateUserResult> Handle(CreateUserCommand command)
{
2025-03-11 00:28:06 +01:00
// var correlationId = Activity.Current?.RootId ?? command.CorrelationId;
using (var operation =
telemetryClient.StartOperation<RequestTelemetry>($"Handle {nameof(CreateUserCommand)}",
command.CorrelationId.ToString()))
{
try
{
operation.Telemetry.Properties["CorrelationId"] = command.CorrelationId.ToString();
var result = await decoratedHandler.Handle(command);
operation.Telemetry.Success = true;
return result;
}
catch (Exception ex)
{
operation.Telemetry.Success = false;
telemetryClient.TrackException(ex, new Dictionary<string, string>
{
["CommandType"] = nameof(CreateUserCommand)
});
throw;
}
}
2025-03-10 15:56:22 +01:00
}
2025-03-11 00:28:06 +01:00
}