Search in sources :

Example 11 with AsyncTraceId

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

the class TAsyncClientManagerCallInterceptor method injectAsyncTraceId.

private AsyncTraceId injectAsyncTraceId(final Object asyncMethodCallObj, final Trace trace) {
    final AsyncTraceId asyncTraceId = trace.getAsyncTraceId();
    SpanEventRecorder recorder = trace.currentSpanEventRecorder();
    recorder.recordNextAsyncId(asyncTraceId.getAsyncId());
    ((AsyncTraceIdAccessor) asyncMethodCallObj)._$PINPOINT$_setAsyncTraceId(asyncTraceId);
    if (isDebug) {
        logger.debug("Set asyncTraceId metadata {}", asyncTraceId);
    }
    return asyncTraceId;
}
Also used : AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncTraceIdAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)

Example 12 with AsyncTraceId

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

the class TAsyncClientManagerCallInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    if (!validate(target, args)) {
        return;
    }
    final Trace trace = this.traceContext.currentRawTraceObject();
    if (trace == null) {
        return;
    }
    try {
        ThriftRequestProperty parentTraceInfo = new ThriftRequestProperty();
        final boolean shouldSample = trace.canSampled();
        if (!shouldSample) {
            if (isDebug) {
                logger.debug("set Sampling flag=false");
            }
            parentTraceInfo.setShouldSample(shouldSample);
        } else {
            SpanEventRecorder recorder = trace.traceBlockBegin();
            Object asyncMethodCallObj = args[0];
            // inject async trace info to AsyncMethodCall object
            final AsyncTraceId asyncTraceId = injectAsyncTraceId(asyncMethodCallObj, trace);
            // retrieve connection information
            String remoteAddress = getRemoteAddress(asyncMethodCallObj);
            final TraceId nextId = asyncTraceId.getNextTraceId();
            // Inject nextSpanId as the actual sending of data will be handled asynchronously.
            final long nextSpanId = nextId.getSpanId();
            parentTraceInfo.setSpanId(nextSpanId);
            parentTraceInfo.setTraceId(nextId.getTransactionId());
            parentTraceInfo.setParentSpanId(nextId.getParentSpanId());
            parentTraceInfo.setFlags(nextId.getFlags());
            parentTraceInfo.setParentApplicationName(this.traceContext.getApplicationName());
            parentTraceInfo.setParentApplicationType(this.traceContext.getServerTypeCode());
            parentTraceInfo.setAcceptorHost(remoteAddress);
            recorder.recordServiceType(ThriftConstants.THRIFT_CLIENT);
            recorder.recordNextSpanId(nextSpanId);
            recorder.recordDestinationId(remoteAddress);
            String methodUri = ThriftUtils.getAsyncMethodCallName((TAsyncMethodCall<?>) asyncMethodCallObj);
            String thriftUrl = remoteAddress + "/" + methodUri;
            recorder.recordAttribute(ThriftConstants.THRIFT_URL, thriftUrl);
        }
        InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
        currentTransaction.setAttachment(parentTraceInfo);
    } catch (Throwable t) {
        logger.warn("BEFORE error. Caused:{}", t.getMessage(), t);
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) ThriftRequestProperty(com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId)

Example 13 with AsyncTraceId

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

the class RequestStartAsyncInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, "", descriptor.getMethodName(), "", args);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    try {
        SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        if (validate(target, result, throwable)) {
            ((AsyncAccessor) target)._$PINPOINT$_setAsync(Boolean.TRUE);
            // make asynchronous trace-id
            final AsyncTraceId asyncTraceId = trace.getAsyncTraceId();
            recorder.recordNextAsyncId(asyncTraceId.getAsyncId());
            // result is BasicFuture
            // type check validate()
            ((AsyncTraceIdAccessor) result)._$PINPOINT$_setAsyncTraceId(asyncTraceId);
            if (isDebug) {
                logger.debug("Set asyncTraceId metadata {}", asyncTraceId);
            }
        }
        recorder.recordServiceType(TomcatConstants.TOMCAT_METHOD);
        recorder.recordApi(descriptor);
        recorder.recordException(throwable);
    } catch (Throwable t) {
        logger.warn("Failed to AFTER process. {}", t.getMessage(), t);
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId) AsyncAccessor(com.navercorp.pinpoint.plugin.tomcat.AsyncAccessor) AsyncTraceIdAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)

Example 14 with AsyncTraceId

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

the class VertxImplExecuteBlockingInterceptor 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();
    if (validate(args, 0) || validate(args, 2)) {
        // make asynchronous trace-id
        final AsyncTraceId asyncTraceId = trace.getAsyncTraceId();
        recorder.recordNextAsyncId(asyncTraceId.getAsyncId());
        if (validate(args, 0)) {
            // args 0 'io.vertx.core.Handler'
            ((AsyncTraceIdAccessor) args[0])._$PINPOINT$_setAsyncTraceId(asyncTraceId);
        }
        if (validate(args, 2)) {
            // args 2 'io.vertx.core.Handler'
            ((AsyncTraceIdAccessor) args[2])._$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 15 with AsyncTraceId

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

the class DefaultAsyncTraceIdTest method nextAsyncSequence.

@Test
public void nextAsyncSequence() throws Exception {
    long agentStartTime = System.currentTimeMillis();
    TraceId traceId = new DefaultTraceId("testAgentId", agentStartTime, 0);
    AsyncTraceId asyncTraceId = new DefaultAsyncTraceId(traceId, 0, agentStartTime + 10);
    Assert.assertEquals(asyncTraceId.nextAsyncSequence(), 1);
    Assert.assertEquals(asyncTraceId.nextAsyncSequence(), 2);
    Assert.assertEquals(asyncTraceId.nextAsyncSequence(), 3);
}
Also used : DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId) DefaultAsyncTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultAsyncTraceId) DefaultTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultTraceId) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) AsyncTraceId(com.navercorp.pinpoint.bootstrap.context.AsyncTraceId) DefaultAsyncTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultAsyncTraceId) DefaultAsyncTraceId(com.navercorp.pinpoint.profiler.context.id.DefaultAsyncTraceId) Test(org.junit.Test)

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