Search in sources :

Example 1 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.

the class HttpRequestExecuteAsyncMethodInterceptor 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;
    }
    SpanEventRecorder recorder = trace.traceBlockBegin();
    try {
        // set asynchronous trace
        final AsyncTraceId asyncTraceId = trace.getAsyncTraceId();
        recorder.recordNextAsyncId(asyncTraceId.getAsyncId());
        // set async id.
        InterceptorScopeInvocation transaction = interceptorScope.getCurrentInvocation();
        if (transaction != null) {
            transaction.setAttachment(asyncTraceId);
            if (isDebug) {
                logger.debug("Set asyncTraceId metadata {}", asyncTraceId);
            }
        }
    } 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) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId)

Example 2 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation 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 3 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation 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 4 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.

the class HttpRequestExecuteAsyncMethodInterceptor method doInAfterTrace.

@Override
protected void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
    recorder.recordApi(methodDescriptor);
    recorder.recordServiceType(HttpClientConstants.HTTP_CLIENT_INTERNAL);
    recorder.recordException(throwable);
    // remove async id.
    InterceptorScopeInvocation transaction = interceptorScope.getCurrentInvocation();
    if (transaction != null) {
        // clear
        transaction.removeAttachment();
    }
}
Also used : InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)

Example 5 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation 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);
        }
    }
}
Also used : InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Aggregations

InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)71 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)27 Test (org.junit.Test)20 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)15 DefaultInterceptorScopeInvocation (com.navercorp.pinpoint.profiler.interceptor.scope.DefaultInterceptorScopeInvocation)15 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)9 ThriftClientCallContext (com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext)8 HttpCallContext (com.navercorp.pinpoint.plugin.httpclient4.HttpCallContext)7 DefaultInterceptorScopeDefinition (com.navercorp.pinpoint.bootstrap.instrument.DefaultInterceptorScopeDefinition)6 AttachmentFactory (com.navercorp.pinpoint.bootstrap.interceptor.scope.AttachmentFactory)5 Request (com.squareup.okhttp.Request)5 CommandContext (com.navercorp.pinpoint.plugin.redis.CommandContext)4 ThriftRequestProperty (com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty)4 ServerMarkerFlagFieldAccessor (com.navercorp.pinpoint.plugin.thrift.field.accessor.ServerMarkerFlagFieldAccessor)4 HttpClient3CallContext (com.navercorp.pinpoint.plugin.httpclient3.HttpClient3CallContext)3 CommandContext (com.navercorp.pinpoint.plugin.redis.jedis.CommandContext)3 Request (okhttp3.Request)3 AsyncContext (com.navercorp.pinpoint.bootstrap.context.AsyncContext)2 EndPointAccessor (com.navercorp.pinpoint.plugin.redis.EndPointAccessor)2 HttpRequest (org.apache.http.HttpRequest)2