Search in sources :

Example 6 with MemcachedNode

use of net.spy.memcached.MemcachedNode 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();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) OperationAccessor(com.navercorp.pinpoint.plugin.arcus.OperationAccessor) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) Future(java.util.concurrent.Future) MemcachedNode(net.spy.memcached.MemcachedNode) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext) Operation(net.spy.memcached.ops.Operation) ServiceCodeAccessor(com.navercorp.pinpoint.plugin.arcus.ServiceCodeAccessor)

Aggregations

MemcachedNode (net.spy.memcached.MemcachedNode)6 OperationAccessor (com.navercorp.pinpoint.plugin.arcus.OperationAccessor)2 ServiceCodeAccessor (com.navercorp.pinpoint.plugin.arcus.ServiceCodeAccessor)2 InetSocketAddress (java.net.InetSocketAddress)2 SocketAddress (java.net.SocketAddress)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 KetamaNodeLocator (net.spy.memcached.KetamaNodeLocator)2 Operation (net.spy.memcached.ops.Operation)2 DefaultKetamaNodeLocatorConfiguration (net.spy.memcached.util.DefaultKetamaNodeLocatorConfiguration)2 Test (org.junit.Test)2 AsyncContextAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor)1 AsyncContext (com.navercorp.pinpoint.bootstrap.context.AsyncContext)1 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)1 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)1 HashMap (java.util.HashMap)1 Future (java.util.concurrent.Future)1 Ignore (org.junit.Ignore)1