Search in sources :

Example 36 with AsyncContextAccessor

use of com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor in project pinpoint by naver.

the class TransactionIdStartedInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    AsyncContext asyncContext = AsyncContextAccessorUtils.getAsyncContext(args, 0);
    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);
    }
    traceContext.removeTraceObject();
    try {
        final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        LogMarkerToken logMarkerToken = (LogMarkerToken) args[2];
        String message = ((Function0) args[3]).apply().toString();
        recorder.recordApi(new LogMarkerMethodDescriptor(logMarkerToken));
        if (logMarkerToken.component().equals("database")) {
            recorder.recordServiceType(OpenwhiskConstants.COUCHDB_EXECUTE_QUERY);
            recorder.recordDestinationId("COUCHDB");
            recorder.recordAttribute(OpenwhiskConstants.MARKER_MESSAGE, message);
        } else {
            recorder.recordServiceType(OpenwhiskConstants.OPENWHISK_INTERNAL);
            if (isLoggingMessage && message.length() > 0) {
                recorder.recordAttribute(OpenwhiskConstants.MARKER_MESSAGE, message);
            }
        }
        if (result instanceof AsyncContextAccessor && result instanceof PinpointTraceAccessor) {
            ((AsyncContextAccessor) (result))._$PINPOINT$_setAsyncContext(asyncContext);
            ((PinpointTraceAccessor) (result))._$PINPOINT$_setPinpointTrace(trace);
        }
    } catch (Throwable th) {
        if (logger.isWarnEnabled()) {
            logger.warn("AFTER error. Caused:{}", th.getMessage(), th);
        }
    }
}
Also used : LogMarkerMethodDescriptor(com.navercorp.pinpoint.plugin.openwhisk.descriptor.LogMarkerMethodDescriptor) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) PinpointTraceAccessor(com.navercorp.pinpoint.plugin.openwhisk.accessor.PinpointTraceAccessor) LogMarkerToken(org.apache.openwhisk.common.LogMarkerToken)

Example 37 with AsyncContextAccessor

use of com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor in project pinpoint by naver.

the class HbaseClientConstructorInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    AsyncContext asyncContext = (AsyncContext) scope.getCurrentInvocation().getAttachment();
    ((AsyncContextAccessor) target)._$PINPOINT$_setAsyncContext(asyncContext);
}
Also used : AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Example 38 with AsyncContextAccessor

use of com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor in project pinpoint by naver.

the class HttpRequestExecuteAsyncMethodInnerClassConstructorInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    try {
        if (!validate(target, args)) {
            return;
        }
        final InterceptorScopeInvocation transaction = interceptorScope.getCurrentInvocation();
        final AsyncContext asyncContext = getAsyncContext(transaction);
        if (asyncContext != null) {
            // type check validate();
            ((AsyncContextAccessor) target)._$PINPOINT$_setAsyncContext(asyncContext);
            // clear.
            transaction.removeAttachment();
        }
    } catch (Throwable t) {
        logger.warn("Failed to BEFORE process. {}", t.getMessage(), t);
    }
}
Also used : InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Example 39 with AsyncContextAccessor

use of com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor in project pinpoint by naver.

the class AbstractHttpServerHandleInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    if (traceContext.currentRawTraceObject() != null) {
        if (isDisconnecting(args)) {
            final AsyncContext asyncContext = AsyncContextAccessorUtils.getAsyncContext(args, 0);
            if (asyncContext != null) {
                if (asyncContext instanceof AsyncStateSupport) {
                    final AsyncStateSupport asyncStateSupport = (AsyncStateSupport) asyncContext;
                    AsyncState asyncState = asyncStateSupport.getAsyncState();
                    asyncState.finish();
                    if (isDebug) {
                        logger.debug("Finished asyncState. asyncTraceId={}", asyncContext);
                    }
                }
            }
        }
        // duplicate trace.
        return;
    }
    try {
        if (Boolean.FALSE == isReceived(args)) {
            // invalid args
            return;
        }
        final HttpServerRequest request = (HttpServerRequest) args[0];
        final HttpServerResponse response = (HttpServerResponse) args[0];
        this.servletRequestListener.initialized(request, ReactorNettyConstants.REACTOR_NETTY_INTERNAL, this.methodDescriptor);
        // must after request listener due to trace block begin
        this.servletResponseListener.initialized(response, ReactorNettyConstants.REACTOR_NETTY_INTERNAL, this.methodDescriptor);
        // Set end-point
        final Trace trace = this.traceContext.currentTraceObject();
        if (trace == null) {
            return;
        }
        final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        if (recorder != null) {
            // make asynchronous trace-id
            final boolean asyncStateSupport = enableAsyncEndPoint;
            final AsyncContext asyncContext = recorder.recordNextAsyncContext(asyncStateSupport);
            ((AsyncContextAccessor) args[0])._$PINPOINT$_setAsyncContext(asyncContext);
            if (isDebug) {
                if (enableAsyncEndPoint) {
                    logger.debug("Set closeable-AsyncContext {}", asyncContext);
                } else {
                    logger.debug("Set AsyncContext {}", asyncContext);
                }
            }
        }
    } catch (Throwable t) {
        if (isInfo) {
            logger.info("Failed to servlet request event handle.", t);
        }
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) AsyncState(com.navercorp.pinpoint.bootstrap.context.AsyncState) HttpServerRequest(reactor.netty.http.server.HttpServerRequest) HttpServerResponse(reactor.netty.http.server.HttpServerResponse) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext) AsyncStateSupport(com.navercorp.pinpoint.bootstrap.context.AsyncStateSupport)

Example 40 with AsyncContextAccessor

use of com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor in project pinpoint by naver.

the class HttpClientHandlerConstructorInterceptor method doInAfterTrace.

@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) throws Exception {
    recorder.recordApi(methodDescriptor);
    recorder.recordException(throwable);
    recorder.recordServiceType(ReactorNettyConstants.REACTOR_NETTY_CLIENT_INTERNAL);
    if (throwable == null && target instanceof AsyncContextAccessor) {
        final AsyncContext asyncContext = recorder.recordNextAsyncContext();
        ((AsyncContextAccessor) target)._$PINPOINT$_setAsyncContext(asyncContext);
    }
}
Also used : AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Aggregations

AsyncContextAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor)54 AsyncContext (com.navercorp.pinpoint.bootstrap.context.AsyncContext)44 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)16 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)16 NormalizedBson (com.navercorp.pinpoint.plugin.mongo.NormalizedBson)2 PinpointTraceAccessor (com.navercorp.pinpoint.plugin.openwhisk.accessor.PinpointTraceAccessor)2 Continuation (kotlin.coroutines.Continuation)2 RequestContextImpl (akka.http.scaladsl.server.RequestContextImpl)1 AsyncState (com.navercorp.pinpoint.bootstrap.context.AsyncState)1 AsyncStateSupport (com.navercorp.pinpoint.bootstrap.context.AsyncStateSupport)1 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)1 InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)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 LogMarkerMethodDescriptor (com.navercorp.pinpoint.plugin.openwhisk.descriptor.LogMarkerMethodDescriptor)1 TraceFutureFlagAccessor (com.navercorp.pinpoint.plugin.resttemplate.field.accessor.TraceFutureFlagAccessor)1 SamplingRateFlag (com.navercorp.pinpoint.plugin.vertx.SamplingRateFlag)1 Channel (io.netty.channel.Channel)1