use of com.navercorp.pinpoint.bootstrap.context.AsyncTraceId in project pinpoint by naver.
the class DefaultBaseTraceFactory method continueAsyncTraceObject.
// internal async trace.
@Override
public Trace continueAsyncTraceObject(AsyncTraceId traceId, int asyncId, long startTime) {
final TraceId parentTraceId = traceId.getParentTraceId();
final Storage storage = storageFactory.createStorage();
final Storage asyncStorage = new AsyncStorage(storage);
final Trace trace = new DefaultTrace(callStackFactory, asyncStorage, parentTraceId, AtomicIdGenerator.UNTRACKED_ID, asyncIdGenerator, true, spanFactory, recorderFactory);
final AsyncTrace asyncTrace = new AsyncTrace(trace, asyncId, traceId.nextAsyncSequence(), startTime);
return asyncTrace;
}
use of com.navercorp.pinpoint.bootstrap.context.AsyncTraceId in project pinpoint by naver.
the class SpanAsyncEventSimpleAroundInterceptor method after.
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
if (isDebug) {
logger.afterInterceptor(target, args, result, throwable);
}
final AsyncTraceId asyncTraceId = getAsyncTraceId(target);
if (asyncTraceId == null) {
logger.debug("Not found asynchronous invocation metadata");
return;
}
Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
// leave scope.
if (!leaveAsyncTraceScope(trace)) {
if (logger.isWarnEnabled()) {
logger.warn("Failed to leave scope of async trace {}.", trace);
}
// delete unstable trace.
deleteAsyncTrace(trace);
return;
}
try {
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
doInAfterTrace(recorder, target, args, result, throwable);
} catch (Throwable th) {
if (logger.isWarnEnabled()) {
logger.warn("AFTER error. Caused:{}", th.getMessage(), th);
}
} finally {
trace.traceBlockEnd();
if (isAsyncTraceDestination(trace)) {
deleteAsyncTrace(trace);
}
finishAsyncState(asyncTraceId);
}
}
use of com.navercorp.pinpoint.bootstrap.context.AsyncTraceId in project pinpoint by naver.
the class HttpServletRequestImplInterceptor 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(ResinConstants.RESIN_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 DefaultClientExchangeHandlerImplStartMethodInterceptor method before.
@Override
public void before(Object target, Object[] args) {
if (isDebug) {
logger.beforeInterceptor(target, "", methodDescriptor.getMethodName(), "", args);
}
final Trace trace = traceContext.currentRawTraceObject();
if (trace == null) {
return;
}
final HttpRequest httpRequest = getHttpRequest(target);
final boolean sampling = trace.canSampled();
if (!sampling) {
if (isDebug) {
logger.debug("set Sampling flag=false");
}
if (httpRequest != null) {
httpRequest.setHeader(Header.HTTP_SAMPLED.toString(), SamplingFlagUtils.SAMPLING_RATE_FALSE);
}
return;
}
SpanEventRecorder recorder = trace.traceBlockBegin();
// set remote trace
final TraceId nextId = trace.getTraceId().getNextTraceId();
recorder.recordNextSpanId(nextId.getSpanId());
recorder.recordServiceType(HttpClient4Constants.HTTP_CLIENT_4);
if (httpRequest != null) {
httpRequest.setHeader(Header.HTTP_TRACE_ID.toString(), nextId.getTransactionId());
httpRequest.setHeader(Header.HTTP_SPAN_ID.toString(), String.valueOf(nextId.getSpanId()));
httpRequest.setHeader(Header.HTTP_PARENT_SPAN_ID.toString(), String.valueOf(nextId.getParentSpanId()));
httpRequest.setHeader(Header.HTTP_FLAGS.toString(), String.valueOf(nextId.getFlags()));
httpRequest.setHeader(Header.HTTP_PARENT_APPLICATION_NAME.toString(), traceContext.getApplicationName());
httpRequest.setHeader(Header.HTTP_PARENT_APPLICATION_TYPE.toString(), Short.toString(traceContext.getServerTypeCode()));
final NameIntValuePair<String> host = getHost(target);
if (host != null) {
final String endpoint = getEndpoint(host.getName(), host.getValue());
logger.debug("Get host {}", endpoint);
httpRequest.setHeader(Header.HTTP_HOST.toString(), endpoint);
}
}
try {
if (isAsynchronousInvocation(target, args)) {
// set asynchronous trace
final AsyncTraceId asyncTraceId = trace.getAsyncTraceId();
recorder.recordNextAsyncId(asyncTraceId.getAsyncId());
// check type isAsynchronousInvocation()
((AsyncTraceIdAccessor) ((ResultFutureGetter) target)._$PINPOINT$_getResultFuture())._$PINPOINT$_setAsyncTraceId(asyncTraceId);
if (isDebug) {
logger.debug("Set asyncTraceId metadata {}", asyncTraceId);
}
}
} catch (Throwable t) {
logger.warn("Failed to BEFORE process. {}", t.getMessage(), t);
}
}
use of com.navercorp.pinpoint.bootstrap.context.AsyncTraceId in project pinpoint by naver.
the class HttpRequestExecuteAsyncMethodInterceptor 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;
}
SpanEventRecorder recorder = trace.traceBlockBegin();
try {
// set asynchronous trace
final AsyncTraceId asyncTraceId = trace.getAsyncTraceId();
recorder.recordNextAsyncId(asyncTraceId.getAsyncId());
// set async id.
InterceptorScopeInvocation transaction = interceptorScope.getCurrentInvocation();
if (transaction != null) {
transaction.setAttachment(asyncTraceId);
if (isDebug) {
logger.debug("Set asyncTraceId metadata {}", asyncTraceId);
}
}
} catch (Throwable t) {
logger.warn("Failed to before process. {}", t.getMessage(), t);
}
}
Aggregations