public async Task InvokeAsync(HttpContext context, RequestDelegate next) { _metricsService.BeginRequest(context); var stopwatch = new Stopwatch(); stopwatch.Start(); await next(context); stopwatch.Stop(); _metricsService.EndRequest(context, stopwatch.Elapsed); }