use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation 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);
}
}
use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.
the class HttpRequestExecuteAsyncMethodInterceptor method after.
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
if (isDebug) {
logger.afterInterceptor(target, args);
}
final Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
try {
SpanEventRecorder recorder = trace.currentSpanEventRecorder();
recorder.recordApi(methodDescriptor);
recorder.recordServiceType(HttpClientConstants.HTTP_CLIENT_INTERNAL);
recorder.recordException(throwable);
// remove async id.
InterceptorScopeInvocation transaction = interceptorScope.getCurrentInvocation();
if (transaction != null) {
// clear
transaction.removeAttachment();
}
} finally {
trace.traceBlockEnd();
}
}
use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.
the class HttpMethodBaseRequestAndResponseMethodInterceptor method after.
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
if (isDebug) {
logger.afterInterceptor(target, methodDescriptor.getClassName(), methodDescriptor.getMethodName(), "", args, result, throwable);
}
final Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
if (invocation != null && invocation.getAttachment() != null && invocation.getAttachment() instanceof HttpClient3CallContext) {
HttpClient3CallContext callContext = (HttpClient3CallContext) invocation.getAttachment();
if (methodDescriptor.getMethodName().equals("writeRequest")) {
callContext.setWriteEndTime(System.currentTimeMillis());
callContext.setWriteFail(throwable != null);
} else {
callContext.setReadEndTime(System.currentTimeMillis());
callContext.setReadFail(throwable != null);
}
logger.debug("Set call context {}", callContext);
}
}
use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation 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.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.
the class HttpEngineSendRequestMethodInterceptor method before.
@Override
public void before(Object target, Object[] args) {
if (isDebug) {
logger.beforeInterceptor(target, args);
}
final Trace trace = traceContext.currentRawTraceObject();
if (trace == null) {
return;
}
if (!validate(target)) {
return;
}
if (!trace.canSampled()) {
return;
}
SpanEventRecorder recorder = trace.traceBlockBegin();
try {
final TraceId nextId = trace.getTraceId().getNextTraceId();
recorder.recordNextSpanId(nextId.getSpanId());
recorder.recordServiceType(OkHttpConstants.OK_HTTP_CLIENT);
InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
if (invocation != null) {
invocation.getOrCreateAttachment(new AttachmentFactory() {
@Override
public Object createAttachment() {
return nextId;
}
});
}
} catch (Throwable t) {
logger.warn("Failed to BEFORE process. {}", t.getMessage(), t);
}
}
Aggregations