Search in sources :

Example 61 with AsyncContext

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

the class ChannelPipelineWriteInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    if (!validate(args)) {
        return;
    }
    Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    SpanEventRecorder recorder = trace.traceBlockBegin();
    recorder.recordServiceType(NettyConstants.SERVICE_TYPE);
    // Inner handler can run before after() method.
    // If create AsyncContext in after() method, then there is a possibility that AsyncContext will be saved later than execution
    // The write method returns an exception in the Future, so you do not needs to worry about to handle throwable field.
    Object request = ArrayUtils.get(args, 0);
    if (isAsynchronousInvocation(request)) {
        // set asynchronous trace
        final AsyncContext asyncContext = recorder.recordNextAsyncContext();
        ((AsyncContextAccessor) request)._$PINPOINT$_setAsyncContext(asyncContext);
        if (isDebug) {
            logger.debug("Set AsyncContext {}", asyncContext);
        }
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Example 62 with AsyncContext

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

the class HttpServerResponseImplInterceptor method doInAfterTrace.

@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
    recorder.recordApi(methodDescriptor);
    recorder.recordServiceType(VertxConstants.VERTX_HTTP_SERVER_INTERNAL);
    recorder.recordException(throwable);
    if (target instanceof HttpServerResponse) {
        final HttpServerResponse response = (HttpServerResponse) target;
        // TODO more simple.
        final AsyncContext asyncContext = getAsyncContext(target);
        if (asyncContext != null) {
            final Trace trace = asyncContext.currentAsyncTraceObject();
            if (trace != null) {
                final SpanRecorder spanRecorder = trace.getSpanRecorder();
                this.httpStatusCodeRecorder.record(spanRecorder, response.getStatusCode());
            }
        }
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanRecorder(com.navercorp.pinpoint.bootstrap.context.SpanRecorder) HttpServerResponse(io.vertx.core.http.HttpServerResponse) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Example 63 with AsyncContext

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

the class ServerConnectionHandleRequestInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    if (traceContext.currentRawTraceObject() != null) {
        // duplicate trace.
        return;
    }
    try {
        if (!validate(args)) {
            // invalid args.
            return;
        }
        final HttpServerRequest request = (HttpServerRequest) args[0];
        final HttpServerResponse response = request.response();
        if (!(response instanceof AsyncContextAccessor)) {
            if (isDebug) {
                logger.debug("Invalid response. Need metadata accessor({}).", AsyncContextAccessor.class.getName());
            }
            return;
        }
        // create trace for standalone entry point.
        final Trace trace = createTrace(request);
        if (trace == null) {
            return;
        }
        entryScope(trace);
        this.httpHeaderFilter.filter(request);
        if (!trace.canSampled()) {
            return;
        }
        final SpanEventRecorder recorder = trace.traceBlockBegin();
        recorder.recordServiceType(VertxConstants.VERTX_HTTP_SERVER_INTERNAL);
        // make asynchronous trace-id
        final AsyncContext asyncContext = recorder.recordNextAsyncContext(true);
        ((AsyncContextAccessor) request)._$PINPOINT$_setAsyncContext(asyncContext);
        ((AsyncContextAccessor) response)._$PINPOINT$_setAsyncContext(asyncContext);
        if (isDebug) {
            logger.debug("Set closeable-AsyncContext {}", asyncContext);
        }
    } catch (Throwable t) {
        if (logger.isWarnEnabled()) {
            logger.warn("BEFORE. Caused:{}", t.getMessage(), t);
        }
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) HttpServerRequest(io.vertx.core.http.HttpServerRequest) HttpServerResponse(io.vertx.core.http.HttpServerResponse) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Example 64 with AsyncContext

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

the class DispatchInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, descriptor.getClassName(), descriptor.getMethodName(), descriptor.getParameterDescriptor(), args);
    }
    Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    if (isCompletedContinuation(args)) {
        return;
    }
    final SpanEventRecorder recorder = trace.traceBlockBegin();
    recorder.recordServiceType(serviceType);
    AsyncContextAccessor accessor = ArrayArgumentUtils.getArgument(args, 0, AsyncContextAccessor.class);
    if (accessor != null) {
        final AsyncContext asyncContext = recorder.recordNextAsyncContext();
        accessor._$PINPOINT$_setAsyncContext(asyncContext);
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Example 65 with AsyncContext

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

the class ResumeWithInterceptor method getAsyncContext.

private AsyncContext getAsyncContext(Object object) {
    if (object instanceof Continuation) {
        CoroutineContext context = ((Continuation<?>) object).getContext();
        if (context instanceof AsyncContextAccessor) {
            AsyncContextAccessor accessor = (AsyncContextAccessor) context;
            AsyncContext asyncContext = accessor._$PINPOINT$_getAsyncContext();
            return asyncContext;
        }
    }
    return null;
}
Also used : Continuation(kotlin.coroutines.Continuation) CoroutineContext(kotlin.coroutines.CoroutineContext) 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