/// <summary>
        /// Process events where we need to switch based on the key, which is slower.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private bool ProcessEventsByKey(KeyValuePair <string, object> value)
        {
            switch (value.Key)
            {
            case "Microsoft.AspNetCore.Hosting.UnhandledException":     //used when no exception handler is registered in the request pipeline
            case "Microsoft.AspNetCore.Diagnostics.UnhandledException": //used when an exception handler is registered
            case "Microsoft.AspNetCore.Diagnostics.HandledException":   //used when an exception handler is registered
            {
                //This can be made faster, but if we're in an exception flow performance is already not fabulous.
                var httpContext = value.Value.GetProperty <HttpContext>("httpContext");
                var exception   = value.Value.GetProperty <Exception>("exception");

                if (exception != null)
                {
                    httpContext?.Features.Get <RequestMetric>()?.SetException(exception);
                }
                break;
            }

            case "Microsoft.AspNetCore.Hosting.HttpRequestIn.Start":
            {
                var httpContext = value.Value as HttpContext;
                httpContext?.Features.Set(_requestMetricFactory.Start(httpContext));
                break;
            }

            case "Microsoft.AspNetCore.Hosting.HttpRequestIn.Stop":
            {
                var httpContext = value.Value as HttpContext;
                httpContext?.Features.Get <RequestMetric>()?.Stop();
                break;
            }

            default:
                return(false);    //we didn't handle it.
            }

            return(true);
        }
 public virtual void BeginRequest(HttpContext httpContext)
 {
     httpContext?.Features.Set(_actionMetricFactory.Start(httpContext));
 }