using System.Diagnostics; using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.DataContracts; namespace PlanTempus.Components.Users.Create; public class CreateUserHandlerDecorator( ICommandHandler decoratedHandler, TelemetryClient telemetryClient) : ICommandHandler, ICommandHandlerDecorator { public async Task Handle(CreateUserCommand command) { // var correlationId = Activity.Current?.RootId ?? command.CorrelationId; using (var operation = telemetryClient.StartOperation($"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 { ["CommandType"] = nameof(CreateUserCommand) }); throw; } } } }