我是靠谱客的博主 陶醉时光,这篇文章主要介绍使用CAT进行打点,现在分享给大家,希望可以做个参考。

使用CAT进行打点:

  • 使用CAT进行打点,以下是CatUtil的主要代码:
/**
* 开启一个新事务记录事件
*
* @param txType
* @param txName
* @param kvs
*/
public static void logEvent(String txType, String txName, KVPair... kvs) {
   if (kvs == null) {
       return;
   }
   Transaction t = null;
   try {
       MessageProducer producer = Cat.getProducer();
       t = producer.newTransaction(txType, txName);
       for (KVPair kv : kvs) {
           producer.logEvent(kv.getKey(), kv.getValue());
       }
       t.setStatus(Transaction.SUCCESS);
   } catch (Throwable th) {
       t.setStatus(th);
       log.error("faid to parse token and calculate time", th);
   } finally {
       complete(t);
   }
}

/**
* 结束事务
*
* @param t
*/
public static void complete(Transaction t) {
   try {
       if (t != null && !t.isCompleted()) {
           t.complete();
       }
   } catch (Throwable thr) {
       log.error("fail to complete transaction", thr);
   }
}

简单KV对象:

@Data
@AllArgsConstructor
@NoArgsConstructor
public class KVPair {
    private String key;
    private String value;

    public static KVPair of(String key, String value) {
        return new KVPair(key, value);
    }
}

在需要打点的地方调用logEvent方法,如下所示:

 CatUtil.logEvent(AUTH_TIME, "AUTH_TIME_EVENT", KVPair.of(AUTH_TIME, "AUTH_TIME_ALL=" + fullTimeSpent));

最后

以上就是陶醉时光最近收集整理的关于使用CAT进行打点的全部内容,更多相关使用CAT进行打点内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(154)

评论列表共有 0 条评论

立即
投稿
返回
顶部