public async Task PreHandleAsync(TestEvent @event, CancellationToken cancellationToken = default)
        {
            using var tx = _session.BeginTransaction();
            var process = await _session.GetAsync <TestProcessEntity>(CorrelationId, cancellationToken);

            process.EventTime = _clock.UtcNow;
            await _session.UpdateAsync(process, cancellationToken);

            await tx.CommitAsync(cancellationToken);

            _metricsService.Observe(new MultiStepBusinessProcessMetric("test_process", "event_received"), (process.EventTime - process.StartTime).TotalMilliseconds);
        }
        public async Task <TResult> ReceiveAsync <TResult>(IQuery <TResult> query, CancellationToken cancellationToken = default)
        {
            var stopWatch = new Stopwatch();

            _metrics.Increment(new RequestCounterMetric(query));
            _metrics.Increment(new RequestGaugeMetric("generic_request_gauge", "Current request count"));
            try {
                stopWatch.Start();
                var result = await _next.ReceiveAsync(query, cancellationToken);

                stopWatch.Stop();

                _metrics.Observe(new RequestDurationMetric(query), stopWatch.ElapsedMilliseconds);

                return(result);
            }
            catch (Exception exception) {
                stopWatch.Stop();
                _metrics.Increment(new RequestFailureMetric(query, exception));

                throw;
            }
            finally {
                _metrics.Decrement(new RequestGaugeMetric("generic_request_gauge", "Current request count"));
            }
        }
        public async Task ReceiveAsync <TCommand>(TCommand command, CancellationToken cancellationToken = default) where TCommand : ICommand
        {
            var stopWatch = new Stopwatch();

            _metrics.Increment(new RequestCounterMetric(command));
            _metrics.Increment(new RequestGaugeMetric("generic_request_gauge", "Current request count"));

            try {
                stopWatch.Start();
                await _next.ReceiveAsync(command, cancellationToken);

                stopWatch.Stop();

                _metrics.Observe(new RequestDurationMetric(command), stopWatch.ElapsedMilliseconds);
            }
            catch (Exception exception) {
                stopWatch.Stop();
                _metrics.Increment(new RequestFailureMetric(command, exception));

                throw;
            }
            finally {
                _metrics.Decrement(new RequestGaugeMetric("generic_request_gauge", "Current request count"));
            }
        }