/** * @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; }