use of com.pamirs.pradar.InvokeContext in project LinkAgent by shulieTech.
the class TraceInterceptor method endClientInvokeException.
/**
* 结束客户端异常调用
*
* @param advice
* @throws Throwable
*/
private final void endClientInvokeException(Advice advice) throws Throwable {
try {
if (!advice.hasMark(BEFORE_TRACE_SUCCESS)) {
if (isDebugEnabled) {
LOGGER.debug("{} before trace not finished.", getClass().getName());
}
return;
}
SpanRecord record = exceptionTrace(advice);
if (record == null) {
endClientInvoke(ResultCode.INVOKE_RESULT_SUCCESS, getPluginType(), advice);
return;
}
InvokeContext invokeContext = readCurrentInvokeContext(advice);
if (invokeContext == null) {
return;
}
Object response = record.getResponse();
if (response != null && response instanceof Throwable) {
advice.attach(response);
}
if (Pradar.isResponseOn()) {
invokeContext.setResponse(response);
}
if (StringUtils.isNotBlank(record.getRemoteIp())) {
invokeContext.setRemoteIp(record.getRemoteIp());
}
if (StringUtils.isNotBlank(record.getPort())) {
invokeContext.setPort(record.getPort());
}
if (record.getMiddlewareName() != null) {
invokeContext.setMiddlewareName(record.getMiddlewareName());
}
if (record.getCallbackMsg() != null) {
invokeContext.setCallBackMsg(record.getCallbackMsg());
}
endClientInvoke(record.getResultCode(), getPluginType(), advice);
} catch (Throwable e) {
endClientInvoke(ResultCode.INVOKE_RESULT_UNKNOWN, getPluginType(), advice);
throw e;
} finally {
advice.unMark(BEFORE_TRACE_SUCCESS);
}
}
use of com.pamirs.pradar.InvokeContext in project LinkAgent by shulieTech.
the class TraceInterceptor method endClientInvoke.
/**
* client invoke 结束
*
* @param advice
* @throws Throwable
*/
private void endClientInvoke(Advice advice) throws Throwable {
try {
if (!advice.hasMark(BEFORE_TRACE_SUCCESS)) {
if (isDebugEnabled) {
LOGGER.debug("{} before trace not finished.", getClass().getName());
}
return;
}
SpanRecord record = afterTrace(advice);
if (record == null) {
// 如果上下文开始了,但是这里没有,则需要强制结束
endClientInvoke(ResultCode.INVOKE_RESULT_SUCCESS, getPluginType(), advice);
return;
}
InvokeContext invokeContext = readCurrentInvokeContext(advice);
if (invokeContext == null) {
return;
}
if (record.getResponseSize() != 0) {
invokeContext.setResponseSize(record.getResponseSize());
}
Object response = record.getResponse();
if (response instanceof Throwable) {
advice.attach(response);
}
if (Pradar.isResponseOn()) {
invokeContext.setResponse(response);
}
if (StringUtils.isNotBlank(record.getRemoteIp())) {
invokeContext.setRemoteIp(record.getRemoteIp());
}
if (StringUtils.isNotBlank(record.getPort())) {
invokeContext.setPort(record.getPort());
}
if (record.getMiddlewareName() != null) {
invokeContext.setMiddlewareName(record.getMiddlewareName());
}
if (record.getCallbackMsg() != null) {
invokeContext.setCallBackMsg(record.getCallbackMsg());
}
endClientInvoke(record.getResultCode(), getPluginType(), advice);
} catch (Throwable e) {
/**
* 如果出错了,则强制将上下文提交
*/
endClientInvoke(ResultCode.INVOKE_RESULT_UNKNOWN, getPluginType(), advice);
throw e;
} finally {
advice.unMark(BEFORE_TRACE_SUCCESS);
}
}
Aggregations