/** * @return The distributed trace ID if available in the request or the SLF4J {@link MDC}, or null if it cannot be * found. Will also return null if the distributed trace ID exists but its trimmed length is 0 * (i.e. the distributed trace ID must be non-empty and contain something besides whitespace for it to be * used). If you are using a distributed tracing system that uses different keys or where the trace ID is * otherwise unobtainable using the rules defined here, then you can override this method and provide * whatever rules you want. */ public String extractDistributedTraceId(RequestInfoForLogging request) { String traceIdToUse = null; if (distributedTraceIdHeaderKey != null) { String dtraceIdFromHeader = request.getHeader(distributedTraceIdHeaderKey); Object dtraceIdFromAttribute = request.getAttribute(distributedTraceIdHeaderKey); if (StringUtils.isNotBlank(dtraceIdFromHeader)) traceIdToUse = dtraceIdFromHeader.trim(); else if (dtraceIdFromAttribute != null && StringUtils.isNotBlank(dtraceIdFromAttribute.toString())) traceIdToUse = dtraceIdFromAttribute.toString().trim(); } if (traceIdToUse == null) { // As a last resort try to get it from the MDC since some distributed systems (e.g. Wingtips) put the // trace ID there. String fromMdc = MDC.get(TRACE_ID_MDC_KEY); if (fromMdc != null) traceIdToUse = fromMdc.trim(); } return traceIdToUse; }
return headerName + "=[MASKED]"; } else { List<String> headerValues = request.getHeaders(headerName); if (headerValues == null || headerValues.isEmpty()) return "";
/** * @return All the headers in the given request as a comma-separated list of name=value in string form. * Multi-value headers will come back in name=[value1,value2] form. * NOTE: This method never throws an exception. If it catches one it will return blank string "" instead. */ public String parseRequestHeadersToString(RequestInfoForLogging request) { try { Map<String, List<String>> headers = request.getHeadersMap(); if (headers == null || headers.isEmpty()) return ""; Set<String> headerNames = headers.keySet(); StringBuilder sb = new StringBuilder(); boolean first = true; for (String headerName : headerNames) { if (!first) sb.append(","); sb.append(parseSpecificHeaderToString(request, headerName)); first = false; } return sb.toString(); } catch(Exception ex) { return ""; } }
String requestUri = request.getRequestUri(); String requestMethod = request.getRequestHttpMethod(); String queryString = request.getQueryString(); String headersString = parseRequestHeadersToString(request); String contributingErrorsString = concatenateErrorCollection(contributingErrors);
String body; try { body = request.getBody(); } catch (RequestInfoForLogging.GetBodyException e) { logger.warn("Failed to retrieve request_body while handling exception ex=" + ex, e);