use of org.apache.hc.core5.http.message.BasicHttpRequest in project skywalking-java by apache.
the class IOSessionImplPollInterceptor method afterMethod.
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
Command command = (Command) ret;
if (!(command instanceof RequestExecutionCommand)) {
return ret;
}
HttpContext httpContext = ((RequestExecutionCommand) command).getContext();
ContextSnapshot snapshot = (ContextSnapshot) httpContext.getAttribute(Constants.SKYWALKING_CONTEXT_SNAPSHOT);
if (snapshot == null) {
return ret;
}
httpContext.removeAttribute(Constants.SKYWALKING_CONTEXT_SNAPSHOT);
AbstractSpan localSpan = ContextManager.createLocalSpan("httpasyncclient/local");
localSpan.setComponent(ComponentsDefine.HTTP_ASYNC_CLIENT);
localSpan.setLayer(SpanLayer.HTTP);
ContextManager.continued(snapshot);
final ContextCarrier contextCarrier = new ContextCarrier();
BasicHttpRequest request = (BasicHttpRequest) httpContext.getAttribute(HttpClientContext.HTTP_REQUEST);
URI uri = request.getUri();
String operationName = uri.getPath();
int port = uri.getPort();
AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, uri.getHost() + ":" + (port == -1 ? 80 : port));
span.setComponent(ComponentsDefine.HTTP_ASYNC_CLIENT);
Tags.URL.set(span, uri.toURL().toString());
Tags.HTTP.METHOD.set(span, request.getMethod());
SpanLayer.asHttp(span);
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
request.setHeader(next.getHeadKey(), next.getHeadValue());
}
return ret;
}
Aggregations