Search in sources :

Example 91 with BasicHttpRequest

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;
}
Also used : ContextSnapshot(org.apache.skywalking.apm.agent.core.context.ContextSnapshot) ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) Command(org.apache.hc.core5.reactor.Command) RequestExecutionCommand(org.apache.hc.core5.http.nio.command.RequestExecutionCommand) HttpContext(org.apache.hc.core5.http.protocol.HttpContext) RequestExecutionCommand(org.apache.hc.core5.http.nio.command.RequestExecutionCommand) URI(java.net.URI) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Aggregations

HttpRequest (org.apache.hc.core5.http.HttpRequest)75 BasicHttpRequest (org.apache.hc.core5.http.message.BasicHttpRequest)68 Test (org.junit.jupiter.api.Test)47 HttpResponse (org.apache.hc.core5.http.HttpResponse)41 BasicRequestProducer (org.apache.hc.core5.http.nio.support.BasicRequestProducer)37 Message (org.apache.hc.core5.http.Message)34 StringAsyncEntityConsumer (org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer)33 InetSocketAddress (java.net.InetSocketAddress)30 HttpHost (org.apache.hc.core5.http.HttpHost)30 Test (org.junit.Test)30 URI (java.net.URI)23 HttpException (org.apache.hc.core5.http.HttpException)21 IOException (java.io.IOException)20 BasicHttpResponse (org.apache.hc.core5.http.message.BasicHttpResponse)19 URIAuthority (org.apache.hc.core5.net.URIAuthority)17 InterruptedIOException (java.io.InterruptedIOException)16 HttpContext (org.apache.hc.core5.http.protocol.HttpContext)15 Header (org.apache.hc.core5.http.Header)14 URISyntaxException (java.net.URISyntaxException)8 ContentType (org.apache.hc.core5.http.ContentType)8