Search in sources :

Example 41 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 42 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 43 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 44 with SpanEventRecorder

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

the class PreparedStatementExecuteQueryInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    SpanEventRecorder recorder = trace.traceBlockBegin();
    try {
        DatabaseInfo databaseInfo = (target instanceof DatabaseInfoAccessor) ? ((DatabaseInfoAccessor) target)._$PINPOINT$_getDatabaseInfo() : null;
        if (databaseInfo == null) {
            databaseInfo = UnKnownDatabaseInfo.INSTANCE;
        }
        recorder.recordServiceType(databaseInfo.getExecuteQueryType());
        recorder.recordEndPoint(databaseInfo.getMultipleHost());
        recorder.recordDestinationId(databaseInfo.getDatabaseId());
        ParsingResult parsingResult = null;
        if (target instanceof ParsingResultAccessor) {
            parsingResult = ((ParsingResultAccessor) target)._$PINPOINT$_getParsingResult();
        }
        Map<Integer, String> bindValue = null;
        if (target instanceof BindValueAccessor) {
            bindValue = ((BindValueAccessor) target)._$PINPOINT$_getBindValue();
        }
        if (bindValue != null) {
            String bindString = toBindVariable(bindValue);
            recorder.recordSqlParsingResult(parsingResult, bindString);
        } else {
            recorder.recordSqlParsingResult(parsingResult);
        }
        recorder.recordApi(descriptor);
        //            trace.recordApi(apiId);
        // Need to change where to invoke clean().
        // There is cleanParameters method but it's not necessary to intercept that method.
        // iBatis intentionally does not invoke it in most cases. 
        clean(target);
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn(e.getMessage(), e);
        }
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) ParsingResult(com.navercorp.pinpoint.bootstrap.context.ParsingResult) UnKnownDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo) DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) DatabaseInfoAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor) BindValueAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor) ParsingResultAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor)

Example 45 with SpanEventRecorder

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

the class SpanAsyncEventSimpleAroundInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    final AsyncTraceId asyncTraceId = getAsyncTraceId(target);
    if (asyncTraceId == null) {
        logger.debug("Not found asynchronous invocation metadata");
        return;
    }
    Trace trace = traceContext.currentRawTraceObject();
    if (trace == null) {
        // create async trace;
        trace = createAsyncTrace(asyncTraceId);
        if (trace == null) {
            return;
        }
    } else {
        // check sampled.
        if (!trace.canSampled()) {
            // sckip.
            return;
        }
    }
    // entry scope.
    entryAsyncTraceScope(trace);
    try {
        // trace event for default & async.
        final SpanEventRecorder recorder = trace.traceBlockBegin();
        doInBeforeTrace(recorder, asyncTraceId, target, args);
    } catch (Throwable th) {
        if (logger.isWarnEnabled()) {
            logger.warn("BEFORE. Caused:{}", th.getMessage(), th);
        }
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId) 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