Search code examples
netflix-zuul

Where can i find the debug information in zuul?


I want to use debugFilter in ZUUL. when i post param "debug=true" in query string, I can't find the debug info in my standard output.

Where can i find the debug information?


Solution

  • If you call api with param debug=true, debugging information will be accumulated into RequestContext with a key routingDebug. The value is List<String> type. If you set the properties like below, debug info will be added into response-header - X-Zuul-Debug-Header.

    zuul.include-debug-header=true
    

    As far as I know, this information is not printed out to standard out as default. Instead, you can easily access this info via com.netflix.zuul.context.Debug.getRoutingDebug().

    You can make your own post filter to print out this info easily like below.

    @Override
    public boolean shouldFilter() {
        return Debug.debugRouting();
    }
    
    @Override
    public Object run() {
        String debug = convertToPrettyPrintString(Debug.getRoutingDebug());
        log.info("Filter Debug Info = \n{}", debug);
        // or System.out.println(...)
        return null;
    }
    
    private String convertToPrettyPrintString(List<String> filterDebugList) {
        return filterDebugList.stream()
            .map(s -> s.startsWith("{") ? "\t" + s : s)
            .collect(Collectors.joining("\n"));
    }