public async Task HandleAsync(TEvent @event)
        {
            if (!_trackingSampler.DoWork())
            {
                await _handler.HandleAsync(@event);

                return;
            }

            using var scope = _withTracing ? BuildScope(@event.GetEventName()) : null;

            _qoSViolateChecker.Run();

            try
            {
                await _handler.HandleAsync(@event);
            }
            catch (Exception exception)
            {
                switch (exception)
                {
                case AppException _:
                    _qoSViolateRaiser.Raise(ViolationType.AmongServicesInconsistency);
                    break;
                }
                throw;
            }

            await _qoSViolateChecker.Analyze();
        }
        public Task Execute(IJobExecutionContext context)
        {
            var currentDate       = _dateTimeProvider.Now();
            var pendingOperations = _pendingOperationsService.GetAll();

            foreach (var(id, (operationName, startOperationTime)) in pendingOperations)
            {
                if (DidHandlingRequestOvertime(currentDate, startOperationTime))
                {
                    _logger.LogWarning($"Request with Id {id} and name {operationName} still is not full handled.");
                    _qoSViolateRaiser.Raise(ViolationType.NotFullyHandledOperation);
                    _overtimeOperations.Add(id);
                }
            }

            if (_overtimeOperations.Any())
            {
                foreach (var operationId in _overtimeOperations)
                {
                    pendingOperations.Remove(operationId);
                }
                _overtimeOperations.Clear();
            }

            return(Task.CompletedTask);
        }
        private bool RaiseTimeQoSViolationIfNeeded(long handlingTime, long requiredHandlingTime)
        {
            var shouldRaise = ShouldRaiseTimeViolation(handlingTime, requiredHandlingTime);

            if (shouldRaise)
            {
                _qoSViolateRaiser.Raise(ViolationType.HandlerTimeExceeded);
            }
            return(shouldRaise);
        }