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);
}
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);
}
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);
}
}
}
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);
}
}
}
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);
}
Aggregations