Diagnose Server-Side Errors

Updated at:

ARMS Application Monitoring automatically captures and collects application exceptions, generates exception statistics, and traces each exception end to end. Use these capabilities to diagnose the cause of a server-side 5xx error online, without modifying your application code and without logging on to a host to read logs.

Problem description

Web page errors, especially 5xx errors, are one of the most common issues in applications on the Internet. 5xx errors usually occur on the server side, which carries the most complex business logic. In the entire request chain, the server side is where errors are most likely to occur and where the cause of an error is hardest to diagnose. To locate such an error, O&M engineers and development engineers often have to log on to the host and check the logs.

Example: A common Java application error log

2018-03-19 20:34:22,890 ERROR [io.undertow.request] (default task-84) UT005023: Exception handling request to /plan-manage.htm:
java.lang.IllegalStateException: UT000010: Session not found wFcTlKtkzPiwMyNtBTFv48jU
    at io.undertow.server.session.InMemorySessionManager$SessionImpl.getAttribute(InMemorySessionManager.java:353) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.spec.HttpSessionImpl.getAttribute(HttpSessionImpl.java:121) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at org.springframework.security.web.context.HttpSessionSecurityContextRepository$SaveToSessionResponseWrapper.saveContext(HttpSessionSecurityContextRepository.java:323) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.context.HttpSessionSecurityContextRepository.saveContext(HttpSessionSecurityContextRepository.java:117) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:93) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344) [spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261) [spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) [spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:197) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759) [undertow-core-1.1.0.Final.jar:1.1.0.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_45]
    at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]

For applications that have simple logic and have been in production for a short time, logging on to the host and checking logs resolves most web page errors. However, this traditional diagnostic approach does not work in the following scenarios:

  • In a distributed application cluster, you need to know when and how often a specific type of error occurs.

  • A system has been running for a long time. You want to ignore legacy exceptions and know only which exceptions were added today compared with yesterday, or after a release compared with before the release.

  • You want to view the web request and the related request parameters for an exception.

  • A customer service representative provides the order number of a failed order, and you need to analyze why the order failed.

Solution

ARMS Application Monitoring captures exceptions automatically and gives you a full view of the error messages of an application. Diagnose a server-side error in two stages: first review the exception statistics to identify which exception types occur, and then open the trace of a single exception to find its cause.

The following table maps the questions that server logs leave unanswered to the data that ARMS Application Monitoring provides.

Diagnostic question

Data that answers it

When and how often a specific type of error occurs

The number of exceptions of the application and the number of occurrences of each exception type.

Which exceptions are newly added

The day-over-day and week-over-week changes of the number of exceptions.

Which request failed, and with which parameters

The complete trace and method stack of a single call, including its upstream and downstream context.

Prerequisites

  • The ARMS agent is installed for the application that you want to diagnose. ARMS Application Monitoring collects and displays exception data only for applications that have the agent installed.

Step 1: Install an ARMS agent

Before you can monitor an application, you must install an ARMS agent. Select one of the following methods to install an ARMS agent. For more information, see Application Monitoring overview.

View application exception statistics

ARMS collects the following metrics of an application for the selected time range, together with the day-over-day and week-over-week changes of each metric:

  • Total number of requests

  • Average response time

  • Number of errors

  • Number of real-time instances

  • Number of FullGC events

  • Number of slow SQL statements

  • Number of exceptions

  • Number of slow calls

  1. Log on to the ARMS console. In the left-side navigation pane, choose Application Monitoring > Application List.

  2. Select a region in the top navigation bar and click the application.

    Note

    Icons in the Language column indicate the application's programming language:

    • Java icon: Java

    • image: Go

    • image: Python

    • - (Hyphen): an application monitored in Managed Service for OpenTelemetry

  3. On the Application Overview page, on the Overall Analysis tab, view the total number of exceptions and its week-over-week and day-over-day changes.

  4. Scroll down to the Exception Type table in the Statistical analysis section at the bottom of the Overall Analysis tab to view how many times each type of exception occurred.

    The table displays the number of occurrences and the proportion of each exception type.

Diagnose exception causes

Application exception statistics alone are not enough to diagnose why an exception occurred. The exception stack in the log contains the code snippet of the call, but it does not contain the complete upstream and downstream information or the request parameters of that call. The ARMS agent uses bytecode enhancement to capture a complete snapshot of the calls upstream and downstream of an exception with minimal performance overhead, so that you can identify the specific cause of the exception.

  1. In the left-side navigation pane, click Application Details. Then, on the right side of the page, click the Exception Analysis tab to view the exception statistics chart, the number of errors, and exception stacks.

    The Actions column of the exception stack list provides the Call Statistics, Call chain query, and Details links. The following steps use Call chain query because it opens the complete upstream and downstream snapshot of the call.

  2. On the Exception Analysis tab, find the exception type that you want to diagnose. In the Actions column on its right, click Call chain query.

    The Call chain query tab displays the trace information related to this exception type.

  3. On the Call chain query tab, click the TraceId of an erroneous call. The trace details page appears.

    Note

    For information about how to find a target trace, see trace query.

    On the trace details page, you can enter an interface name in the search box to filter the list. The list contains the Time, Interface, Application, Time Consumed, Result, TraceId, and Actions columns. In the Result column, a green dot indicates a normal call and a red dot indicates an exception. Use this column to locate exceptional calls.

  4. On the trace details page, view the trace information of the exception. In the Details column, click the magnifier icon to view the method stack of the call and obtain the context of the exception.

    To investigate the cause in the logs instead, click View Logs in the row of the exceptional call.

    Complete trace information of the exception. The method stack shows that the total request time is 58947 ms and that the trace is Tomcat Servlet Process→sun.net.www.protocol.http.HttpURLConnection.getInputStream()→org.apache.http.impl.client.CloseableHttpClient.execute, and so on. HttpURLConnection.getInputStream() throws a java.io.IOException exception when it accesses OSS, which helps you locate the cause of the exception.

    At this point, you have found the cause of the application exception, which helps you with the next step of code optimization. You can also return to the Call chain query tab to view the other exceptions in the list and resolve them one by one.

If no exception data appears

If a step in this topic returns no exception data, the scope of your query might exclude the exception. Check the following items:

  • Time range — The number of exceptions, its day-over-day and week-over-week changes, and the exception type statistics all cover the selected time range only. Change the time range, and then check the statistics again.

  • Exception filter — An exception type that is excluded by the exception filter of the application is not counted in the exception statistics. To ignore an exception type, configure the exception filter field under Application Settings > Custom Configuration > Advanced Settings.

Next steps

Instead of diagnosing the causes of errors reactively after an issue occurs, you can use the alert feature of ARMS proactively. Create alerts for one interface or for all interfaces, so that your O&M team is notified when an issue occurs. For information about how to create an alert, see Application Monitoring alert rules.