Search in sources :

Example 1 with HttpClient4RequestWrapper

use of com.navercorp.pinpoint.plugin.httpclient4.HttpClient4RequestWrapper 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 HttpClient4RequestWrapper

use of com.navercorp.pinpoint.plugin.httpclient4.HttpClient4RequestWrapper in project pinpoint by naver.

the class DefaultClientExchangeHandlerImplStartMethodInterceptor 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 {
        SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        final HttpRequest httpRequest = getHttpRequest(target);
        final NameIntValuePair<String> host = getHost(target);
        if (httpRequest != null) {
            // Accessing httpRequest here not BEFORE() because it can cause side effect.
            ClientRequestWrapper clientRequest = new HttpClient4RequestWrapper(httpRequest, host.getName(), host.getValue());
            this.clientRequestRecorder.record(recorder, clientRequest, throwable);
            this.cookieRecorder.record(recorder, httpRequest, throwable);
            this.entityRecorder.record(recorder, httpRequest, throwable);
        }
        recorder.recordApi(methodDescriptor);
        recorder.recordException(throwable);
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) HttpRequest(org.apache.http.HttpRequest) ClientRequestWrapper(com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestWrapper) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) HttpClient4RequestWrapper(com.navercorp.pinpoint.plugin.httpclient4.HttpClient4RequestWrapper)

Aggregations

SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)2 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)2 ClientRequestWrapper (com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestWrapper)2 HttpClient4RequestWrapper (com.navercorp.pinpoint.plugin.httpclient4.HttpClient4RequestWrapper)2 HttpRequest (org.apache.http.HttpRequest)2 InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)1 IntBooleanIntBooleanValue (com.navercorp.pinpoint.common.util.IntBooleanIntBooleanValue)1 HttpCallContext (com.navercorp.pinpoint.plugin.httpclient4.HttpCallContext)1