use of com.navercorp.pinpoint.bootstrap.context.AsyncContext 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.context.AsyncContext 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.context.AsyncContext in project pinpoint by naver.
the class HbaseClientConstructorInterceptor method after.
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
AsyncContext asyncContext = (AsyncContext) scope.getCurrentInvocation().getAttachment();
((AsyncContextAccessor) target)._$PINPOINT$_setAsyncContext(asyncContext);
}
use of com.navercorp.pinpoint.bootstrap.context.AsyncContext in project pinpoint by naver.
the class HttpRequestExecuteAsyncMethodInnerClassConstructorInterceptor method before.
@Override
public void before(Object target, Object[] args) {
if (isDebug) {
logger.beforeInterceptor(target, args);
}
try {
if (!validate(target, args)) {
return;
}
final InterceptorScopeInvocation transaction = interceptorScope.getCurrentInvocation();
final AsyncContext asyncContext = getAsyncContext(transaction);
if (asyncContext != null) {
// type check validate();
((AsyncContextAccessor) target)._$PINPOINT$_setAsyncContext(asyncContext);
// clear.
transaction.removeAttachment();
}
} catch (Throwable t) {
logger.warn("Failed to BEFORE process. {}", t.getMessage(), t);
}
}
use of com.navercorp.pinpoint.bootstrap.context.AsyncContext in project pinpoint by naver.
the class AbstractHttpServerHandleInterceptor method before.
@Override
public void before(Object target, Object[] args) {
if (isDebug) {
logger.beforeInterceptor(target, args);
}
if (traceContext.currentRawTraceObject() != null) {
if (isDisconnecting(args)) {
final AsyncContext asyncContext = AsyncContextAccessorUtils.getAsyncContext(args, 0);
if (asyncContext != null) {
if (asyncContext instanceof AsyncStateSupport) {
final AsyncStateSupport asyncStateSupport = (AsyncStateSupport) asyncContext;
AsyncState asyncState = asyncStateSupport.getAsyncState();
asyncState.finish();
if (isDebug) {
logger.debug("Finished asyncState. asyncTraceId={}", asyncContext);
}
}
}
}
// duplicate trace.
return;
}
try {
if (Boolean.FALSE == isReceived(args)) {
// invalid args
return;
}
final HttpServerRequest request = (HttpServerRequest) args[0];
final HttpServerResponse response = (HttpServerResponse) args[0];
this.servletRequestListener.initialized(request, ReactorNettyConstants.REACTOR_NETTY_INTERNAL, this.methodDescriptor);
// must after request listener due to trace block begin
this.servletResponseListener.initialized(response, ReactorNettyConstants.REACTOR_NETTY_INTERNAL, this.methodDescriptor);
// Set end-point
final Trace trace = this.traceContext.currentTraceObject();
if (trace == null) {
return;
}
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
if (recorder != null) {
// make asynchronous trace-id
final boolean asyncStateSupport = enableAsyncEndPoint;
final AsyncContext asyncContext = recorder.recordNextAsyncContext(asyncStateSupport);
((AsyncContextAccessor) args[0])._$PINPOINT$_setAsyncContext(asyncContext);
if (isDebug) {
if (enableAsyncEndPoint) {
logger.debug("Set closeable-AsyncContext {}", asyncContext);
} else {
logger.debug("Set AsyncContext {}", asyncContext);
}
}
}
} catch (Throwable t) {
if (isInfo) {
logger.info("Failed to servlet request event handle.", t);
}
}
}
Aggregations