/// <summary>
 /// Observes request state, updated aggregate metrics.
 /// </summary>
 /// <param name="requestState"></param>
 internal void ObserveRequestState(WebMetricsRequestState requestState)
 {
     lock (_lock)
     {
         _requestHandlerMillisecondsComposite.Increment(requestState.RequestHandlerMilliseconds);
         _requestMillisecondsComposite.Increment(requestState.RequestMilliseconds);
         _responseBodyLengthComposite.Increment(requestState.ResponseBodyLength);
         TotalObservedRequests.Increment();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// We observe the `BeginRequest` event to allocate request state and
        /// capture the request start time.
        /// </summary>
        private void OnBeginRequest(object sender, EventArgs e)
        {
            // NOTE: we remove Accept-Encoding and replace with "identity" to
            //       avoid opportunity for response filter to receive
            //       compressed content
            if (AppDomain.CurrentDomain.FriendlyName.Contains("/W3SVC/"))
            {
                HttpContext.Current.Request.Headers.Remove("Accept-Encoding");
                HttpContext.Current.Request.Headers.Add("Accept-Encoding", "identity");
            }
            var requestState = new WebMetricsRequestState(HttpContext.Current.Request.RawUrl);

            HttpContext.Current.Items[HTTPCONTEXT_WEBMETRICS_REQUESTSTATE_KEY] = requestState;
            HttpContext.Current.Response.BufferOutput = true;
            HttpContext.Current.Response.Filter       = new IO.HtmlRewriteFilterStream(
                HttpContext.Current.Response,
                requestState,
                s_aggregateState);
            requestState.ObserveBeginRequest();
        }