Beispiel #1
0
        private static void FinalizeRequestLatencies(HttpContext httpContext, RequestDetailsLogger requestDetailsLogger, IActivityScope activityScope, LatencyTracker tracker, int traceContext)
        {
            if (tracker == null)
            {
                return;
            }
            if (requestDetailsLogger == null)
            {
                throw new ArgumentNullException("requestDetailsLogger");
            }
            if (activityScope == null)
            {
                throw new ArgumentNullException("activityScope");
            }
            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }
            long num = tracker.GetCurrentLatency(LatencyTrackerKey.ProxyModuleLatency);

            if (num >= 0L)
            {
                long num2 = 0L;
                long.TryParse(activityScope.GetProperty(ServiceLatencyMetadata.HttpPipelineLatency), out num2);
                long num3 = 0L;
                bool flag = requestDetailsLogger.TryGetLatency(HttpProxyMetadata.BackendProcessingLatency, out num3);
                long num4 = requestDetailsLogger.GetLatency(HttpProxyMetadata.ClientRequestStreamingLatency, 0L) + requestDetailsLogger.GetLatency(HttpProxyMetadata.BackendRequestStreamingLatency, 0L) + num3 + requestDetailsLogger.GetLatency(HttpProxyMetadata.BackendResponseStreamingLatency, 0L) + requestDetailsLogger.GetLatency(HttpProxyMetadata.ClientResponseStreamingLatency, 0L);
                long num5 = num - num4;
                PerfCounters.UpdateMovingAveragePerformanceCounter(PerfCounters.HttpProxyCountersInstance.MovingAverageCasLatency, num5);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, HttpProxyMetadata.HttpProxyOverhead, num5);

                long num6 = num5 - num2;
                if (flag)
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, HttpProxyMetadata.RoutingLatency, Math.Max(num6, 0L));

                    string property = activityScope.GetProperty(HttpProxyMetadata.TargetServer);
                    if (PerfCounters.RoutingLatenciesEnabled && !string.IsNullOrEmpty(property))
                    {
                        string empty = string.Empty;
                        Utilities.TryGetSiteNameFromServerFqdn(property, out empty);
                        PercentilePerfCounters.UpdateRoutingLatencyPerfCounter(empty, (double)num6);
                        PerfCounters.GetHttpProxyPerSiteCountersInstance(empty).TotalProxyWithLatencyRequests.Increment();
                    }
                }
                long val = num6 - requestDetailsLogger.GetLatency(HttpProxyMetadata.BackendRequestInitLatency, 0L) - requestDetailsLogger.GetLatency(HttpProxyMetadata.BackendResponseInitLatency, 0L);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, HttpProxyMetadata.CoreLatency, Math.Max(val, 0L));

                long currentLatency = tracker.GetCurrentLatency(LatencyTrackerKey.ProxyModuleLatency);
                long num7           = currentLatency - num;
                num = currentLatency;
                if (num7 > 5L)
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(requestDetailsLogger, "TotalRequestTimeDelta", num7);
                }
            }
            RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, HttpProxyMetadata.TotalRequestTime, num);
        }
Beispiel #2
0
        private void OnPostAuthorizeRequest(object sender, EventArgs e)
        {
            HttpApplication httpApplication = (HttpApplication)sender;
            HttpContext     httpContext     = httpApplication.Context;

            Diagnostics.SendWatsonReportOnUnhandledException(delegate()
            {
                if (Microsoft.Exchange.Diagnostics.Components.HttpProxy.ExTraceGlobals.VerboseTracer.IsTraceEnabled(TraceType.DebugTrace))
                {
                    Microsoft.Exchange.Diagnostics.Components.HttpProxy.ExTraceGlobals.VerboseTracer.TraceDebug((long)this.GetHashCode(), "[ProxyModule::OnPostAuthorizeRequest]: Method {0}; Url {1}; Username {2}; Context {3};", new object[]
                    {
                        httpContext.Request.HttpMethod,
                        httpContext.Request.Url,
                        (httpContext.User == null) ? string.Empty : httpContext.User.Identity.GetSafeName(true),
                        httpContext.GetTraceContext()
                    });
                }
                this.OnPostAuthorizeInternal(httpApplication);
                LatencyTracker latencyTracker = LatencyTracker.FromHttpContext(httpContext);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(RequestDetailsLoggerBase <RequestDetailsLogger> .GetCurrent(httpContext), ServiceLatencyMetadata.HttpPipelineLatency, latencyTracker.GetCurrentLatency(LatencyTrackerKey.ProxyModuleLatency));
                long currentLatency = latencyTracker.GetCurrentLatency(LatencyTrackerKey.AuthenticationLatency);
                PerfCounters.UpdateMovingAveragePerformanceCounter(PerfCounters.HttpProxyCountersInstance.MovingAverageAuthenticationLatency, currentLatency);
                latencyTracker.StartTracking(LatencyTrackerKey.ModuleToHandlerSwitchingLatency, false);
            }, new Diagnostics.LastChanceExceptionHandler(RequestDetailsLogger.LastChanceExceptionHandler));
        }
