Search in sources :

Example 1 with TomcatAsyncListener

use of com.navercorp.pinpoint.plugin.tomcat.TomcatAsyncListener 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, args, result, throwable);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    try {
        final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        if (validate(target, result, throwable)) {
            com.navercorp.pinpoint.bootstrap.context.AsyncContext nextAsyncContext = recorder.recordNextAsyncContext(true);
            // Add async listener
            final AsyncContext asyncContext = (AsyncContext) result;
            final AsyncListener asyncListener = new TomcatAsyncListener(this.traceContext, nextAsyncContext);
            asyncContext.addListener(asyncListener);
            // Set AsyncContext, AsyncListener
            final HttpServletRequest request = (HttpServletRequest) target;
            request.setAttribute(com.navercorp.pinpoint.bootstrap.context.AsyncContext.class.getName(), nextAsyncContext);
            request.setAttribute(TomcatConstants.TOMCAT_SERVLET_REQUEST_TRACE, asyncListener);
            if (isDebug) {
                logger.debug("Add async listener {}", asyncListener);
            }
        }
        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 : TomcatAsyncListener(com.navercorp.pinpoint.plugin.tomcat.TomcatAsyncListener) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncContext(javax.servlet.AsyncContext) Trace(com.navercorp.pinpoint.bootstrap.context.Trace) HttpServletRequest(javax.servlet.http.HttpServletRequest) AsyncListener(javax.servlet.AsyncListener) TomcatAsyncListener(com.navercorp.pinpoint.plugin.tomcat.TomcatAsyncListener)

Aggregations

SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)1 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)1 TomcatAsyncListener (com.navercorp.pinpoint.plugin.tomcat.TomcatAsyncListener)1 AsyncContext (javax.servlet.AsyncContext)1 AsyncListener (javax.servlet.AsyncListener)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1