博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ZipKin添加自定义跨度Span
阅读量:6970 次
发布时间:2019-06-27

本文共 2177 字,大约阅读时间需要 7 分钟。

hot3.png

监测mysql查询时间

    @Autowired

    private Tracer tracer; //用于访问Spring Cloud Sleuth跟踪信息
public Organization getOrg
            (String organizationId) {
        Span newSpan = tracer.createSpan("getOrgDBCall");//创建一个新的自定义跨度,名为getOrgDBCall
        logger.debug("In the organizationService.getOrg() call");
        try {
            return orgRepository.findById(organizationId);
        }
        finally{
          newSpan.tag("peer.service", "mysql");//将标签信息添加到跨度中,提供了将要被Zipkin捕获的服务名称
          newSpan.logEvent(org.springframework.cloud.sleuth.Span.CLIENT_RECV);//记录事件,告诉Spring Cloud Sleuth捕获调用完成的时间
          tracer.close(newSpan);//关闭跟踪,否则报错
        }
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
监测redis查询时间

 private Organization checkRedisCache(String organizationId) {

       Span newSpan = tracer.createSpan("readLicensingDataFromRedis");
        try {
            return orgRedisRepo.findOrganization(organizationId);
        }
        catch (Exception ex){
            return null;
        }
        finally {
          newSpan.tag("peer.service", "redis");
          newSpan.logEvent(org.springframework.cloud.sleuth.Span.CLIENT_RECV);
          tracer.close(newSpan);
        }
    }
 

@Aspect@Component@ConditionalOnProperty(value = "spring.sleuth.enabled", matchIfMissing = false)public class TracerServiceAspect {		@Pointcut("execution(public * com.xxx.cloud.*.service.impl.*.*(..))")	public void tracerLog() {	}	// 全局的trace对象	@Autowired	Tracer tracer;	// 针对所有Controller层的方法的切面	@Around("tracerLog()")	public Object doSurround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {		Span currentSpan = tracer.getCurrentSpan();		String className = proceedingJoinPoint.getSignature().getDeclaringTypeName();		String methodName = proceedingJoinPoint.getSignature().getName();		Span newSpan = null;		if (currentSpan != null) {			newSpan = tracer.createSpan(methodName, currentSpan);		} else {			newSpan = tracer.createSpan(methodName);		}		newSpan.tag("className", className);		newSpan.tag("methodName", methodName);		Object result = null;		try {			// 方法的执行结果			 result = proceedingJoinPoint.proceed();		} catch (Exception e) {			newSpan.tag("error", e.getMessage());		} finally {			newSpan.logEvent(org.springframework.cloud.sleuth.Span.CLIENT_RECV);// 记录事件,告诉Spring Cloud Sleuth捕获调用完成的时间			tracer.close(newSpan);// 关闭跟踪,否则报错		}		return result;	}}

 

转载于:https://my.oschina.net/xiaominmin/blog/3047867

你可能感兴趣的文章
Download file using libcurl in C/C++
查看>>
电Call记录统计查询sql
查看>>
JS面试题-算法台阶问题
查看>>
[转] c# 的传递参数值传递与传递引用的区别,ref与out区别
查看>>
iOS开发UI篇—在UItableview中实现加载更多功能
查看>>
Java计算文件的SHA码和MD5码
查看>>
Tomcat7基于Redis的Session共享实战一
查看>>
Linux下使用ps命令来查看Oracle相关的进程
查看>>
使用两个路由器扩展家庭无线网络
查看>>
Spark metrics on wordcount example
查看>>
【SQL Sever】SQL Sever数据库重命名
查看>>
Javascript数组中shift()和push(),unshift()和pop()操作方法使用
查看>>
Linux搭建一个FTP服务器
查看>>
Quick Touch – 在 iOS 设备运行的 “Touch Bar”
查看>>
Post with HttpClient
查看>>
仰视源代码,实现strcpy
查看>>
【Bootstrap Method】Evaluating The Accuracy of a Classifier
查看>>
让 Python 带你进入开源的世界——Git 从入门到与他人协作开发
查看>>
解决Flask局域网内访问不了的问题
查看>>
PHP获取今天、昨天、明天的日期
查看>>