Beispiel #3
0
        private void OnEndRequest(object sender, EventArgs e)
        {
            HttpApplication httpApplication = (HttpApplication)sender;
            HttpContext     httpContext     = httpApplication.Context;

            Diagnostics.SendWatsonReportOnUnhandledException(delegate()
            {
                LatencyTracker latencyTracker = LatencyTracker.FromHttpContext(httpContext);
                RequestDetailsLogger current  = RequestDetailsLoggerBase <RequestDetailsLogger> .GetCurrent(httpContext);
                int traceContext = httpContext.GetTraceContext();
                if (HttpProxyGlobals.ProtocolType != ProtocolType.Mapi)
                {
                    OwaProxyRequestHandler.TryAddUnAuthenticatedPLTRequestPostDataToUriQueryOfIISLog(httpContext);
                }
                if (httpContext.Response != null && current != null)
                {
                    httpContext.Response.AppendToLog(Constants.RequestIdKeyForIISLogs + current.ActivityId.ToString() + ";");
                }
                if (HealthCheckResponder.Instance.IsHealthCheckRequest(httpContext))
                {
                    return;
                }
                if (httpContext.Response.StatusCode == 404 && httpContext.Response.SubStatusCode == 13)
                {
                    httpContext.Response.StatusCode = 507;
                }
                if (Microsoft.Exchange.Diagnostics.Components.HttpProxy.ExTraceGlobals.VerboseTracer.IsTraceEnabled(TraceType.DebugTrace))
                {
                    Microsoft.Exchange.Diagnostics.Components.HttpProxy.ExTraceGlobals.VerboseTracer.TraceDebug((long)this.GetHashCode(), "[ProxyModule::OnEndRequest]: Method {0}; Url {1}; Username {2}; Context {3};", new object[]
                    {
                        httpContext.Request.HttpMethod,
                        httpContext.Request.Url,
                        (httpContext.User == null) ? string.Empty : httpContext.User.Identity.GetSafeName(true),
                        traceContext
                    });
                }
                if (latencyTracker != null)
                {
                    long currentLatency = latencyTracker.GetCurrentLatency(LatencyTrackerKey.HandlerToModuleSwitchingLatency);
                    if (currentLatency >= 0L)
                    {
                        RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(current, HttpProxyMetadata.HandlerToModuleSwitchingLatency, currentLatency);
                    }
                }
                ProxyRequestHandler proxyRequestHandler = httpContext.CurrentHandler as ProxyRequestHandler;
                if (proxyRequestHandler != null && !proxyRequestHandler.IsDisposed)
                {
                    current.AppendGenericInfo("DisposeProxyRequestHandler", "ProxyModule::OnEndRequest");
                    proxyRequestHandler.Dispose();
                }
                string value = httpContext.Items["AnonymousRequestFilterModule"] as string;
                if (!string.IsNullOrEmpty(value))
                {
                    current.AppendGenericInfo("AnonymousRequestFilterModule", value);
                }
                try
                {
                    this.OnEndRequestInternal(httpApplication);
                }
                finally
                {
                    if (current != null && !current.IsDisposed)
                    {
                        IActivityScope activityScope = current.ActivityScope;
                        if (activityScope != null)
                        {
                            if (!string.IsNullOrEmpty(activityScope.TenantId))
                            {
                                httpContext.Items["AuthenticatedUserOrganization"] = activityScope.TenantId;
                            }
                            ProxyModule.FinalizeRequestLatencies(httpContext, current, activityScope, latencyTracker, traceContext);
                        }
                        current.LogCurrentTime("EndRequest");
                        current.AsyncCommit(false);
                    }
                    if (Microsoft.Exchange.Diagnostics.Components.HttpProxy.ExTraceGlobals.VerboseTracer.IsTraceEnabled(TraceType.DebugTrace))
                    {
                        Microsoft.Exchange.Diagnostics.Components.HttpProxy.ExTraceGlobals.VerboseTracer.TraceDebug(0L, "[ProxyModule::OnEndRequest]: Method {0}; Url {1}; OnEndRequestLatency {2}; Context {3};", new object[]
                        {
                            httpContext.Request.HttpMethod,
                            httpContext.Request.Url,
                            (latencyTracker != null) ? latencyTracker.GetCurrentLatency(LatencyTrackerKey.ProxyModuleLatency).ToString() : "Unknown",
                            traceContext
                        });
                    }
                }
            }, new Diagnostics.LastChanceExceptionHandler(RequestDetailsLogger.LastChanceExceptionHandler));
        }
