Search in sources :

Example 16 with AsyncContext

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

the class WorkerScheduleInterceptor method doInBeforeTrace.

@Override
protected void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[] args) {
    logBeforeInterceptor0(target, args);
    if (args != null && args.length > 0) {
        if (args[0] instanceof AsyncContextAccessor) {
            AsyncContext asyncContext = recorder.recordNextAsyncContext();
            ((AsyncContextAccessor) args[0])._$PINPOINT$_setAsyncContext(asyncContext);
        }
    }
}
Also used : AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Example 17 with AsyncContext

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

the class DirectivesInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    int requestContextIndex = getArgsIndexOfRequestContext(args);
    if (requestContextIndex == -1) {
        return;
    }
    if (traceContext.currentTraceObject() != null) {
        return;
    }
    RequestContextImpl requestContext = (RequestContextImpl) args[requestContextIndex];
    if (!(requestContext instanceof AsyncContextAccessor)) {
        if (isDebug) {
            logger.debug("Invalid requestContext. Need metadata accessor({}).", AsyncContextAccessor.class.getName());
        }
        return;
    }
    akka.http.scaladsl.model.HttpRequest request = requestContext.request();
    final Trace trace = createTrace(request);
    if (trace == null || !trace.canSampled()) {
        return;
    }
    final SpanEventRecorder recorder = trace.traceBlockBegin();
    recorder.recordServiceType(AkkaHttpConstants.AKKA_HTTP_SERVER_INTERNAL);
    final AsyncContext asyncContext = recorder.recordNextAsyncContext(true);
    ((AsyncContextAccessor) requestContext)._$PINPOINT$_setAsyncContext(asyncContext);
    if (isDebug) {
        logger.debug("Set closeable-AsyncContext {}", asyncContext);
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) RequestContextImpl(akka.http.scaladsl.server.RequestContextImpl) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Example 18 with AsyncContext

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

the class ListenerConstructorInterceptor method doInAfterTrace.

@Override
protected void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
    if (target instanceof AsyncContextAccessor) {
        // set asynchronous trace
        final AsyncContext asyncContext = recorder.recordNextAsyncContext();
        ((AsyncContextAccessor) target)._$PINPOINT$_setAsyncContext(asyncContext);
        if (isDebug) {
            logger.debug("Set AsyncContext {}", asyncContext);
        }
    }
    recorder.recordApi(LISTENER_RESULT_DESCRIPTOR);
    recorder.recordException(throwable);
}
Also used : AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Example 19 with AsyncContext

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

the class GrpcAsyncContextSpanEventEndPointInterceptor 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, args, result, throwable);
    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)

Example 20 with AsyncContext

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

the class CopyAsyncContextInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args);
    }
    if (ArrayUtils.getLength(args) == 2) {
        AsyncContext asyncContext = getAsyncContext(args[0]);
        if (result instanceof AsyncContextAccessor) {
            logger.info("set AsyncContext:{}", asyncContext);
            ((AsyncContextAccessor) result)._$PINPOINT$_setAsyncContext(asyncContext);
        }
    }
}
Also used : AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) 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