public void handleResponse()

in aws-xray-agent/src/main/java/com/amazonaws/xray/agent/runtime/handlers/upstream/ServletHandler.java [73:108]


    public void handleResponse(Event event) {
        HttpServletNetworkResponseEvent responseEvent = (HttpServletNetworkResponseEvent) event;
        Segment currentSegment = getSegment();

        // No need to log since a Context Missing Error will already be recorded
        if (currentSegment == null) {
            return;
        }

        // Add the status code
        // Obtain the status code of the underlying http response. If it failed, it's a fault.
        Map<String, Object> responseAttributes = new HashMap<>();
        int statusCode = responseEvent.getStatusCode();

        // Check if the status code was a fault.
        switch (statusCode / 100) {
            case 2:
                // Server OK
                break;
            case 4:
                // Exception
                currentSegment.setError(true);
                if (statusCode == 429) {
                    currentSegment.setThrottle(true);
                }
                break;
            case 5:
                // Fault
                currentSegment.setFault(true);
                break;
        }
        responseAttributes.put(STATUS_KEY, statusCode);
        currentSegment.putHttp(RESPONSE_KEY, responseAttributes);

        endSegment();
    }