Beispiel #4
0
 public void Init(HttpApplication application)
 {
     Diagnostics.SendWatsonReportOnUnhandledException(delegate()
     {
         LatencyTracker latencyTracker = new LatencyTracker();
         latencyTracker.StartTracking(LatencyTrackerKey.ProxyModuleInitLatency, false);
         Microsoft.Exchange.Diagnostics.Components.HttpProxy.ExTraceGlobals.VerboseTracer.TraceDebug <ProtocolType>((long)this.GetHashCode(), "[ProxyModule::Init]: Init called.  Protocol type: {0}", HttpProxyGlobals.ProtocolType);
         if (application == null)
         {
             string message = "[ProxyModule::Init]: ProxyModule.Init called with null HttpApplication context.";
             Microsoft.Exchange.Diagnostics.Components.HttpProxy.ExTraceGlobals.BriefTracer.TraceError((long)this.GetHashCode(), message);
             throw new ArgumentNullException("application", message);
         }
         this.PfdTracer                     = new PfdTracer(0, this.GetHashCode());
         application.BeginRequest          += this.OnBeginRequest;
         application.AuthenticateRequest   += this.OnAuthenticateRequest;
         application.PostAuthorizeRequest  += this.OnPostAuthorizeRequest;
         application.PreSendRequestHeaders += this.OnPreSendRequestHeaders;
         application.EndRequest            += this.OnEndRequest;
         if (Microsoft.Exchange.Diagnostics.Components.HttpProxy.ExTraceGlobals.VerboseTracer.IsTraceEnabled(TraceType.DebugTrace))
         {
             Microsoft.Exchange.Diagnostics.Components.HttpProxy.ExTraceGlobals.VerboseTracer.TraceDebug <ProtocolType, long>((long)this.GetHashCode(), "[ProxyModule::Init]: Protocol type: {0}, InitLatency {1}", HttpProxyGlobals.ProtocolType, latencyTracker.GetCurrentLatency(LatencyTrackerKey.ProxyModuleInitLatency));
         }
     });
 }
Beispiel #5
0
        // Token: 0x060005FB RID: 1531 RVA: 0x00021BD8 File Offset: 0x0001FDD8
        private void OnEndRequest(object sender, EventArgs e)
        {
            HttpApplication httpApplication = (HttpApplication)sender;
            HttpContext     httpContext     = httpApplication.Context;

            CheckpointTracker.GetOrCreate(httpContext.Items).Add(FrontEndHttpProxyCheckpoints.ProxyModuleEndRequest);
            Diagnostics.SendWatsonReportOnUnhandledException(delegate()
            {
                if (!HostHeaderValidator.HasValidHostHeaderStatusDescription(new HttpContextWrapper(httpContext).Response) || httpContext.Items["AutodiscoverRedirectModule"] != null)
                {
                    return;
                }
                LatencyTracker latencyTracker = LatencyTracker.FromHttpContext(httpContext);
                RequestDetailsLogger current  = RequestDetailsLoggerBase <RequestDetailsLogger> .GetCurrent(httpContext);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(RequestDetailsLoggerBase <RequestDetailsLogger> .GetCurrent(httpContext), GuardedSharedCacheExecution.Default.Key, GuardedSharedCacheExecution.Default.Guard.GetCurrentValue());
                int traceContext = httpContext.GetTraceContext();
                if (httpContext.Response != null && current != null)
                {
                    httpContext.Response.AppendToLog(Constants.RequestIdKeyForIISLogs + current.ActivityId.ToString() + ";");
                }
                if (HealthCheckResponder.Instance.IsHealthCheckRequest(httpContext))
                {
                    return;
                }
                if (httpContext.Response.StatusCode == 404 && httpContext.Response.SubStatusCode == 13)
                {
                    httpContext.Response.StatusCode = 507;
                }
                if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(1))
                {
                    ExTraceGlobals.VerboseTracer.TraceDebug((long)this.GetHashCode(), "[ProxyModule::OnEndRequest]: Method {0}; Url {1}; Username {2}; Context {3};", new object[]
                    {
                        httpContext.Request.HttpMethod,
                        httpContext.Request.Url,
                        (httpContext.User == null) ? string.Empty : IIdentityExtensions.GetSafeName(httpContext.User.Identity, true),
                        traceContext
                    });
                }
                if (latencyTracker != null)
                {
                    long currentLatency = latencyTracker.GetCurrentLatency(LatencyTrackerKey.HandlerToModuleSwitchingLatency);
                    if (currentLatency >= 0L)
                    {
                        RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(current, 5, currentLatency);
                    }
                }
                ProxyRequestHandler proxyRequestHandler = httpContext.CurrentHandler as ProxyRequestHandler;
                if (proxyRequestHandler != null && !proxyRequestHandler.IsDisposed)
                {
                    current.AppendGenericInfo("DisposeProxyRequestHandler", "ProxyModule::OnEndRequest");
                    proxyRequestHandler.Dispose();
                }
                ProxyModule.InspectNativeProxyFatalError(httpContext.Response, current);
                string text = httpContext.Items["AnonymousRequestFilterModule"] as string;
                if (!string.IsNullOrEmpty(text))
                {
                    current.AppendGenericInfo("AnonymousRequestFilterModule", text);
                }
                try
                {
                    this.OnEndRequestInternal(httpApplication);
                }
                finally
                {
                    if (current != null && !current.IsDisposed)
                    {
                        IActivityScope activityScope = current.ActivityScope;
                        if (activityScope != null)
                        {
                            if (!string.IsNullOrEmpty(activityScope.TenantId))
                            {
                                httpContext.Items["AuthenticatedUserOrganization"] = activityScope.TenantId;
                            }
                            ProxyModule.FinalizeRequestLatencies(httpContext, current, activityScope, latencyTracker, traceContext);
                        }
                        current.LogCurrentTime("EndRequest");
                        RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(current, 0, DateTime.UtcNow);
                        current.AsyncCommit(false, NativeProxyHelper.WasProxiedByNativeProxyHandler(SharedHttpContextWrapper.GetWrapper(httpContext)));
                    }
                    if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(1))
                    {
                        ExTraceGlobals.VerboseTracer.TraceDebug(0L, "[ProxyModule::OnEndRequest]: Method {0}; Url {1}; OnEndRequestLatency {2}; Context {3};", new object[]
                        {
                            httpContext.Request.HttpMethod,
                            httpContext.Request.Url,
                            (latencyTracker != null) ? latencyTracker.GetCurrentLatency(LatencyTrackerKey.ProxyModuleLatency).ToString() : "Unknown",
                            traceContext
                        });
                    }
                }
            }, new Diagnostics.LastChanceExceptionHandler(RequestDetailsLogger.LastChanceExceptionHandler));
        }
