Search in sources :

Example 11 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation 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)

Example 12 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.

the class AbstractHttpClientExecuteMethodInterceptor 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();
        recorder.recordApi(descriptor);
        recorder.recordException(throwable);
        final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
        if (invocation != null) {
            // clear
            invocation.removeAttachment();
        }
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)

Example 13 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation 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;
    //        }
    InterceptorScopeInvocation transaction = interceptorScope.getCurrentInvocation();
    if (transaction != null && transaction.getAttachment() != null && transaction.getAttachment() 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 14 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.

the class HttpMethodBaseRequestAndResponseMethodInterceptor method before.

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

Example 15 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.

the class HttpRequestExecuteAsyncMethodInterceptor 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;
    }
    SpanEventRecorder recorder = trace.traceBlockBegin();
    try {
        // set asynchronous trace
        final AsyncTraceId asyncTraceId = trace.getAsyncTraceId();
        recorder.recordNextAsyncId(asyncTraceId.getAsyncId());
        // set async id.
        InterceptorScopeInvocation transaction = interceptorScope.getCurrentInvocation();
        if (transaction != null) {
            transaction.setAttachment(asyncTraceId);
            if (isDebug) {
                logger.debug("Set asyncTraceId metadata {}", asyncTraceId);
            }
        }
    } catch (Throwable t) {
        logger.warn("Failed to before process. {}", t.getMessage(), t);
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId)

Aggregations

InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)53 Test (org.junit.Test)20 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)15 DefaultInterceptorScopeInvocation (com.navercorp.pinpoint.profiler.interceptor.scope.DefaultInterceptorScopeInvocation)15 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)8 ThriftClientCallContext (com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext)7 DefaultInterceptorScopeDefinition (com.navercorp.pinpoint.bootstrap.instrument.DefaultInterceptorScopeDefinition)6 HttpCallContext (com.navercorp.pinpoint.plugin.httpclient4.HttpCallContext)6 ThriftRequestProperty (com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty)5 CommandContext (com.navercorp.pinpoint.plugin.redis.CommandContext)4 ServerMarkerFlagFieldAccessor (com.navercorp.pinpoint.plugin.thrift.field.accessor.ServerMarkerFlagFieldAccessor)4 AsyncTraceId (com.navercorp.pinpoint.bootstrap.context.AsyncTraceId)3 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)3 Request (com.squareup.okhttp.Request)3 AttachmentFactory (com.navercorp.pinpoint.bootstrap.interceptor.scope.AttachmentFactory)2 HttpClient3CallContext (com.navercorp.pinpoint.plugin.httpclient3.HttpClient3CallContext)2 EndPointAccessor (com.navercorp.pinpoint.plugin.redis.EndPointAccessor)2 HttpRequest (org.apache.http.HttpRequest)2 AsyncTraceIdAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)1 UrlGetter (com.navercorp.pinpoint.plugin.okhttp.UrlGetter)1