private void ProcessEndRequest(EndRequestMessage message, HttpContext httpContext) { var request = httpContext.Request; var response = httpContext.Response; message.RequestUrl = $"{request.Scheme}://{request.Host}{request.PathBase}{request.Path}{request.QueryString}"; // TODO: check if there is a better way of doing this message.RequestPath = request.Path; message.RequestQueryString = request.QueryString.Value; message.ResponseHeaders = response.Headers.ToDictionary(h => h.Key, h => h.Value); message.ResponseContentLength = response.ContentLength; message.ResponseContentType = response.ContentType; message.ResponseStatusCode = response.StatusCode; // in this case still want to publish but setting duration to 0 var timing = _broker.EndLogicalOperation<BeginRequestMessage>(); if (timing != null) { message.ResponseDuration = Math.Round(timing.Elapsed.TotalMilliseconds, 2); message.ResponseEndTime = timing.End.ToUniversalTime(); } else { message.ResponseDuration = 0.0; message.ResponseEndTime = DateTime.UtcNow; _logger.LogCritical("ProcessEndRequest: Still published `EndRequestMessage` but couldn't find `BeginRequestMessage` in stack"); } }
public void OnEndRequest(HttpContext httpContext) { var message = new EndRequestMessage(); ProcessEndRequest(message, httpContext); _broker.SendMessage(message); }