Search in sources :

Example 1 with HttpCallContext

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

the class HttpClientExecuteMethodInternalInterceptor method needGetStatusCode.

private boolean needGetStatusCode() {
    if (isHasCallbackParam) {
        return false;
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return false;
    }
    // TODO fix me.
    // if (trace.getServiceType() != ServiceType.ASYNC_HTTP_CLIENT.getCode()) {
    // return false;
    // }
    final InterceptorScopeInvocation transaction = interceptorScope.getCurrentInvocation();
    final Object attachment = getAttachment(transaction);
    if (attachment instanceof HttpCallContext) {
        return false;
    }
    return true;
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) HttpCallContext(com.navercorp.pinpoint.plugin.httpclient4.HttpCallContext)

Example 2 with HttpCallContext

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

the class HttpRequestExecutorDoSendRequestAndDoReceiveResponseMethodInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
    final Object attachment = getAttachment(invocation);
    if (attachment instanceof HttpCallContext) {
        HttpCallContext callContext = (HttpCallContext) attachment;
        if (methodDescriptor.getMethodName().equals("doSendRequest")) {
            callContext.setWriteBeginTime(System.currentTimeMillis());
        } else {
            callContext.setReadBeginTime(System.currentTimeMillis());
        }
        if (isDebug) {
            logger.debug("Set call context {}", callContext);
        }
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) HttpCallContext(com.navercorp.pinpoint.plugin.httpclient4.HttpCallContext)

Example 3 with HttpCallContext

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

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

the class HttpRequestExecutorExecuteMethodInterceptor method getHost.

private NameIntValuePair<String> getHost() {
    final InterceptorScopeInvocation transaction = interceptorScope.getCurrentInvocation();
    final Object attachment = getAttachment(transaction);
    if (attachment instanceof HttpCallContext) {
        HttpCallContext callContext = (HttpCallContext) attachment;
        return new NameIntValuePair<>(callContext.getHost(), callContext.getPort());
    }
    return new NameIntValuePair<>(null, -1);
}
Also used : InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) HttpCallContext(com.navercorp.pinpoint.plugin.httpclient4.HttpCallContext) NameIntValuePair(com.navercorp.pinpoint.bootstrap.pair.NameIntValuePair)

Example 5 with HttpCallContext

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

the class AbstractHttpClientExecuteMethodInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    final SpanEventRecorder recorder = trace.traceBlockBegin();
    recorder.recordServiceType(HttpClient4Constants.HTTP_CLIENT_4_INTERNAL);
    final NameIntValuePair<String> host = getHost(args);
    if (host != null) {
        final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
        if (invocation != null) {
            final HttpCallContext callContext = (HttpCallContext) invocation.getOrCreateAttachment(HttpCallContextFactory.HTTPCALL_CONTEXT_FACTORY);
            callContext.setHost(host.getName());
            callContext.setPort(host.getValue());
        }
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) HttpCallContext(com.navercorp.pinpoint.plugin.httpclient4.HttpCallContext) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)

Aggregations

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