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

cn.com.antcloud.api.common.trace.AbstractTraceContext Maven / Gradle / Ivy

Go to download

Ant Fin Tech API SDK For Java Copyright (c) 2015-present Alipay.com, https://www.alipay.com

The newest version!
/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2021 All Rights Reserved.
 */
package cn.com.antcloud.api.common.trace;

public class AbstractTraceContext {
    private static ThreadLocal threadLocal              = new ThreadLocal();


    // ======================== 以下为透传数据的 key ========================
    /** TraceId 放在透传上下文中的 key */
    public static final String                     TRACE_ID_KEY             = "gwTraceId";
    /**
     * 压测key
     */
    public static final String                     LOAD_TEST_MARK_KEY             = "gwLoadTestMark";

    /**
     *  压测uid
     */
    public static final String                     LOAD_TEST_UID_KEY             = "gwLoadTestUid";

    public static final String                     X_ANTCHAIN_LOAD_TEST_MARK     = "x-antchain-load-test-mark";

    public static final String                     X_ANTCHAIN_LOAD_TEST_UID      = "x-antchain-load-test-uid";

    public static final String                     SOFA4_TRACE_ID                = "SOFA-TraceId";


    /** 可穿透的数据, 包括两部分: tracer自身需要穿透的(如tracerId, rpcId,mark)**/

    protected TracerContext tracerContext            = new TracerContext();

    public static AbstractTraceContext get() {
        return threadLocal.get();
    }

    public static void set(AbstractTraceContext ctx) {
        threadLocal.set(ctx);
    }

    /**
     * 清除
     */
    public static void clear(){
        threadLocal.remove();
    }


    /**
     * @return
     */
    public String getTraceId() {
        return tracerContext.get(TRACE_ID_KEY);
    }

    /**
     * @param traceId
     */
    public void setTraceId(String traceId) {
        tracerContext.put(TRACE_ID_KEY, traceId == null ? "" : traceId);
    }



    /**
     * @return
     */
    public String getLoadTestMark() {
        return tracerContext.get(LOAD_TEST_MARK_KEY);
    }

    /**
     * @param loadTestMark
     */
    public void setLoadTestMark(String loadTestMark) {
        tracerContext.put(LOAD_TEST_MARK_KEY, loadTestMark == null ? "" : loadTestMark);
    }

    public String getLoadTestUid(){
        return tracerContext.get(LOAD_TEST_UID_KEY);
    }

    /**
     * @param loadTestUid
     */
    public void setLoadTestUid(String loadTestUid) {
        tracerContext.put(LOAD_TEST_UID_KEY, loadTestUid == null ? "" : loadTestUid);
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy