All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.youta8.frame.common.util.TraceUtil Maven / Gradle / Ivy

There is a newer version: 2.4.4
Show newest version
package com.youta8.frame.common.util;

import com.youta8.frame.common.constants.MyConstant;
import org.slf4j.MDC;
import javax.servlet.http.HttpServletRequest;

/**
 * 链路追踪工具类
 *
 * @author youta
 */
public class TraceUtil {

    /**
     * 从header和参数中获取traceId
     * 从前端传入数据
     *
     * @param request HttpServletRequest
     * @return traceId
     */
    public static String getTraceId(HttpServletRequest request) {
        String traceId = request.getParameter(MyConstant.MINE_TRACE_ID);
        if (StringUtil.isBlank(traceId)) {
            traceId = request.getHeader(MyConstant.MINE_TRACE_ID);
        }
        return traceId;
    }

    /**
     * 传递traceId至MDC
     * @param traceId 跟踪ID
     */
    public static void mdcTraceId (String traceId) {
        if (StringUtil.isNotBlank(traceId)) {
            MDC.put(MyConstant.LOG_TRACE_ID, traceId);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy