use of com.creditease.uav.apm.invokechain.span.Span in project uavstack by uavorg.
the class ApacheAsyncHttpClientAdapter method afterDoCap.
@Override
public void afterDoCap(InvokeChainContext context, Object[] args) {
if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
Span span = (Span) context.get(InvokeChainConstants.PARAM_SPAN_KEY);
SlowOperContext slowOperContext = new SlowOperContext();
if (args[0] != null) {
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_EXCEPTION, args[0].toString());
} else if (Exception.class.isAssignableFrom(args[1].getClass())) {
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_EXCEPTION, args[1].toString());
} else if (HttpResponse.class.isAssignableFrom(args[1].getClass())) {
HttpResponse response = (HttpResponse) args[1];
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_HEADER, getResponHeaders(response));
HttpEntity entity = response.getEntity();
// 由于存在读取失败和无法缓存的大entity会使套壳失败,故此处添加如下判断
if (BufferedHttpEntity.class.isAssignableFrom(entity.getClass())) {
Header header = entity.getContentEncoding();
String encoding = header == null ? "utf-8" : header.getValue();
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_BODY, getHttpEntityContent(entity, encoding));
} else {
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_BODY, "HttpEntityWrapper failed! Maybe HTTP entity too large to be buffered in memory");
}
} else {
HttpResponse response = (HttpResponse) args[1];
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_HEADER, getResponHeaders(response));
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_BODY, "unsupported response");
}
Object[] params = { span, slowOperContext };
UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.SlowOperSupporter", "runCap", span.getEndpointInfo().split(",")[0], InvokeChainConstants.CapturePhase.DOCAP, context, params);
}
}
use of com.creditease.uav.apm.invokechain.span.Span in project uavstack by uavorg.
the class ApacheHttpClientAdapter method afterDoCap.
@Override
public void afterDoCap(InvokeChainContext context, Object[] args) {
if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
Span span = (Span) context.get(InvokeChainConstants.PARAM_SPAN_KEY);
SlowOperContext slowOperContext = new SlowOperContext();
if (Throwable.class.isAssignableFrom(args[0].getClass())) {
Throwable e = (Throwable) args[0];
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_EXCEPTION, e.toString());
} else {
HttpResponse response = (HttpResponse) args[0];
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_HEADER, getResponHeaders(response));
HttpEntity entity = response.getEntity();
// 由于存在读取失败和无法缓存的大entity会使套壳失败,故此处添加如下判断
if (BufferedHttpEntity.class.isAssignableFrom(entity.getClass())) {
Header header = entity.getContentEncoding();
String encoding = header == null ? "utf-8" : header.getValue();
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_BODY, getHttpEntityContent(entity, encoding));
} else {
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_BODY, "HttpEntityWrapper failed! Maybe HTTP entity too large to be buffered in memory");
}
}
Object[] params = { span, slowOperContext };
UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.SlowOperSupporter", "runCap", span.getEndpointInfo().split(",")[0], InvokeChainConstants.CapturePhase.DOCAP, context, params);
}
}
use of com.creditease.uav.apm.invokechain.span.Span in project uavstack by uavorg.
the class ApacheHttpClientAdapter method afterPreCap.
@Override
public void afterPreCap(InvokeChainContext context, Object[] args) {
if (args.length < 2) {
return;
}
/**
* after precap the client's span is created, set the span meta into http request header
*/
String url = (String) context.get(InvokeChainConstants.CLIENT_SPAN_THREADLOCAL_STOREKEY);
Span span = this.spanFactory.getSpanFromContext(url);
String spanMeta = this.spanFactory.getSpanMeta(span);
HttpRequest request = (HttpRequest) args[1];
request.removeHeaders(InvokeChainConstants.PARAM_HTTPHEAD_SPANINFO);
request.addHeader(InvokeChainConstants.PARAM_HTTPHEAD_SPANINFO, spanMeta);
handleSlowOperSupporter(request, span, context);
}
use of com.creditease.uav.apm.invokechain.span.Span in project uavstack by uavorg.
the class ApacheHttpClient3Adapter method afterPreCap.
@Override
public void afterPreCap(InvokeChainContext context, Object[] args) {
/**
* after precap the client's span is created, set the span meta into http request header
*/
String url = (String) context.get(InvokeChainConstants.CLIENT_SPAN_THREADLOCAL_STOREKEY);
Span span = this.spanFactory.getSpanFromContext(url);
String spanMeta = this.spanFactory.getSpanMeta(span);
HttpMethod method = (HttpMethod) args[1];
method.removeRequestHeader(InvokeChainConstants.PARAM_HTTPHEAD_SPANINFO);
method.addRequestHeader(InvokeChainConstants.PARAM_HTTPHEAD_SPANINFO, spanMeta);
if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
// httpclient3好像没有encoding参数
SlowOperContext slowOperContext = new SlowOperContext();
String quertParams = method.getQueryString();
if (quertParams == null) {
quertParams = "{}";
}
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_HEADER, getHeadersContent(method.getRequestHeaders()) + quertParams);
// 通过此种方式判断是否存在body,通过httpclient类继承确定
String requestBody = "";
if (EntityEnclosingMethod.class.isAssignableFrom(method.getClass())) {
EntityEnclosingMethod entityMethod = (EntityEnclosingMethod) method;
RequestEntity requestEntity = entityMethod.getRequestEntity();
// 根据不同类型entity采取不同读取方式(由于httpclient3没有显视encoding,故此处使用默认的编码格式)
if (ByteArrayRequestEntity.class.isAssignableFrom(requestEntity.getClass())) {
requestBody = new String(((ByteArrayRequestEntity) requestEntity).getContent());
} else if (InputStreamRequestEntity.class.isAssignableFrom(requestEntity.getClass())) {
InputStreamRequestEntity inputStreamRequestEntity = (InputStreamRequestEntity) requestEntity;
if (!inputStreamRequestEntity.isRepeatable()) {
inputStreamRequestEntity.getContentLength();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStreamRequestEntity.getContent()));
StringBuilder body = new StringBuilder();
String str;
while ((str = reader.readLine()) != null) {
body.append(str);
}
requestBody = body.toString();
} catch (UnsupportedOperationException e) {
logger.warn("body type is not supported!", e);
requestBody = "body type is not supported!" + e.toString();
} catch (IOException e) {
logger.error("IOException!", e);
requestBody = e.toString();
}
} else if (MultipartRequestEntity.class.isAssignableFrom(requestEntity.getClass())) {
// MultipartRequestEntity暂时不支持
requestBody = "MultipartRequestEntity is not supported";
} else if (StringRequestEntity.class.isAssignableFrom(requestEntity.getClass())) {
requestBody = ((StringRequestEntity) requestEntity).getContent();
} else {
requestBody = "unsupported type";
}
}
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_BODY, requestBody);
Object[] params = { span, slowOperContext };
UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.SlowOperSupporter", "runCap", span.getEndpointInfo().split(",")[0], InvokeChainConstants.CapturePhase.PRECAP, context, params);
}
}
use of com.creditease.uav.apm.invokechain.span.Span in project uavstack by uavorg.
the class ApacheHttpClient3Adapter method afterDoCap.
@Override
public void afterDoCap(InvokeChainContext context, Object[] args) {
if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
Span span = (Span) context.get(InvokeChainConstants.PARAM_SPAN_KEY);
SlowOperContext slowOperContext = new SlowOperContext();
if (Throwable.class.isAssignableFrom(args[0].getClass())) {
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_EXCEPTION, args[0].toString());
} else {
HttpMethod method = (HttpMethod) args[0];
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_HEADER, getHeadersContent(method.getRequestHeaders()));
try {
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_BODY, method.getResponseBodyAsString());
} catch (IOException e) {
slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_EXCEPTION, e.toString());
}
}
Object[] params = { span, slowOperContext };
UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.SlowOperSupporter", "runCap", span.getEndpointInfo().split(",")[0], InvokeChainConstants.CapturePhase.DOCAP, context, params);
}
}
Aggregations