Beispiel #6
0
        // Token: 0x060005F2 RID: 1522 RVA: 0x00021190 File Offset: 0x0001F390
        private static void FinalizeRequestLatencies(HttpContext httpContext, RequestDetailsLogger requestDetailsLogger, IActivityScope activityScope, LatencyTracker tracker, int traceContext)
        {
            if (tracker == null)
            {
                return;
            }
            if (requestDetailsLogger == null)
            {
                throw new ArgumentNullException("requestDetailsLogger");
            }
            if (activityScope == null)
            {
                throw new ArgumentNullException("activityScope");
            }
            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }
            HttpContextBase wrapper = SharedHttpContextWrapper.GetWrapper(httpContext);
            long            num     = tracker.GetCurrentLatency(LatencyTrackerKey.ProxyModuleLatency);

            if (num >= 0L)
            {
                long num2 = 0L;
                long.TryParse(activityScope.GetProperty(6), out num2);
                long num3 = 0L;
                bool flag = requestDetailsLogger.TryGetLatency(37, ref num3);
                long num4 = requestDetailsLogger.GetLatency(34, 0L) + requestDetailsLogger.GetLatency(36, 0L) + num3 + requestDetailsLogger.GetLatency(39, 0L) + requestDetailsLogger.GetLatency(40, 0L);
                long num5 = num - num4;
                if (!NativeProxyHelper.WasProxiedByNativeProxyHandler(wrapper))
                {
                    PerfCounters.UpdateMovingAveragePerformanceCounter(PerfCounters.HttpProxyCountersInstance.MovingAverageCasLatency, num5);
                }
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, 43, num5);

                long num6 = num5 - num2;
                if (flag)
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, 42, Math.Max(num6, 0L));

                    string property = activityScope.GetProperty(13);
                    if (PerfCounters.RoutingLatenciesEnabled && !string.IsNullOrEmpty(property))
                    {
                        string empty = string.Empty;
                        Utilities.TryExtractForestFqdnFromServerFqdn(property, ref empty);
                        PercentilePerfCounters.UpdateRoutingLatencyPerfCounter(empty, (double)num6);
                        PerfCounters.GetHttpProxyPerForestCountersInstance(empty).TotalProxyWithLatencyRequests.Increment();
                    }
                }
                long val = num6 - requestDetailsLogger.GetLatency(35, 0L) - requestDetailsLogger.GetLatency(38, 0L);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, 41, Math.Max(val, 0L));

                long currentLatency = tracker.GetCurrentLatency(LatencyTrackerKey.ProxyModuleLatency);
                long num7           = currentLatency - num;
                num = currentLatency;
                if (num7 > 5L)
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(requestDetailsLogger, "TotalRequestTimeDelta", num7);
                }
            }
            RequestDetailsLoggerBase <RequestDetailsLogger> .SafeSetLogger(requestDetailsLogger, 16, num);
        }