Search in sources :

Example 26 with AsyncContext

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

the class DispatchHandlerInvokeHandlerMethodInterceptor method doInAfterTrace.

@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
    recorder.recordApi(methodDescriptor);
    recorder.recordServiceType(SpringWebFluxConstants.SPRING_WEBFLUX);
    recorder.recordException(throwable);
    if (Boolean.FALSE == validate(args)) {
        return;
    }
    final AsyncContext publisherAsyncContext = AsyncContextAccessorUtils.getAsyncContext(args, 0);
    if (publisherAsyncContext != null) {
        // Set AsyncContext to CoreSubscriber
        if (result instanceof AsyncContextAccessor) {
            ((AsyncContextAccessor) (result))._$PINPOINT$_setAsyncContext(publisherAsyncContext);
            if (isDebug) {
                logger.debug("Set AsyncContext result={}", result);
            }
        }
    }
}
Also used : AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Example 27 with AsyncContext

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

the class DispatchHandlerHandleMethodInterceptor method doInBeforeTrace.

@Override
protected void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[] args) {
    if (isAsync(args)) {
        // make asynchronous trace-id
        final AsyncContext asyncContext = recorder.recordNextAsyncContext();
        ((AsyncContextAccessor) args[0])._$PINPOINT$_setAsyncContext(asyncContext);
        if (isDebug) {
            logger.debug("Set AsyncContext {}", asyncContext);
        }
    }
}
Also used : AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Example 28 with AsyncContext

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

the class ExchangeFunctionMethodInterceptor method doInBeforeTrace.

@Override
protected void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[] args) {
    if (isAsync(args)) {
        // make asynchronous trace-id
        final AsyncContext asyncContext = recorder.recordNextAsyncContext();
        ((AsyncContextAccessor) args[0])._$PINPOINT$_setAsyncContext(asyncContext);
        if (isDebug) {
            logger.debug("Set closeable-AsyncContext {}", asyncContext);
        }
    }
}
Also used : AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Example 29 with AsyncContext

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

Example 30 with AsyncContext

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

the class AsyncContextSpanEventEndPointInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    final AsyncContext asyncContext = getAsyncContext(target);
    if (asyncContext == null) {
        logger.debug("Not found asynchronous invocation metadata");
        return;
    }
    if (isDebug) {
        logger.debug("Asynchronous invocation. asyncContext={}", asyncContext);
    }
    final Trace trace = asyncContext.currentAsyncTraceObject();
    if (trace == null) {
        return;
    }
    if (isDebug) {
        logger.debug("Asynchronous invocation. asyncTraceId={}, trace={}", asyncContext, trace);
    }
    // leave scope.
    if (!leaveAsyncTraceScope(trace)) {
        if (logger.isWarnEnabled()) {
            logger.warn("Failed to leave scope of async trace {}.", trace);
        }
        // delete unstable trace.
        deleteAsyncTrace(trace);
        return;
    }
    try {
        final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        doInAfterTrace(recorder, target, args, result, throwable);
    } catch (Throwable th) {
        if (logger.isWarnEnabled()) {
            logger.warn("AFTER error. Caused:{}", th.getMessage(), th);
        }
    } finally {
        trace.traceBlockEnd();
        if (isAsyncTraceDestination(trace)) {
            if (isDebug) {
                logger.debug("Arrived at async trace destination. asyncTraceId={}", asyncContext);
            }
            deleteAsyncTrace(trace);
        }
        finishAsyncState(asyncContext);
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Aggregations

AsyncContext (com.navercorp.pinpoint.bootstrap.context.AsyncContext)68 AsyncContextAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor)44 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)31 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)28 Test (org.junit.Test)7 AsyncState (com.navercorp.pinpoint.bootstrap.context.AsyncState)2 InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)2 NormalizedBson (com.navercorp.pinpoint.plugin.mongo.NormalizedBson)2 HttpServerResponse (io.vertx.core.http.HttpServerResponse)2 Method (java.lang.reflect.Method)2 Continuation (kotlin.coroutines.Continuation)2 RequestContextImpl (akka.http.scaladsl.server.RequestContextImpl)1 AsyncStateSupport (com.navercorp.pinpoint.bootstrap.context.AsyncStateSupport)1 SpanRecorder (com.navercorp.pinpoint.bootstrap.context.SpanRecorder)1 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)1 ClientRequestWrapper (com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestWrapper)1 OperationAccessor (com.navercorp.pinpoint.plugin.arcus.OperationAccessor)1 ServiceCodeAccessor (com.navercorp.pinpoint.plugin.arcus.ServiceCodeAccessor)1 AsyncStartFlagFieldAccessor (com.navercorp.pinpoint.plugin.netty.field.accessor.AsyncStartFlagFieldAccessor)1 TraceFutureFlagAccessor (com.navercorp.pinpoint.plugin.resttemplate.field.accessor.TraceFutureFlagAccessor)1