Search in sources :

Example 21 with InterceptorScopeInvocation

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

the class DefaultScopeTest method testAttachment3.

@Test
public void testAttachment3() {
    String oldAttachment = "context";
    String newAttachment = "newnew";
    InterceptorScopeInvocation transaction = new DefaultInterceptorScopeInvocation("test");
    transaction.tryEnter(ExecutionPolicy.ALWAYS);
    transaction.setAttachment(oldAttachment);
    assertSame(oldAttachment, transaction.getAttachment());
    assertSame(oldAttachment, transaction.setAttachment(newAttachment));
    assertSame(newAttachment, transaction.getAttachment());
    assertSame(newAttachment, transaction.removeAttachment());
    assertNull(transaction.getAttachment());
    transaction.canLeave(ExecutionPolicy.ALWAYS);
    transaction.leave(ExecutionPolicy.ALWAYS);
}
Also used : DefaultInterceptorScopeInvocation(com.navercorp.pinpoint.profiler.interceptor.scope.DefaultInterceptorScopeInvocation) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) DefaultInterceptorScopeInvocation(com.navercorp.pinpoint.profiler.interceptor.scope.DefaultInterceptorScopeInvocation) Test(org.junit.Test)

Example 22 with InterceptorScopeInvocation

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

the class DefaultScopeTest method testAfterWithoutBefore3.

@Test(expected = IllegalStateException.class)
public void testAfterWithoutBefore3() {
    InterceptorScopeInvocation transaction = new DefaultInterceptorScopeInvocation("test");
    transaction.leave(ExecutionPolicy.INTERNAL);
}
Also used : DefaultInterceptorScopeInvocation(com.navercorp.pinpoint.profiler.interceptor.scope.DefaultInterceptorScopeInvocation) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) DefaultInterceptorScopeInvocation(com.navercorp.pinpoint.profiler.interceptor.scope.DefaultInterceptorScopeInvocation) Test(org.junit.Test)

Example 23 with InterceptorScopeInvocation

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

the class DefaultScopeTest method testSetAttachmentFail2.

@Test(expected = IllegalStateException.class)
public void testSetAttachmentFail2() {
    InterceptorScopeInvocation transaction = new DefaultInterceptorScopeInvocation("test");
    transaction.tryEnter(ExecutionPolicy.ALWAYS);
    transaction.canLeave(ExecutionPolicy.ALWAYS);
    transaction.leave(ExecutionPolicy.ALWAYS);
    transaction.setAttachment("attachment");
}
Also used : DefaultInterceptorScopeInvocation(com.navercorp.pinpoint.profiler.interceptor.scope.DefaultInterceptorScopeInvocation) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) DefaultInterceptorScopeInvocation(com.navercorp.pinpoint.profiler.interceptor.scope.DefaultInterceptorScopeInvocation) Test(org.junit.Test)

Example 24 with InterceptorScopeInvocation

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

the class HttpRequestExecutorDoSendRequestAndDoReceiveResponseMethodInterceptor 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;
    }
    final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
    if (invocation != null && invocation.getAttachment() != null && invocation.getAttachment() instanceof HttpCallContext) {
        HttpCallContext callContext = (HttpCallContext) invocation.getAttachment();
        if (methodDescriptor.getMethodName().equals("doSendRequest")) {
            callContext.setWriteEndTime(System.currentTimeMillis());
            callContext.setWriteFail(throwable != null);
        } else {
            callContext.setReadEndTime(System.currentTimeMillis());
            callContext.setReadFail(throwable != null);
        }
        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 25 with InterceptorScopeInvocation

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

the class HttpClientExecuteMethodInternalInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, target.getClass().getName(), "", "internal", args);
    }
    if (!needGetStatusCode()) {
        return;
    }
    if (result != null && result instanceof HttpResponse) {
        HttpResponse response = (HttpResponse) result;
        if (response.getStatusLine() != null) {
            HttpCallContext context = new HttpCallContext();
            final StatusLine statusLine = response.getStatusLine();
            if (statusLine != null) {
                context.setStatusCode(statusLine.getStatusCode());
                InterceptorScopeInvocation transaction = interceptorScope.getCurrentInvocation();
                if (transaction != null && transaction.getAttachment() == null) {
                    transaction.setAttachment(context);
                }
            }
        }
    }
}
Also used : HttpCallContext(com.navercorp.pinpoint.plugin.httpclient4.HttpCallContext) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)

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