Search in sources :

Example 6 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 7 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 8 with InterceptorScopeInvocation

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

the class HttpRequestExecutorDoSendRequestAndDoReceiveResponseMethodInterceptor 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 InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
    if (invocation != null && invocation.getAttachment() != null && invocation.getAttachment() instanceof HttpCallContext) {
        HttpCallContext callContext = (HttpCallContext) invocation.getAttachment();
        if (methodDescriptor.getMethodName().equals("doSendRequest")) {
            callContext.setWriteBeginTime(System.currentTimeMillis());
        } else {
            callContext.setReadBeginTime(System.currentTimeMillis());
        }
        if (isDebug) {
            logger.debug("Set call context {}", callContext);
        }
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) HttpCallContext(com.navercorp.pinpoint.plugin.httpclient4.HttpCallContext)

Example 9 with InterceptorScopeInvocation

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

the class HttpRequestExecutorExecuteMethodInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    try {
        final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        final HttpRequest httpRequest = getHttpRequest(args);
        if (httpRequest != null) {
            // Accessing httpRequest here not BEFORE() because it can cause side effect.
            if (httpRequest.getRequestLine() != null) {
                final String httpUrl = InterceptorUtils.getHttpUrl(httpRequest.getRequestLine().getUri(), param);
                recorder.recordAttribute(AnnotationKey.HTTP_URL, httpUrl);
            }
            final NameIntValuePair<String> host = getHost();
            if (host != null) {
                final String endpoint = getEndpoint(host.getName(), host.getValue());
                recorder.recordDestinationId(endpoint);
            }
            recordHttpRequest(trace, httpRequest, throwable);
        }
        if (statusCode) {
            final Integer statusCodeValue = getStatusCode(result);
            if (statusCodeValue != null) {
                recorder.recordAttribute(AnnotationKey.HTTP_STATUS_CODE, statusCodeValue);
            }
        }
        recorder.recordApi(methodDescriptor);
        recorder.recordException(throwable);
        final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
        if (invocation != null && invocation.getAttachment() != null && invocation.getAttachment() instanceof HttpCallContext) {
            final HttpCallContext callContext = (HttpCallContext) invocation.getAttachment();
            logger.debug("Check call context {}", callContext);
            if (io) {
                final StringBuilder sb = new StringBuilder();
                sb.append("write=").append(callContext.getWriteElapsedTime());
                if (callContext.isWriteFail()) {
                    sb.append("(fail)");
                }
                sb.append(", read=").append(callContext.getReadElapsedTime());
                if (callContext.isReadFail()) {
                    sb.append("(fail)");
                }
                recorder.recordAttribute(AnnotationKey.HTTP_IO, sb.toString());
            }
            // clear
            invocation.removeAttachment();
        }
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) HttpRequest(org.apache.http.HttpRequest) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) HttpCallContext(com.navercorp.pinpoint.plugin.httpclient4.HttpCallContext) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)

Example 10 with InterceptorScopeInvocation

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

the class HttpRequestExecutorExecuteMethodInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    final Trace trace = traceContext.currentRawTraceObject();
    if (trace == null) {
        return;
    }
    final HttpRequest httpRequest = getHttpRequest(args);
    final boolean sampling = trace.canSampled();
    if (!sampling) {
        if (isDebug) {
            logger.debug("set Sampling flag=false");
        }
        if (httpRequest != null) {
            httpRequest.setHeader(Header.HTTP_SAMPLED.toString(), SamplingFlagUtils.SAMPLING_RATE_FALSE);
        }
        return;
    }
    final SpanEventRecorder recorder = trace.traceBlockBegin();
    TraceId nextId = trace.getTraceId().getNextTraceId();
    recorder.recordNextSpanId(nextId.getSpanId());
    recorder.recordServiceType(HttpClient4Constants.HTTP_CLIENT_4);
    if (httpRequest != null) {
        httpRequest.setHeader(Header.HTTP_TRACE_ID.toString(), nextId.getTransactionId());
        httpRequest.setHeader(Header.HTTP_SPAN_ID.toString(), String.valueOf(nextId.getSpanId()));
        httpRequest.setHeader(Header.HTTP_PARENT_SPAN_ID.toString(), String.valueOf(nextId.getParentSpanId()));
        httpRequest.setHeader(Header.HTTP_FLAGS.toString(), String.valueOf(nextId.getFlags()));
        httpRequest.setHeader(Header.HTTP_PARENT_APPLICATION_NAME.toString(), traceContext.getApplicationName());
        httpRequest.setHeader(Header.HTTP_PARENT_APPLICATION_TYPE.toString(), Short.toString(traceContext.getServerTypeCode()));
        final NameIntValuePair<String> host = getHost();
        if (host != null) {
            final String endpoint = getEndpoint(host.getName(), host.getValue());
            logger.debug("Get host {}", endpoint);
            httpRequest.setHeader(Header.HTTP_HOST.toString(), endpoint);
        }
    }
    InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
    if (invocation != null) {
        invocation.getOrCreateAttachment(HttpCallContextFactory.HTTPCALL_CONTEXT_FACTORY);
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) HttpRequest(org.apache.http.HttpRequest) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId)

Aggregations

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