use of com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor in project pinpoint by naver.
the class ProducerSendInterceptor method before.
@Override
public void before(Object target, Object[] args) {
if (isDebug) {
logger.beforeInterceptor(target, args);
}
try {
Trace trace = traceContext.currentTraceObject();
final AsyncContextAccessor sendCallback = getSendCallback(args);
// async send process
if (sendCallback != null) {
if (isSkipTrace()) {
return;
}
final AsyncContext asyncContext = ((AsyncContextAccessor) sendCallback)._$PINPOINT$_getAsyncContext();
if (asyncContext == null) {
logger.debug("Skip rocketmq produce trace");
return;
}
// create async trace
trace = asyncContext.continueAsyncTraceObject();
if (isDebug) {
logger.debug("Created trace. trace={}", trace);
}
if (trace == null) {
// Skip
return;
}
// init entry point scope
if (!initScope(trace)) {
// Defense code
deleteTrace(trace);
return;
}
// entry point scope
entryScope(trace);
}
if (trace == null) {
return;
}
if (!trace.canSampled()) {
return;
}
final SpanEventRecorder recorder = trace.traceBlockBegin();
doInBeforeTrace(recorder, target, args);
} catch (Throwable th) {
if (logger.isWarnEnabled()) {
logger.warn("BEFORE. Caused:{}", th.getMessage(), th);
}
}
}
use of com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor in project pinpoint by naver.
the class CommandAsyncServiceMethodInterceptor method doInBeforeTrace.
@Override
public void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[] args) {
try {
AsyncContextAccessor asynchronousInvocation = getAsynchronousInvocation(target, args);
if (asynchronousInvocation != null) {
// set asynchronous trace
final AsyncContext asyncContext = recorder.recordNextAsyncContext();
// type check isAsynchronousInvocation
asynchronousInvocation._$PINPOINT$_setAsyncContext(asyncContext);
if (isDebug) {
logger.debug("Set AsyncContext {}", asyncContext);
}
}
} catch (Throwable t) {
logger.warn("Failed to BEFORE process. {}", t.getMessage(), t);
}
}
use of com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor in project pinpoint by naver.
the class ApiInterceptor method after.
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
if (isDebug) {
logger.afterInterceptor(target, args, result, throwable);
}
final Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
try {
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
if (traceKey) {
final Object recordObject = args[keyIndex];
recorder.recordApi(methodDescriptor, recordObject, keyIndex);
} else {
recorder.recordApi(methodDescriptor);
}
recorder.recordException(throwable);
// find the target node
if (result instanceof Future && result instanceof OperationAccessor) {
final Operation op = ((OperationAccessor) result)._$PINPOINT$_getOperation();
if (op != null) {
final MemcachedNode handlingNode = op.getHandlingNode();
if (handlingNode != null) {
final String endPoint = getEndPoint(handlingNode);
if (endPoint != null) {
recorder.recordEndPoint(endPoint);
}
}
} else {
logger.info("operation not found");
}
}
if (target instanceof ServiceCodeAccessor) {
// determine the service type
String serviceCode = ((ServiceCodeAccessor) target)._$PINPOINT$_getServiceCode();
if (serviceCode != null) {
recorder.recordDestinationId(serviceCode);
recorder.recordServiceType(ArcusConstants.ARCUS);
} else {
recorder.recordDestinationId("MEMCACHED");
recorder.recordServiceType(ArcusConstants.MEMCACHED);
}
} else {
recorder.recordDestinationId("MEMCACHED");
recorder.recordServiceType(ArcusConstants.MEMCACHED);
}
try {
if (isAsynchronousInvocation(target, args, result, throwable)) {
// set asynchronous trace
final AsyncContext asyncContext = recorder.recordNextAsyncContext();
// type check isAsynchronousInvocation
((AsyncContextAccessor) result)._$PINPOINT$_setAsyncContext(asyncContext);
if (isDebug) {
logger.debug("Set AsyncContext {}", asyncContext);
}
}
} catch (Throwable t) {
logger.warn("Failed to BEFORE process. {}", t.getMessage(), t);
}
} catch (Throwable th) {
if (logger.isWarnEnabled()) {
logger.warn("AFTER error. Caused:{}", th.getMessage(), th);
}
} finally {
trace.traceBlockEnd();
}
}
use of com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor in project pinpoint by naver.
the class AsyncEntryInterceptor method after.
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
if (isDebug) {
logger.afterInterceptor(target, args, result, throwable);
}
final Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
try {
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
recorder.recordApi(this.descriptor);
recorder.recordServiceType(AgentSdkAsyncConstants.AGENT_SDK_ASYNC);
recorder.recordException(throwable);
boolean r = validate(result);
if (r) {
// make asynchronous trace-id
final AsyncContext asyncContext = recorder.recordNextAsyncContext();
((AsyncContextAccessor) result)._$PINPOINT$_setAsyncContext(asyncContext);
if (isDebug) {
logger.debug("Set asyncContext {}", asyncContext);
}
}
} finally {
trace.traceBlockEnd();
}
}
use of com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor in project pinpoint by naver.
the class ExecutorExecuteInterceptor 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();
AsyncContextAccessor accessor = getAsyncContextAccessor(args);
if (accessor != null) {
// make asynchronous trace-id
final AsyncContext asyncContext = recorder.recordNextAsyncContext();
accessor._$PINPOINT$_setAsyncContext(asyncContext);
if (isDebug) {
logger.debug("Set asyncContext {}", asyncContext);
}
}
}
Aggregations