public class TracerLogFilter extends Filter<ILoggingEvent> {
@Override
public FilterReply decide(ILoggingEvent event) {
Object[] argumentArray = event.getArgumentArray();
if (ArrayUtils.isEmpty(argumentArray)) {
return FilterReply.ACCEPT;
}
String message = event.getMessage();
if (message.startsWith("tracer")) {
try {
TracerUtils tracer = SpringBeanUtils.getBean(TracerUtils.class);
if (tracer != null) {
tracer.addTag(message, ArrayUtils.toString(argumentArray));
}
} catch (Exception e) {
e.printStackTrace();
}
}
return FilterReply.ACCEPT;
}
}
@Component
public class TracerUtils {
@Value("${spring.sleuth.enabled:false}")
private Boolean sleuthFlag = false;
public void addTag(String key, String value) {
if (sleuthFlag) {
Tracer tracer = SpringBeanUtils.getBean(Tracer.class);
if (tracer != null) {
tracer.addTag(key, value);
}
}
}
}