use of com.pamirs.pradar.interceptor.SpanRecord in project LinkAgent by shulieTech.
the class HttpClientv4MethodInterceptor1 method exceptionTrace.
@Override
public SpanRecord exceptionTrace(Advice advice) {
Object[] args = advice.getParameterArray();
HttpRequest request = (HttpRequest) args[0];
SpanRecord record = new SpanRecord();
InnerWhiteListCheckUtil.check();
if (advice.getThrowable() instanceof SocketTimeoutException) {
record.setResultCode(ResultCode.INVOKE_RESULT_TIMEOUT);
} else {
record.setResultCode(ResultCode.INVOKE_RESULT_FAILED);
}
record.setResponse(advice.getThrowable());
try {
record.setRequest(getParameters(request));
} catch (Throwable e) {
}
return record;
}
use of com.pamirs.pradar.interceptor.SpanRecord in project LinkAgent by shulieTech.
the class HttpClientv4MethodInterceptor1 method afterTrace.
@Override
public SpanRecord afterTrace(Advice advice) {
Object[] args = advice.getParameterArray();
HttpUriRequest request = (HttpUriRequest) args[0];
SpanRecord record = new SpanRecord();
InnerWhiteListCheckUtil.check();
if (advice.getReturnObj() instanceof HttpResponse) {
HttpResponse response = (HttpResponse) advice.getReturnObj();
try {
record.setResponseSize(response == null ? 0 : response.getEntity().getContentLength());
} catch (Throwable e) {
record.setResponseSize(0);
}
int code = response.getStatusLine().getStatusCode();
record.setResultCode(code + "");
} else {
record.setResponse(advice.getReturnObj());
}
try {
if (request.getHeaders(HeaderMark.DONT_READ_INPUT) == null || request.getHeaders(HeaderMark.DONT_READ_INPUT).length == 0) {
record.setRequest(getParameters(request));
}
} catch (Throwable e) {
}
return record;
}
use of com.pamirs.pradar.interceptor.SpanRecord in project LinkAgent by shulieTech.
the class HttpClientv5MethodInterceptor method exceptionTrace.
@Override
public SpanRecord exceptionTrace(Advice advice) {
Object[] args = advice.getParameterArray();
HttpRequest request = (HttpRequest) args[1];
SpanRecord record = new SpanRecord();
if (advice.getThrowable() instanceof SocketTimeoutException) {
record.setResultCode(ResultCode.INVOKE_RESULT_TIMEOUT);
} else {
record.setResultCode(ResultCode.INVOKE_RESULT_FAILED);
}
try {
record.setRequest(getParameters(request));
} catch (Throwable e) {
}
record.setResponse(advice.getThrowable());
return record;
}
use of com.pamirs.pradar.interceptor.SpanRecord in project LinkAgent by shulieTech.
the class HttpClientv5MethodInterceptor method beforeTrace.
@Override
public SpanRecord beforeTrace(Advice advice) {
Object[] args = advice.getParameterArray();
HttpHost httpHost = (HttpHost) args[0];
final HttpRequest request = (HttpRequest) args[1];
if (httpHost == null) {
return null;
}
URI uri = null;
try {
uri = request.getUri();
} catch (URISyntaxException e) {
logger.error("获取不到url", e);
}
String host = httpHost.getHostName();
int port = httpHost.getPort();
String path = uri.getPath();
SpanRecord record = new SpanRecord();
record.setService(path);
String reqStr = request.toString();
String httpType = StringUtils.upperCase(reqStr.substring(0, reqStr.indexOf(" ")));
record.setMethod(httpType);
record.setRemoteIp(host);
record.setPort(port);
record.setMiddlewareName(HttpClientConstants.HTTP_CLIENT_NAME_5X);
Header[] headers = request.getHeaders("content-length");
if (headers != null && headers.length != 0) {
try {
Header header = headers[0];
record.setRequestSize(Integer.valueOf(header.getValue()));
} catch (NumberFormatException e) {
}
}
record.setRemoteIp(httpHost.getHostName());
return record;
}
use of com.pamirs.pradar.interceptor.SpanRecord in project LinkAgent by shulieTech.
the class HttpClientv5MethodInterceptor1 method beforeTrace.
@Override
public SpanRecord beforeTrace(Advice advice) {
Object[] args = advice.getParameterArray();
final HttpRequest request = (HttpRequest) args[0];
if (request == null) {
return null;
}
URI uri = null;
try {
uri = request.getUri();
} catch (URISyntaxException e) {
logger.error("获取不到url", e);
}
String host = uri.getHost();
int port = uri.getPort();
String path = uri.getPath();
SpanRecord record = new SpanRecord();
record.setService(path);
String method = request.getMethod();
record.setMethod(method);
record.setRemoteIp(host);
record.setPort(port);
record.setMiddlewareName(HttpClientConstants.HTTP_CLIENT_NAME_5X);
Header[] headers = request.getHeaders("content-length");
if (headers != null && headers.length != 0) {
try {
Header header = headers[0];
record.setRequestSize(Integer.valueOf(header.getValue()));
} catch (NumberFormatException e) {
}
}
// OSS 使用httpclient的时候会验证crc,提前读取request的stream流导致crc验证无法通过,先注释
return record;
}
Aggregations