use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder 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.SpanEventRecorder in project pinpoint by naver.
the class TBaseProcessorProcessInterceptor method processTraceObject.
private void processTraceObject(final Trace trace, Object target, Object[] args, Throwable throwable) {
// end spanEvent
try {
SpanEventRecorder recorder = trace.currentSpanEventRecorder();
// TODO Might need a way to collect and record method arguments
// trace.recordAttribute(...);
recorder.recordException(throwable);
recorder.recordApi(this.descriptor);
} catch (Throwable t) {
logger.warn("Error processing trace object. Cause:{}", t.getMessage(), t);
} finally {
trace.traceBlockEnd();
}
// end root span
SpanRecorder recorder = trace.getSpanRecorder();
String methodUri = getMethodUri(target);
recorder.recordRpcName(methodUri);
// retrieve connection information
String localIpPort = ThriftConstants.UNKNOWN_ADDRESS;
String remoteAddress = ThriftConstants.UNKNOWN_ADDRESS;
if (args.length == 2 && args[0] instanceof TProtocol) {
TProtocol inputProtocol = (TProtocol) args[0];
TTransport inputTransport = inputProtocol.getTransport();
if (inputTransport instanceof SocketFieldAccessor) {
Socket socket = ((SocketFieldAccessor) inputTransport)._$PINPOINT$_getSocket();
if (socket != null) {
localIpPort = ThriftUtils.getHostPort(socket.getLocalSocketAddress());
remoteAddress = ThriftUtils.getHost(socket.getRemoteSocketAddress());
}
} else {
if (isDebug) {
logger.debug("Invalid target object. Need field accessor({}).", SocketFieldAccessor.class.getName());
}
}
}
if (localIpPort != ThriftConstants.UNKNOWN_ADDRESS) {
recorder.recordEndPoint(localIpPort);
}
if (remoteAddress != ThriftConstants.UNKNOWN_ADDRESS) {
recorder.recordRemoteAddress(remoteAddress);
}
}
use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder in project pinpoint by naver.
the class TBaseAsyncProcessorProcessInterceptor method processTraceObject.
private void processTraceObject(final Trace trace, Object target, Object[] args, Throwable throwable) {
// end spanEvent
try {
// TODO Might need a way to collect and record method arguments
// trace.recordAttribute(...);
SpanEventRecorder recorder = trace.currentSpanEventRecorder();
recorder.recordException(throwable);
recorder.recordApi(this.descriptor);
} catch (Throwable t) {
logger.warn("Error processing trace object. Cause:{}", t.getMessage(), t);
} finally {
trace.traceBlockEnd();
}
// end root span
SpanRecorder recorder = trace.getSpanRecorder();
String methodUri = getMethodUri(target);
recorder.recordRpcName(methodUri);
}
use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder in project pinpoint by naver.
the class ErrorPageManagerInterceptor 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.currentRawTraceObject();
if (trace == null) {
return;
}
// TODO STATDISABLE this logic was added to disable statistics tracing
if (!trace.canSampled()) {
traceContext.removeTraceObject();
return;
}
final Exception exception = (Exception) args[0];
try {
SpanEventRecorder recorder = trace.currentSpanEventRecorder();
recorder.recordApi(methodDescriptor);
recorder.recordException(exception);
} catch (Throwable th) {
if (logger.isWarnEnabled()) {
logger.warn("AFTER. Caused:{}", th.getMessage(), th);
}
} finally {
traceContext.removeTraceObject();
deleteTrace(trace, target, args, result, throwable);
}
}
use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder in project pinpoint by naver.
the class PostgreSQLConnectionCreateInterceptor method after.
@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
if (isDebug) {
logger.afterInterceptor(target, args, result, throwable);
}
if (args == null || args.length != 5) {
return;
}
Properties properties = getProperties(args[3]);
final String hostToConnectTo = properties.getProperty("PGHOST");
final Integer portToConnectTo = Integer.valueOf(properties.getProperty("PGPORT", DEFAULT_PORT));
final String databaseId = properties.getProperty("PGDBNAME");
// In case of loadbalance, connectUrl is modified.
// final String url = getString(args[4]);
DatabaseInfo databaseInfo = null;
if (hostToConnectTo != null && portToConnectTo != null && databaseId != null) {
// It's dangerous to use this url directly
databaseInfo = createDatabaseInfo(hostToConnectTo, portToConnectTo, databaseId);
if (InterceptorUtils.isSuccess(throwable)) {
// Set only if connection is success.
if (target instanceof DatabaseInfoAccessor) {
((DatabaseInfoAccessor) target)._$PINPOINT$_setDatabaseInfo(databaseInfo);
}
}
}
final Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
SpanEventRecorder recorder = trace.currentSpanEventRecorder();
// We must do this if current transaction is being recorded.
if (databaseInfo != null) {
recorder.recordServiceType(databaseInfo.getType());
recorder.recordEndPoint(databaseInfo.getMultipleHost());
recorder.recordDestinationId(databaseInfo.getDatabaseId());
}
}
Aggregations