public void Int_Right_WithSlash(uint id) // ID - can't be less 0
        {
            var pathString = $"/path/to/{id}/";

            var options = new HttpRequestDurationsOptions {
                CustomNormalizePath = new Dictionary <Regex, string> {
                    { _intRegex, _intValue }
                }
            };

            var path = NormalizePath.Execute(pathString, options);

            Assert.Equal($"/path/to/id/", path);
        }
        public void Guid_Right_WithSlash(string guid)
        {
            var pathString = $"/path/to/{guid}/";

            var options = new HttpRequestDurationsOptions {
                CustomNormalizePath = new Dictionary <Regex, string> {
                    { _guidRegex, _guidValue }
                }
            };

            var path = NormalizePath.Execute(pathString, options);

            Assert.Equal($"/path/to/guid/", path);
        }
        public void Int_Center(uint id)
        {
            var pathString = $"/path/to/{id}/next";

            var options = new HttpRequestDurationsOptions {
                CustomNormalizePath = new Dictionary <Regex, string> {
                    { _intRegex, _intValue }
                }
            };

            var path = NormalizePath.Execute(pathString, options);

            Assert.Equal($"/path/to/id/next", path);
        }
        public async Task Invoke(HttpContext context)
        {
            var path = string.Empty;

#if HasRoutes
            // If we are going to set labels for Controller or Action -- then we need to make them readily available
            if (_options.IncludeController || _options.IncludeAction)
            {
                TryCaptureRouteData(context);
            }

            if (_options.UseRouteName)
            {
                path = context.GetRouteName();
            }
#endif
            if (string.IsNullOrEmpty(path))
            {
                path = context.Request.Path.ToString();
            }

            path = NormalizePath.Execute(path, _options);

            if (_options.IgnoreRoutesStartWith != null && _options.IgnoreRoutesStartWith.Any(i => path.StartsWith(i)))
            {
                await _next.Invoke(context);

                return;
            }

            if (_options.IgnoreRoutesContains != null && _options.IgnoreRoutesContains.Any(i => path.Contains(i)))
            {
                await _next.Invoke(context);

                return;
            }

            if (_options.IgnoreRoutesConcrete != null && _options.IgnoreRoutesConcrete.Any(i => path == i))
            {
                await _next.Invoke(context);

                return;
            }

            if (_options.ShouldMeasureRequest != null && !_options.ShouldMeasureRequest(context.Request))
            {
                await _next.Invoke(context);

                return;
            }

            string statusCode = null;
            var    method     = context.Request.Method;

            var controller = string.Empty;
            var action     = string.Empty;

#if HasRoutes
            controller = context.GetControllerName();
            action     = context.GetActionName();
#endif

            var ts = Stopwatch.GetTimestamp();

            try
            {
                await _next.Invoke(context);
            }
            catch (Exception)
            {
                statusCode = "500";
                throw;
            }
            finally
            {
                if (string.IsNullOrEmpty(statusCode))
                {
                    statusCode = context.Response.StatusCode.ToString();
                }

                double ticks = Stopwatch.GetTimestamp() - ts;
                WriteMetrics(statusCode, method, controller, action, path, ticks / Stopwatch.Frequency);
            }
        }