Search in sources :

Example 31 with AsyncContextAccessor

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

the class ProducerSendInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    try {
        Trace trace = traceContext.currentTraceObject();
        final AsyncContextAccessor sendCallback = getSendCallback(args);
        // async send process
        if (sendCallback != null) {
            if (isSkipTrace()) {
                return;
            }
            final AsyncContext asyncContext = ((AsyncContextAccessor) sendCallback)._$PINPOINT$_getAsyncContext();
            if (asyncContext == null) {
                logger.debug("Skip rocketmq produce trace");
                return;
            }
            // create async trace
            trace = asyncContext.continueAsyncTraceObject();
            if (isDebug) {
                logger.debug("Created trace. trace={}", trace);
            }
            if (trace == null) {
                // Skip
                return;
            }
            // init entry point scope
            if (!initScope(trace)) {
                // Defense code
                deleteTrace(trace);
                return;
            }
            // entry point scope
            entryScope(trace);
        }
        if (trace == null) {
            return;
        }
        if (!trace.canSampled()) {
            return;
        }
        final SpanEventRecorder recorder = trace.traceBlockBegin();
        doInBeforeTrace(recorder, target, args);
    } catch (Throwable th) {
        if (logger.isWarnEnabled()) {
            logger.warn("BEFORE. Caused:{}", th.getMessage(), th);
        }
    }
}
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 32 with AsyncContextAccessor

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

the class CommandAsyncServiceMethodInterceptor method doInBeforeTrace.

@Override
public void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[] args) {
    try {
        AsyncContextAccessor asynchronousInvocation = getAsynchronousInvocation(target, args);
        if (asynchronousInvocation != null) {
            // set asynchronous trace
            final AsyncContext asyncContext = recorder.recordNextAsyncContext();
            // type check isAsynchronousInvocation
            asynchronousInvocation._$PINPOINT$_setAsyncContext(asyncContext);
            if (isDebug) {
                logger.debug("Set AsyncContext {}", asyncContext);
            }
        }
    } catch (Throwable t) {
        logger.warn("Failed to BEFORE process. {}", t.getMessage(), t);
    }
}
Also used : AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Example 33 with AsyncContextAccessor

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

the class ApiInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    try {
        final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        if (traceKey) {
            final Object recordObject = args[keyIndex];
            recorder.recordApi(methodDescriptor, recordObject, keyIndex);
        } else {
            recorder.recordApi(methodDescriptor);
        }
        recorder.recordException(throwable);
        // find the target node
        if (result instanceof Future && result instanceof OperationAccessor) {
            final Operation op = ((OperationAccessor) result)._$PINPOINT$_getOperation();
            if (op != null) {
                final MemcachedNode handlingNode = op.getHandlingNode();
                if (handlingNode != null) {
                    final String endPoint = getEndPoint(handlingNode);
                    if (endPoint != null) {
                        recorder.recordEndPoint(endPoint);
                    }
                }
            } else {
                logger.info("operation not found");
            }
        }
        if (target instanceof ServiceCodeAccessor) {
            // determine the service type
            String serviceCode = ((ServiceCodeAccessor) target)._$PINPOINT$_getServiceCode();
            if (serviceCode != null) {
                recorder.recordDestinationId(serviceCode);
                recorder.recordServiceType(ArcusConstants.ARCUS);
            } else {
                recorder.recordDestinationId("MEMCACHED");
                recorder.recordServiceType(ArcusConstants.MEMCACHED);
            }
        } else {
            recorder.recordDestinationId("MEMCACHED");
            recorder.recordServiceType(ArcusConstants.MEMCACHED);
        }
        try {
            if (isAsynchronousInvocation(target, args, result, throwable)) {
                // set asynchronous trace
                final AsyncContext asyncContext = recorder.recordNextAsyncContext();
                // type check isAsynchronousInvocation
                ((AsyncContextAccessor) result)._$PINPOINT$_setAsyncContext(asyncContext);
                if (isDebug) {
                    logger.debug("Set AsyncContext {}", asyncContext);
                }
            }
        } catch (Throwable t) {
            logger.warn("Failed to BEFORE process. {}", t.getMessage(), t);
        }
    } catch (Throwable th) {
        if (logger.isWarnEnabled()) {
            logger.warn("AFTER error. Caused:{}", th.getMessage(), th);
        }
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) OperationAccessor(com.navercorp.pinpoint.plugin.arcus.OperationAccessor) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) Future(java.util.concurrent.Future) MemcachedNode(net.spy.memcached.MemcachedNode) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext) Operation(net.spy.memcached.ops.Operation) ServiceCodeAccessor(com.navercorp.pinpoint.plugin.arcus.ServiceCodeAccessor)

Example 34 with AsyncContextAccessor

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

the class AsyncEntryInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    try {
        final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        recorder.recordApi(this.descriptor);
        recorder.recordServiceType(AgentSdkAsyncConstants.AGENT_SDK_ASYNC);
        recorder.recordException(throwable);
        boolean r = validate(result);
        if (r) {
            // make asynchronous trace-id
            final AsyncContext asyncContext = recorder.recordNextAsyncContext();
            ((AsyncContextAccessor) result)._$PINPOINT$_setAsyncContext(asyncContext);
            if (isDebug) {
                logger.debug("Set asyncContext {}", asyncContext);
            }
        }
    } finally {
        trace.traceBlockEnd();
    }
}
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 35 with AsyncContextAccessor

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

the class ExecutorExecuteInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    final SpanEventRecorder recorder = trace.traceBlockBegin();
    AsyncContextAccessor accessor = getAsyncContextAccessor(args);
    if (accessor != null) {
        // make asynchronous trace-id
        final AsyncContext asyncContext = recorder.recordNextAsyncContext();
        accessor._$PINPOINT$_setAsyncContext(asyncContext);
        if (isDebug) {
            logger.debug("Set asyncContext {}", asyncContext);
        }
    }
}
Also used : AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor)

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