Search in sources :

Example 6 with AsyncTraceId

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

the class DispatcherEnqueueMethodInterceptor 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;
    }
    if (!validate(args)) {
        return;
    }
    SpanEventRecorder recorder = trace.traceBlockBegin();
    try {
        // set asynchronous trace
        final AsyncTraceId asyncTraceId = trace.getAsyncTraceId();
        recorder.recordNextAsyncId(asyncTraceId.getAsyncId());
        // set async id.
        // AsyncTraceIdAccessor typeCheck validate();
        ((AsyncTraceIdAccessor) args[0])._$PINPOINT$_setAsyncTraceId(asyncTraceId);
        if (isDebug) {
            logger.debug("Set asyncTraceId metadata {}", asyncTraceId);
        }
    } catch (Throwable t) {
        logger.warn("Failed to before process. {}", t.getMessage(), t);
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId) AsyncTraceIdAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)

Example 7 with AsyncTraceId

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

the class VertxImplRunOnContextInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    final SpanEventRecorder recorder = trace.traceBlockBegin();
    recorder.recordServiceType(VertxConstants.VERTX_INTERNAL);
    if (validate(args)) {
        // make asynchronous trace-id
        final AsyncTraceId asyncTraceId = trace.getAsyncTraceId();
        recorder.recordNextAsyncId(asyncTraceId.getAsyncId());
        ((AsyncTraceIdAccessor) args[0])._$PINPOINT$_setAsyncTraceId(asyncTraceId);
        if (isDebug) {
            logger.debug("Set asyncTraceId metadata {}", asyncTraceId);
        }
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId) AsyncTraceIdAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)

Example 8 with AsyncTraceId

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

the class SpanAsyncEventSimpleAroundInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    final AsyncTraceId asyncTraceId = getAsyncTraceId(target);
    if (asyncTraceId == null) {
        logger.debug("Not found asynchronous invocation metadata");
        return;
    }
    Trace trace = traceContext.currentRawTraceObject();
    if (trace == null) {
        // create async trace;
        trace = createAsyncTrace(asyncTraceId);
        if (trace == null) {
            return;
        }
    } else {
        // check sampled.
        if (!trace.canSampled()) {
            // sckip.
            return;
        }
    }
    // entry scope.
    entryAsyncTraceScope(trace);
    try {
        // trace event for default & async.
        final SpanEventRecorder recorder = trace.traceBlockBegin();
        doInBeforeTrace(recorder, asyncTraceId, target, args);
    } catch (Throwable th) {
        if (logger.isWarnEnabled()) {
            logger.warn("BEFORE. Caused:{}", th.getMessage(), th);
        }
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)

Example 9 with AsyncTraceId

use of com.navercorp.pinpoint.bootstrap.context.AsyncTraceId 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
                this.traceContext.getAsyncId();
                final AsyncTraceId asyncTraceId = trace.getAsyncTraceId();
                recorder.recordNextAsyncId(asyncTraceId.getAsyncId());
                // type check isAsynchronousInvocation
                ((AsyncTraceIdAccessor) result)._$PINPOINT$_setAsyncTraceId(asyncTraceId);
                if (isDebug) {
                    logger.debug("Set asyncTraceId metadata {}", asyncTraceId);
                }
            }
        } 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) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId) Future(java.util.concurrent.Future) MemcachedNode(net.spy.memcached.MemcachedNode) Operation(net.spy.memcached.ops.Operation) AsyncTraceIdAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor) ServiceCodeAccessor(com.navercorp.pinpoint.plugin.arcus.ServiceCodeAccessor)

Example 10 with AsyncTraceId

use of com.navercorp.pinpoint.bootstrap.context.AsyncTraceId 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();
        if (transaction != null && transaction.getAttachment() != null) {
            final AsyncTraceId asyncTraceId = (AsyncTraceId) transaction.getAttachment();
            // type check validate();
            ((AsyncTraceIdAccessor) target)._$PINPOINT$_setAsyncTraceId(asyncTraceId);
            // 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) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId) AsyncTraceIdAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)

Aggregations

AsyncTraceId (com.navercorp.pinpoint.bootstrap.context.AsyncTraceId)15 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)12 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)12 AsyncTraceIdAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)9 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)4 InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)3 OperationAccessor (com.navercorp.pinpoint.plugin.arcus.OperationAccessor)1 ServiceCodeAccessor (com.navercorp.pinpoint.plugin.arcus.ServiceCodeAccessor)1 AsyncAccessor (com.navercorp.pinpoint.plugin.resin.AsyncAccessor)1 ThriftRequestProperty (com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty)1 AsyncAccessor (com.navercorp.pinpoint.plugin.tomcat.AsyncAccessor)1 DefaultAsyncTraceId (com.navercorp.pinpoint.profiler.context.id.DefaultAsyncTraceId)1 DefaultTraceId (com.navercorp.pinpoint.profiler.context.id.DefaultTraceId)1 AsyncStorage (com.navercorp.pinpoint.profiler.context.storage.AsyncStorage)1 Storage (com.navercorp.pinpoint.profiler.context.storage.Storage)1 Future (java.util.concurrent.Future)1 MemcachedNode (net.spy.memcached.MemcachedNode)1 Operation (net.spy.memcached.ops.Operation)1 HttpRequest (org.apache.http.HttpRequest)1 Test (org.junit.Test)1