Search in sources :

Example 1 with ClientRequestWrapper

use of com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestWrapper in project pinpoint by naver.

the class HttpRequestExecutorExecuteMethodInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    try {
        final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        final HttpRequest httpRequest = getHttpRequest(args);
        final NameIntValuePair<String> host = getHost();
        if (httpRequest != null) {
            ClientRequestWrapper clientRequest = new HttpClient4RequestWrapper(httpRequest, host.getName(), host.getValue());
            this.clientRequestRecorder.record(recorder, clientRequest, throwable);
            this.cookieRecorder.record(recorder, httpRequest, throwable);
        }
        if (statusCode) {
            final Integer statusCodeValue = getStatusCode(result);
            if (statusCodeValue != null) {
                recorder.recordAttribute(AnnotationKey.HTTP_STATUS_CODE, statusCodeValue);
            }
            recordResponseHeader(recorder, result);
        }
        recorder.recordApi(methodDescriptor);
        recorder.recordException(throwable);
        final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
        final Object attachment = getAttachment(invocation);
        if (attachment instanceof HttpCallContext) {
            final HttpCallContext callContext = (HttpCallContext) attachment;
            logger.debug("Check call context {}", callContext);
            if (io) {
                final IntBooleanIntBooleanValue value = new IntBooleanIntBooleanValue((int) callContext.getWriteElapsedTime(), callContext.isWriteFail(), (int) callContext.getReadElapsedTime(), callContext.isReadFail());
                recorder.recordAttribute(AnnotationKey.HTTP_IO, value);
            }
            // clear
            invocation.removeAttachment();
        }
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) HttpRequest(org.apache.http.HttpRequest) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) HttpCallContext(com.navercorp.pinpoint.plugin.httpclient4.HttpCallContext) ClientRequestWrapper(com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestWrapper) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) IntBooleanIntBooleanValue(com.navercorp.pinpoint.common.util.IntBooleanIntBooleanValue) HttpClient4RequestWrapper(com.navercorp.pinpoint.plugin.httpclient4.HttpClient4RequestWrapper)

Example 2 with ClientRequestWrapper

use of com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestWrapper in project pinpoint by naver.

the class Http1xClientConnectionCreateRequestInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    if (!trace.canSampled()) {
        if (result instanceof HttpRequest) {
            final HttpRequest request = (HttpRequest) result;
            requestTraceWriter.write(request);
        }
        return;
    }
    try {
        final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        recorder.recordApi(descriptor);
        recorder.recordException(throwable);
        recorder.recordServiceType(VertxConstants.VERTX_HTTP_CLIENT);
        if (!validate(args, result)) {
            return;
        }
        final HttpRequest request = (HttpRequest) result;
        final HttpHeaders headers = request.headers();
        if (headers == null) {
            return;
        }
        String host = ArrayArgumentUtils.getArgument(args, 4, String.class, "UNKNOWN");
        // generate next trace id.
        final TraceId nextId = trace.getTraceId().getNextTraceId();
        recorder.recordNextSpanId(nextId.getSpanId());
        requestTraceWriter.write(request, nextId, host);
        final ClientRequestWrapper clientRequest = new VertxHttpClientRequestWrapper(request, host);
        this.clientRequestRecorder.record(recorder, clientRequest, throwable);
        this.cookieRecorder.record(recorder, request, throwable);
    } catch (Throwable t) {
        if (logger.isWarnEnabled()) {
            logger.warn("AFTER. Caused:{}", t.getMessage(), t);
        }
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) HttpRequest(io.netty.handler.codec.http.HttpRequest) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) ClientRequestWrapper(com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestWrapper) VertxHttpClientRequestWrapper(com.navercorp.pinpoint.plugin.vertx.VertxHttpClientRequestWrapper) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) VertxHttpClientRequestWrapper(com.navercorp.pinpoint.plugin.vertx.VertxHttpClientRequestWrapper)

Example 3 with ClientRequestWrapper

use of com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestWrapper in project pinpoint by naver.

