Search in sources :

Example 1 with TraceFutureFlagAccessor

use of com.navercorp.pinpoint.plugin.resttemplate.field.accessor.TraceFutureFlagAccessor in project pinpoint by naver.

the class AsyncHttpRequestInterceptor method traceAndRecordFuture.

// reason for virtual Method
// //////////////////////////////////////////////////
// 1. if virtualMethod not crated
// executeAsync
// - Asynchronous Invocation (for future set)
// - some trace (like connect, write, etc ...)
// //////////////////////////
// 2. if virtualMethod crated
// executeAsync
// 
// - some trace (like connect, write, etc ...)
// - Asynchronous Invocation (for future set)
// //////////////////////////////////////////////////
private void traceAndRecordFuture(Object result, Throwable throwable) {
    if (throwable != null) {
        return;
    }
    if (!(result instanceof ListenableFuture)) {
        return;
    }
    final Trace virtualMethodTrace = traceContext.currentTraceObject();
    try {
        SpanEventRecorder recorder = virtualMethodTrace.traceBlockBegin();
        recorder.recordServiceType(RestTemplateConstants.SERVICE_TYPE);
        recorder.recordApi(execAsyncResultMethodDescriptor);
        if (isAsynchronousInvocation(result)) {
            // set asynchronous trace
            final AsyncContext asyncContext = recorder.recordNextAsyncContext();
            ((AsyncContextAccessor) result)._$PINPOINT$_setAsyncContext(asyncContext);
            if (isDebug) {
                logger.debug("Set AsyncContext {}", asyncContext);
            }
            if (result instanceof TraceFutureFlagAccessor) {
                ((TraceFutureFlagAccessor) result)._$PINPOINT$_setTraceFlag(true);
            }
        }
    } finally {
        virtualMethodTrace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) TraceFutureFlagAccessor(com.navercorp.pinpoint.plugin.resttemplate.field.accessor.TraceFutureFlagAccessor) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) ListenableFuture(org.springframework.util.concurrent.ListenableFuture) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Aggregations

AsyncContextAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor)1 AsyncContext (com.navercorp.pinpoint.bootstrap.context.AsyncContext)1 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)1 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)1 TraceFutureFlagAccessor (com.navercorp.pinpoint.plugin.resttemplate.field.accessor.TraceFutureFlagAccessor)1 ListenableFuture (org.springframework.util.concurrent.ListenableFuture)1