Search in sources :

Example 1 with CommandContext

use of com.navercorp.pinpoint.plugin.redis.CommandContext in project pinpoint by naver.

the class JedisPipelineMethodInterceptor method doInAfterTrace.

@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
    String endPoint = null;
    if (target instanceof EndPointAccessor) {
        endPoint = ((EndPointAccessor) target)._$PINPOINT$_getEndPoint();
    }
    final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
    if (invocation != null && invocation.getAttachment() != null && invocation.getAttachment() instanceof CommandContext) {
        final CommandContext commandContext = (CommandContext) invocation.getAttachment();
        logger.debug("Check command context {}", commandContext);
        if (io) {
            final StringBuilder sb = new StringBuilder();
            sb.append("write=").append(commandContext.getWriteElapsedTime());
            if (commandContext.isWriteFail()) {
                sb.append("(fail)");
            }
            sb.append(", read=").append(commandContext.getReadElapsedTime());
            if (commandContext.isReadFail()) {
                sb.append("(fail)");
            }
            recorder.recordAttribute(AnnotationKey.ARGS0, sb.toString());
        }
        // clear
        invocation.removeAttachment();
    }
    recorder.recordApi(getMethodDescriptor());
    recorder.recordEndPoint(endPoint != null ? endPoint : "Unknown");
    recorder.recordDestinationId(RedisConstants.REDIS.getName());
    recorder.recordServiceType(RedisConstants.REDIS);
    recorder.recordException(throwable);
}
Also used : EndPointAccessor(com.navercorp.pinpoint.plugin.redis.EndPointAccessor) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) CommandContext(com.navercorp.pinpoint.plugin.redis.CommandContext)

Example 2 with CommandContext

use of com.navercorp.pinpoint.plugin.redis.CommandContext in project pinpoint by naver.

the class ProtocolSendCommandAndReadMethodInterceptor 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;
    }
    try {
        final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
        if (invocation != null && invocation.getAttachment() != null && invocation.getAttachment() instanceof CommandContext) {
            final CommandContext commandContext = (CommandContext) invocation.getAttachment();
            if (methodDescriptor.getMethodName().equals("sendCommand")) {
                commandContext.setWriteBeginTime(System.currentTimeMillis());
            } else {
                commandContext.setReadBeginTime(System.currentTimeMillis());
            }
            logger.debug("Set command context {}", commandContext);
        }
    } catch (Throwable t) {
        logger.warn("Failed to BEFORE process. {}", t.getMessage(), t);
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) CommandContext(com.navercorp.pinpoint.plugin.redis.CommandContext)

Example 3 with CommandContext

use of com.navercorp.pinpoint.plugin.redis.CommandContext in project pinpoint by naver.

the class JedisMethodInterceptor method doInAfterTrace.

@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
    String endPoint = null;
    if (target instanceof EndPointAccessor) {
        endPoint = ((EndPointAccessor) target)._$PINPOINT$_getEndPoint();
    }
    final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
    if (invocation != null && invocation.getAttachment() != null && invocation.getAttachment() instanceof CommandContext) {
        final CommandContext commandContext = (CommandContext) invocation.getAttachment();
        logger.debug("Check command context {}", commandContext);
        if (io) {
            final StringBuilder sb = new StringBuilder();
            sb.append("write=").append(commandContext.getWriteElapsedTime());
            if (commandContext.isWriteFail()) {
                sb.append("(fail)");
            }
            sb.append(", read=").append(commandContext.getReadElapsedTime());
            if (commandContext.isReadFail()) {
                sb.append("(fail)");
            }
            recorder.recordAttribute(AnnotationKey.ARGS0, sb.toString());
        }
        // clear
        invocation.removeAttachment();
    }
    recorder.recordApi(getMethodDescriptor());
    recorder.recordEndPoint(endPoint != null ? endPoint : "Unknown");
    recorder.recordDestinationId(RedisConstants.REDIS.getName());
    recorder.recordServiceType(RedisConstants.REDIS);
    recorder.recordException(throwable);
}
Also used : EndPointAccessor(com.navercorp.pinpoint.plugin.redis.EndPointAccessor) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) CommandContext(com.navercorp.pinpoint.plugin.redis.CommandContext)

Example 4 with CommandContext

use of com.navercorp.pinpoint.plugin.redis.CommandContext in project pinpoint by naver.

the class ProtocolSendCommandAndReadMethodInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, methodDescriptor.getClassName(), methodDescriptor.getMethodName(), "", args, result, throwable);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    try {
        final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
        if (invocation != null && invocation.getAttachment() != null && invocation.getAttachment() instanceof CommandContext) {
            final CommandContext commandContext = (CommandContext) invocation.getAttachment();
            if (methodDescriptor.getMethodName().equals("sendCommand")) {
                commandContext.setWriteEndTime(System.currentTimeMillis());
                commandContext.setWriteFail(throwable != null);
            } else {
                commandContext.setReadEndTime(System.currentTimeMillis());
                commandContext.setReadFail(throwable != null);
            }
            logger.debug("Set command context {}", commandContext);
        }
    } catch (Throwable t) {
        logger.warn("Failed to AFTER process. {}", t.getMessage(), t);
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) CommandContext(com.navercorp.pinpoint.plugin.redis.CommandContext)

Aggregations

InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)4 CommandContext (com.navercorp.pinpoint.plugin.redis.CommandContext)4 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)2 EndPointAccessor (com.navercorp.pinpoint.plugin.redis.EndPointAccessor)2