Search in sources :

Example 1 with AsyncContext

use of com.navercorp.pinpoint.bootstrap.context.AsyncContext in project pinpoint by naver.

the class AsyncContextAccessorUtilsTest method getAsyncContext_null.

@Test
public void getAsyncContext_null() {
    Object[] args = null;
    AsyncContext asyncContext = AsyncContextAccessorUtils.getAsyncContext(args, 0);
    Assert.assertNull(asyncContext);
}
Also used : AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext) Test(org.junit.Test)

Example 2 with AsyncContext

use of com.navercorp.pinpoint.bootstrap.context.AsyncContext in project pinpoint by naver.

the class AsyncContextAccessorUtilsTest method getAsyncContext.

@Test
public void getAsyncContext() {
    AsyncContextAccessor accessorMock = mock(AsyncContextAccessor.class);
    when(accessorMock._$PINPOINT$_getAsyncContext()).thenReturn(mock(AsyncContext.class));
    Object[] args = { accessorMock };
    AsyncContext asyncContext = AsyncContextAccessorUtils.getAsyncContext(args, 0);
    Assert.assertNotNull(asyncContext);
}
Also used : AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext) Test(org.junit.Test)

Example 3 with AsyncContext

use of com.navercorp.pinpoint.bootstrap.context.AsyncContext in project pinpoint by naver.

the class HttpRequestExecuteAsyncMethodInterceptor method doInBeforeTrace.

@Override
protected void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[] args) {
    // set asynchronous trace
    final AsyncContext asyncContext = recorder.recordNextAsyncContext();
    final InterceptorScopeInvocation transaction = interceptorScope.getCurrentInvocation();
    if (transaction != null) {
        transaction.setAttachment(asyncContext);
        if (isDebug) {
            logger.debug("Set AsyncContext {}", asyncContext);
        }
    }
}
Also used : InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Example 4 with AsyncContext

use of com.navercorp.pinpoint.bootstrap.context.AsyncContext in project pinpoint by naver.

the class MQExternalClientHandlerInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    final AsyncContext asyncContext = getAsyncContext(args);
    if (asyncContext == null) {
        return;
    }
    final Trace trace = asyncContext.currentAsyncTraceObject();
    if (trace == null) {
        return;
    }
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    // leave scope.
    if (!leaveAsyncTraceScope(trace)) {
        if (logger.isWarnEnabled()) {
            logger.warn("Failed to leave scope of async trace {}.", trace);
        }
        // delete unstable trace.
        deleteAsyncContext(trace, asyncContext);
        return;
    }
    try {
        final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        if (throwable != null) {
            recorder.recordException(throwable);
        }
    } catch (Throwable th) {
        if (logger.isWarnEnabled()) {
            logger.warn("AFTER error. Caused:{}", th.getMessage(), th);
        }
    } finally {
        trace.traceBlockEnd();
        if (isAsyncTraceDestination(trace)) {
            deleteAsyncContext(trace, asyncContext);
        }
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Example 5 with AsyncContext

use of com.navercorp.pinpoint.bootstrap.context.AsyncContext in project pinpoint by naver.

the class ASMClassNodeAdapterTest method addField_transient.

@Test
public void addField_transient() throws Exception {
    final String baseClassName = "com.navercorp.pinpoint.profiler.instrument.mock.SerializableClass";
    final Class<AsyncContext> asyncContextClass = AsyncContext.class;
    final String accessorClassName = asyncContextClass.getName();
    final ASMClassNodeLoader.TestClassLoader classLoader = ASMClassNodeLoader.getClassLoader();
    classLoader.setTargetClassName(baseClassName);
    classLoader.setCallbackHandler(new ASMClassNodeLoader.CallbackHandler() {

        @Override
        public void handle(ClassNode classNode) {
            ASMClassNodeAdapter classNodeAdapter = new ASMClassNodeAdapter(pluginClassInputStreamProvider, null, getClass().getProtectionDomain(), classNode);
            classNodeAdapter.addField("_$PINPOINT$_" + JavaAssistUtils.javaClassNameToVariableName(accessorClassName), Type.getDescriptor(asyncContextClass));
            classNodeAdapter.addInterface(accessorClassName);
            ASMFieldNodeAdapter fieldNode = classNodeAdapter.getField("_$PINPOINT$_" + JavaAssistUtils.javaClassNameToVariableName(accessorClassName), null);
            classNodeAdapter.addGetterMethod("_$PINPOINT$_getAsyncContext", fieldNode);
            classNodeAdapter.addSetterMethod("_$PINPOINT$_setAsyncContext", fieldNode);
        }
    });
    Class<?> baseClazz = classLoader.loadClass(baseClassName);
    Object instance = baseClazz.newInstance();
    AsyncContext asyncContext = new MockAsyncContext();
    Method setMethod = baseClazz.getDeclaredMethod("_$PINPOINT$_setAsyncContext", asyncContextClass);
    setMethod.invoke(instance, asyncContext);
    Method getMethod = baseClazz.getDeclaredMethod("_$PINPOINT$_getAsyncContext");
    AsyncContext result = (AsyncContext) getMethod.invoke(instance);
    JavaSerializableUtils.serialize(instance);
    logger.debug("{}", result);
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) MockAsyncContext(com.navercorp.pinpoint.profiler.instrument.mock.accessor.MockAsyncContext) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext) Method(java.lang.reflect.Method) MockAsyncContext(com.navercorp.pinpoint.profiler.instrument.mock.accessor.MockAsyncContext) Test(org.junit.Test)

Aggregations

AsyncContext (com.navercorp.pinpoint.bootstrap.context.AsyncContext)68 AsyncContextAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor)44 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)31 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)28 Test (org.junit.Test)7 AsyncState (com.navercorp.pinpoint.bootstrap.context.AsyncState)2 InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)2 NormalizedBson (com.navercorp.pinpoint.plugin.mongo.NormalizedBson)2 HttpServerResponse (io.vertx.core.http.HttpServerResponse)2 Method (java.lang.reflect.Method)2 Continuation (kotlin.coroutines.Continuation)2 RequestContextImpl (akka.http.scaladsl.server.RequestContextImpl)1 AsyncStateSupport (com.navercorp.pinpoint.bootstrap.context.AsyncStateSupport)1 SpanRecorder (com.navercorp.pinpoint.bootstrap.context.SpanRecorder)1 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)1 ClientRequestWrapper (com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestWrapper)1 OperationAccessor (com.navercorp.pinpoint.plugin.arcus.OperationAccessor)1 ServiceCodeAccessor (com.navercorp.pinpoint.plugin.arcus.ServiceCodeAccessor)1 AsyncStartFlagFieldAccessor (com.navercorp.pinpoint.plugin.netty.field.accessor.AsyncStartFlagFieldAccessor)1 TraceFutureFlagAccessor (com.navercorp.pinpoint.plugin.resttemplate.field.accessor.TraceFutureFlagAccessor)1