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;
}
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);
}
}
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();
}
}
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);
}
}
}
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);
}
Aggregations