Search in sources :

Example 76 with SpanEventRecorder

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);
    }
}
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 77 with SpanEventRecorder

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);
    }
}
Also used : SpanRecorder(com.navercorp.pinpoint.bootstrap.context.SpanRecorder) TProtocol(org.apache.thrift.protocol.TProtocol) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) SocketFieldAccessor(com.navercorp.pinpoint.plugin.thrift.field.accessor.SocketFieldAccessor) TTransport(org.apache.thrift.transport.TTransport) Socket(java.net.Socket)

Example 78 with SpanEventRecorder

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);
}
Also used : SpanRecorder(com.navercorp.pinpoint.bootstrap.context.SpanRecorder) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)

Example 79 with SpanEventRecorder

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);
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)

Example 80 with SpanEventRecorder

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());
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) DefaultDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DefaultDatabaseInfo) DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) DatabaseInfoAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) Properties(java.util.Properties)

Aggregations

SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)86 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)75 AsyncTraceId (com.navercorp.pinpoint.bootstrap.context.AsyncTraceId)12 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)9 AsyncTraceIdAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)8 InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)8 DatabaseInfoAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor)5 DatabaseInfo (com.navercorp.pinpoint.bootstrap.context.DatabaseInfo)4 Socket (java.net.Socket)3 HttpRequest (org.apache.http.HttpRequest)3 Test (org.junit.Test)3 MethodDescriptor (com.navercorp.pinpoint.bootstrap.context.MethodDescriptor)2 ParsingResult (com.navercorp.pinpoint.bootstrap.context.ParsingResult)2 SpanRecorder (com.navercorp.pinpoint.bootstrap.context.SpanRecorder)2 TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)2 BindValueAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor)2 DefaultDatabaseInfo (com.navercorp.pinpoint.bootstrap.plugin.jdbc.DefaultDatabaseInfo)2 JdbcUrlParser (com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcUrlParser)2 ParsingResultAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor)2 UnKnownDatabaseInfo (com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo)2