/// <summary> /// Post-Request processing /// </summary> /// <param name="context">type: IOwinContext</param> private void EndRequest(IOwinContext context) { if (HttpContext.Current == null) { return; } var startTime = ItemDecorator.GetInspectorInstance()[ItemDecorator.RequestStartTime]; if (startTime != null //// ignore non-user pings && TelemetryState.IsTelemetryEnabledUserAgent() //// ignore requests to specific paths && TelemetryState.IsTelemetryEnabledRequestPath() //// ignore requests to specific extensions && TelemetryState.IsTelemetryEnabledRequestExtension() //// make sure the portal is configured && this.IsPortalConfigured()) { var requestStartTime = (DateTime)startTime; var elapsedTime = DateTime.UtcNow - requestStartTime; MdmMetrics.RequestExecutionTimeMetric.LogValue((long)elapsedTime.TotalMilliseconds); var ag = PerformanceAggregateLogger.GetPerformanceAggregate(); if (ag != null) { PerformanceEventSource.Log.PerformanceAggregate(ag, elapsedTime); } } }
protected string ElapsedTime() { try { if (this.HttpContext == null) { return(string.Empty); } if (this.OwinContext == null || this.OwinContext.Get <RequestElapsedTimeContext>() == null) { var inspector = ItemDecorator.GetInspectorInstance(this.HttpContextBase); var startTime = inspector[ItemDecorator.RequestStartTime]; if (startTime != null) { var requestStartTime = (DateTime)startTime; return((DateTime.UtcNow - requestStartTime).TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); } return(string.Empty); } else { return(this.OwinContext.Get <RequestElapsedTimeContext>().ElapsedTime().ToString()); } } catch { // eat exception expecting it to possibly happen in scenarios without context // i.g., background worker threads return(string.Empty); } }