Search in sources :

Example 11 with SpanEventRecorder

use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder in project pinpoint by naver.

the class TAsyncClientManagerCallInterceptor 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 = this.traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    try {
        SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        recorder.recordApi(this.descriptor);
        recorder.recordException(throwable);
    } catch (Throwable t) {
        logger.warn("AFTER error. Caused:{}", t.getMessage(), t);
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)

Example 12 with SpanEventRecorder

use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder in project pinpoint by naver.

the class HttpServletRequestImplInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, "", descriptor.getMethodName(), "", args);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    try {
        SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        if (validate(target, result, throwable)) {
            ((AsyncAccessor) target)._$PINPOINT$_setAsync(Boolean.TRUE);
            // make asynchronous trace-id
            final AsyncTraceId asyncTraceId = trace.getAsyncTraceId();
            recorder.recordNextAsyncId(asyncTraceId.getAsyncId());
            // result is BasicFuture type check validate()
            ((AsyncTraceIdAccessor) result)._$PINPOINT$_setAsyncTraceId(asyncTraceId);
            if (isDebug) {
                logger.debug("Set asyncTraceId metadata {}", asyncTraceId);
            }
        }
        recorder.recordServiceType(ResinConstants.RESIN_METHOD);
        recorder.recordApi(descriptor);
        recorder.recordException(throwable);
    } catch (Throwable t) {
        logger.warn("Failed to AFTER process. {}", t.getMessage(), t);
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId) AsyncAccessor(com.navercorp.pinpoint.plugin.resin.AsyncAccessor) AsyncTraceIdAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)

Example 13 with SpanEventRecorder

use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder in project pinpoint by naver.

the class ServletInvocationInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    try {
        final Trace trace = createTrace(target, args);
        if (trace == null) {
            return;
        }
        // TODO STATDISABLE this logic was added to disable statistics tracing
        if (!trace.canSampled()) {
            return;
        }
        // ------------------------------------------------------
        SpanEventRecorder recorder = trace.traceBlockBegin();
        recorder.recordServiceType(ResinConstants.RESIN_METHOD);
    } catch (Throwable th) {
        if (logger.isWarnEnabled()) {
            logger.warn("BEFORE. Caused:{}", th.getMessage(), th);
        }
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)

Example 14 with SpanEventRecorder

use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder in project pinpoint by naver.

the class ServletInvocationInterceptor 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.currentRawTraceObject();
    if (trace == null) {
        return;
    }
    // TODO STATDISABLE this logic was added to disable statistics tracing
    if (!trace.canSampled()) {
        traceContext.removeTraceObject();
        return;
    }
    // ------------------------------------------------------
    try {
        SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        if (this.isTraceRequestParam) {
            final HttpServletRequest request = (HttpServletRequest) args[0];
            if (!excludeProfileMethodFilter.filter(request.getMethod())) {
                final String parameters = getRequestParameter(request, 64, 512);
                if (parameters != null && parameters.length() > 0) {
                    recorder.recordAttribute(AnnotationKey.HTTP_PARAM, parameters);
                }
            }
            recordRequest(trace, request, throwable);
        }
        final HttpServletResponse response = (HttpServletResponse) args[1];
        if (throwable != null) {
            recorder.recordAttribute(AnnotationKey.HTTP_STATUS_CODE, 500);
            recorder.recordException(throwable);
        } else {
            if (isResinVersion4(target)) {
                recorder.recordAttribute(AnnotationKey.HTTP_STATUS_CODE, response.getStatus());
            }
        }
        recorder.recordApi(methodDescriptor);
    } catch (Throwable th) {
        if (logger.isWarnEnabled()) {
            logger.warn("AFTER. Caused:{}", th.getMessage(), th);
        }
    } finally {
        traceContext.removeTraceObject();
        deleteTrace(trace, target, args, result, throwable);
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) HttpServletRequest(javax.servlet.http.HttpServletRequest) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 15 with SpanEventRecorder

use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder 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)

Aggregations

SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)86 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)75 AsyncTraceId (com.navercorp.pinpoint.bootstrap.context.AsyncTraceId)12 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)9 AsyncTraceIdAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)8 InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)8 DatabaseInfoAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor)5 DatabaseInfo (com.navercorp.pinpoint.bootstrap.context.DatabaseInfo)4 Socket (java.net.Socket)3 HttpRequest (org.apache.http.HttpRequest)3 Test (org.junit.Test)3 MethodDescriptor (com.navercorp.pinpoint.bootstrap.context.MethodDescriptor)2 ParsingResult (com.navercorp.pinpoint.bootstrap.context.ParsingResult)2 SpanRecorder (com.navercorp.pinpoint.bootstrap.context.SpanRecorder)2 TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)2 BindValueAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor)2 DefaultDatabaseInfo (com.navercorp.pinpoint.bootstrap.plugin.jdbc.DefaultDatabaseInfo)2 JdbcUrlParser (com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcUrlParser)2 ParsingResultAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor)2 UnKnownDatabaseInfo (com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo)2