the class HttpClientStreamInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    try {
        final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        recorder.recordApi(descriptor);
        recorder.recordException(throwable);
        recorder.recordServiceType(VertxConstants.VERTX_HTTP_CLIENT);
        if (!validate(args)) {
            return;
        }
        final HttpRequest request = (HttpRequest) args[0];
        final HttpHeaders headers = request.headers();
        if (headers == null) {
            return;
        }
        final String host = (String) args[1];
        ClientRequestWrapper clientRequest = new VertxHttpClientRequestWrapper(request, host);
        this.clientRequestRecorder.record(recorder, clientRequest, throwable);
        this.cookieRecorder.record(recorder, request, throwable);
    } catch (Throwable t) {
        if (logger.isWarnEnabled()) {
            logger.warn("AFTER. Caused:{}", t.getMessage(), t);
        }
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) ClientRequestWrapper(com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestWrapper) VertxHttpClientRequestWrapper(com.navercorp.pinpoint.plugin.vertx.VertxHttpClientRequestWrapper) VertxHttpClientRequestWrapper(com.navercorp.pinpoint.plugin.vertx.VertxHttpClientRequestWrapper)

Example 4 with ClientRequestWrapper

use of com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestWrapper in project pinpoint by naver.

the class BodyInserterRequestBuilderWriteToInterceptor method doInAfterTrace.

@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
    recorder.recordApi(methodDescriptor);
    recorder.recordException(throwable);
    if (!validate(args)) {
        return;
    }
    final ClientHttpRequest request = (ClientHttpRequest) args[0];
    final ClientRequestWrapper clientRequestWrapper = new WebClientRequestWrapper(request);
    this.clientRequestRecorder.record(recorder, clientRequestWrapper, throwable);
    this.cookieRecorder.record(recorder, request, throwable);
    if (isAsync(result)) {
        // make asynchronous trace-id
        final AsyncContext asyncContext = recorder.recordNextAsyncContext();
        ((AsyncContextAccessor) result)._$PINPOINT$_setAsyncContext(asyncContext);
        if (isDebug) {
            logger.debug("Set closeable-AsyncContext {}", asyncContext);
        }
    }
}
Also used : ClientRequestWrapper(com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestWrapper) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext) ClientHttpRequest(org.springframework.http.client.reactive.ClientHttpRequest)

Example 5 with ClientRequestWrapper

use of com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestWrapper in project pinpoint by naver.

the class HttpClientOperationsSendInterceptor method doInBeforeTrace.

@Override
public void doInBeforeTrace(SpanEventRecorder recorder, AsyncContext asyncContext, Object target, Object[] args) {
    final Trace trace = asyncContext.currentAsyncTraceObject();
    if (trace == null) {
        if (logger.isWarnEnabled()) {
            logger.warn("Unexpected error, Current async trace is null");
        }
        return;
    }
    final TraceId nextId = trace.getTraceId().getNextTraceId();
    recorder.recordNextSpanId(nextId.getSpanId());
    recorder.recordServiceType(ReactorNettyConstants.REACTOR_NETTY_CLIENT);
    final HttpClientRequest request = (HttpClientRequest) target;
    final ClientRequestWrapper clientRequestWrapper = new HttpClientRequestWrapper(request);
    this.requestTraceWriter.write(request, nextId, clientRequestWrapper.getDestinationId());
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) HttpClientRequest(reactor.netty.http.client.HttpClientRequest) ClientRequestWrapper(com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestWrapper) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId)

Aggregations

ClientRequestWrapper (com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestWrapper)9 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)5 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)4 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)2 HttpClient4RequestWrapper (com.navercorp.pinpoint.plugin.httpclient4.HttpClient4RequestWrapper)2 VertxHttpClientRequestWrapper (com.navercorp.pinpoint.plugin.vertx.VertxHttpClientRequestWrapper)2 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)2 HttpRequest (io.netty.handler.codec.http.HttpRequest)2 HttpRequest (org.apache.http.HttpRequest)2 HttpClientRequest (reactor.netty.http.client.HttpClientRequest)2 AsyncContextAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor)1 AsyncContext (com.navercorp.pinpoint.bootstrap.context.AsyncContext)1 InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)1 IntBooleanIntBooleanValue (com.navercorp.pinpoint.common.util.IntBooleanIntBooleanValue)1 HttpClient3CallContext (com.navercorp.pinpoint.plugin.httpclient3.HttpClient3CallContext)1 HttpClient3RequestWrapper (com.navercorp.pinpoint.plugin.httpclient3.HttpClient3RequestWrapper)1 HttpCallContext (com.navercorp.pinpoint.plugin.httpclient4.HttpCallContext)1 HttpClientRequestWrapper (com.navercorp.pinpoint.plugin.vertx.HttpClientRequestWrapper)1 HttpClientRequest (io.vertx.core.http.HttpClientRequest)1 HttpConnection (org.apache.commons.httpclient.HttpConnection)1