package com.olivia.sdk.aspect;
import com.olivia.sdk.utils.MDCUtils;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
/***
*
*/
@Slf4j
@Aspect
@Component
public class NextSpanAspect {
@Pointcut("execution(* com.olivia.peanut.*.service.impl.*.*(..))")
public void spanId() {
}
@Before("spanId()")
public void doBefore(JoinPoint joinPoint) throws Throwable {
}
@Around("spanId()")
public Object aroundLog(ProceedingJoinPoint joinPoint) throws Throwable {
Object result = null;
String spanId = MDCUtils.getSpanId();
try {
MDCUtils.nextSpanId();
result = joinPoint.proceed();
} finally {
MDCUtils.setSpanId(spanId);
}
return result;
}
}