Search in sources :

Example 1 with AsyncAccessor

use of com.navercorp.pinpoint.plugin.tomcat.AsyncAccessor in project pinpoint by naver.

the class RequestRecycleInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    logger.beforeInterceptor(target, target.getClass().getName(), targetMethod.getName(), "", args);
    try {
        if (target instanceof AsyncAccessor) {
            // reset
            ((AsyncAccessor) target)._$PINPOINT$_setAsync(Boolean.FALSE);
        }
        if (target instanceof TraceAccessor) {
            final Trace trace = ((TraceAccessor) target)._$PINPOINT$_getTrace();
            if (trace != null && trace.canSampled()) {
                // end of root span
                trace.close();
            }
            // reset
            ((TraceAccessor) target)._$PINPOINT$_setTrace(null);
        }
    } catch (Throwable t) {
        logger.warn("Failed to BEFORE process. {}", t.getMessage(), t);
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) AsyncAccessor(com.navercorp.pinpoint.plugin.tomcat.AsyncAccessor) TraceAccessor(com.navercorp.pinpoint.plugin.tomcat.TraceAccessor)

Example 2 with AsyncAccessor

use of com.navercorp.pinpoint.plugin.tomcat.AsyncAccessor in project pinpoint by naver.

the class RequestStartAsyncInterceptor 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(TomcatConstants.TOMCAT_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.tomcat.AsyncAccessor) AsyncTraceIdAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)

Aggregations

Trace (com.navercorp.pinpoint.bootstrap.context.Trace)2 AsyncAccessor (com.navercorp.pinpoint.plugin.tomcat.AsyncAccessor)2 AsyncTraceIdAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)1 AsyncTraceId (com.navercorp.pinpoint.bootstrap.context.AsyncTraceId)1 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)1 TraceAccessor (com.navercorp.pinpoint.plugin.tomcat.TraceAccessor)1