Search in sources :

Example 1 with SocketGetter

use of com.navercorp.pinpoint.plugin.activemq.client.field.getter.SocketGetter in project pinpoint by naver.

the class ActiveMQMessageConsumerDispatchInterceptor method validateTransport.

private boolean validateTransport(ActiveMQSession session) {
    if (session == null) {
        return false;
    }
    ActiveMQConnection connection = session.getConnection();
    if (!(connection instanceof TransportGetter)) {
        if (isDebug) {
            logger.debug("Invalid connection object. Need field accessor({}).", TransportGetter.class.getName());
        }
        return false;
    }
    Transport transport = getRootTransport(((TransportGetter) connection)._$PINPOINT$_getTransport());
    if (!(transport instanceof SocketGetter)) {
        if (isDebug) {
            logger.debug("Transport not traceable({}).", transport.getClass().getName());
        }
        return false;
    }
    return true;
}
Also used : SocketGetter(com.navercorp.pinpoint.plugin.activemq.client.field.getter.SocketGetter) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) TransportGetter(com.navercorp.pinpoint.plugin.activemq.client.field.getter.TransportGetter) Transport(org.apache.activemq.transport.Transport)

Example 2 with SocketGetter

use of com.navercorp.pinpoint.plugin.activemq.client.field.getter.SocketGetter in project pinpoint by naver.

the class ActiveMQMessageProducerSendInterceptor method validateTransport.

private boolean validateTransport(ActiveMQSession session) {
    if (session == null) {
        return false;
    }
    ActiveMQConnection connection = session.getConnection();
    if (!(connection instanceof TransportGetter)) {
        if (isDebug) {
            logger.debug("Invalid connection object. Need field accessor({}).", TransportGetter.class.getName());
        }
        return false;
    }
    Transport transport = getRootTransport(((TransportGetter) connection)._$PINPOINT$_getTransport());
    if (!(transport instanceof SocketGetter)) {
        if (isDebug) {
            logger.debug("Transport not traceable({}).", transport.getClass().getName());
        }
        return false;
    }
    return true;
}
Also used : SocketGetter(com.navercorp.pinpoint.plugin.activemq.client.field.getter.SocketGetter) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) TransportGetter(com.navercorp.pinpoint.plugin.activemq.client.field.getter.TransportGetter) Transport(org.apache.activemq.transport.Transport)

Example 3 with SocketGetter

use of com.navercorp.pinpoint.plugin.activemq.client.field.getter.SocketGetter in project pinpoint by naver.

the class ActiveMQMessageConsumerDispatchInterceptor method doInBeforeTrace.

@Override
protected void doInBeforeTrace(SpanRecorder recorder, Object target, Object[] args) {
    recorder.recordServiceType(ActiveMQClientConstants.ACTIVEMQ_CLIENT);
    ActiveMQSession session = ((ActiveMQSessionGetter) target)._$PINPOINT$_getActiveMQSession();
    ActiveMQConnection connection = session.getConnection();
    Transport transport = getRootTransport(((TransportGetter) connection)._$PINPOINT$_getTransport());
    Socket socket = ((SocketGetter) transport)._$PINPOINT$_getSocket();
    SocketAddress localSocketAddress = socket.getLocalSocketAddress();
    String endPoint = ActiveMQClientUtils.getEndPoint(localSocketAddress);
    // Endpoint should be the local socket address of the consumer.
    recorder.recordEndPoint(endPoint);
    SocketAddress remoteSocketAddress = socket.getRemoteSocketAddress();
    String remoteAddress = ActiveMQClientUtils.getEndPoint(remoteSocketAddress);
    // Remote address is the socket address of where the consumer is connected to.
    recorder.recordRemoteAddress(remoteAddress);
    MessageDispatch md = (MessageDispatch) args[0];
    ActiveMQMessage message = (ActiveMQMessage) md.getMessage();
    ActiveMQDestination destination = message.getDestination();
    // Rpc name is the URI of the queue/topic we're consuming from.
    recorder.recordRpcName(destination.getQualifiedName());
    // Record acceptor host as the queue/topic name in order to generate virtual queue node.
    recorder.recordAcceptorHost(destination.getPhysicalName());
    String parentApplicationName = ActiveMQClientHeader.getParentApplicationName(message, null);
    if (!recorder.isRoot() && parentApplicationName != null) {
        short parentApplicationType = ActiveMQClientHeader.getParentApplicationType(message, ServiceType.UNDEFINED.getCode());
        recorder.recordParentApplication(parentApplicationName, parentApplicationType);
    }
}
Also used : MessageDispatch(org.apache.activemq.command.MessageDispatch) ActiveMQSessionGetter(com.navercorp.pinpoint.plugin.activemq.client.field.getter.ActiveMQSessionGetter) ActiveMQSession(org.apache.activemq.ActiveMQSession) SocketGetter(com.navercorp.pinpoint.plugin.activemq.client.field.getter.SocketGetter) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) Transport(org.apache.activemq.transport.Transport) SocketAddress(java.net.SocketAddress) Socket(java.net.Socket) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 4 with SocketGetter

use of com.navercorp.pinpoint.plugin.activemq.client.field.getter.SocketGetter in project pinpoint by naver.

the class ActiveMQMessageProducerSendInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args);
    }
    if (!validate(target, args)) {
        return;
    }
    Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    try {
        SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        recorder.recordApi(descriptor);
        if (throwable == null) {
            ActiveMQDestination destination = (ActiveMQDestination) args[0];
            // This annotation indicates the uri to which the call is made
            recorder.recordAttribute(AnnotationKey.MESSAGE_QUEUE_URI, destination.getQualifiedName());
            // DestinationId is used to render the virtual queue node.
            // We choose the queue/topic name as the logical name of the queue node.
            recorder.recordDestinationId(destination.getPhysicalName());
            ActiveMQSession session = ((ActiveMQSessionGetter) target)._$PINPOINT$_getActiveMQSession();
            ActiveMQConnection connection = session.getConnection();
            Transport transport = getRootTransport(((TransportGetter) connection)._$PINPOINT$_getTransport());
            Socket socket = ((SocketGetter) transport)._$PINPOINT$_getSocket();
            SocketAddress remoteSocketAddress = socket.getRemoteSocketAddress();
            String remoteAddress = ActiveMQClientUtils.getEndPoint(remoteSocketAddress);
            // Producer's endPoint should be the socket address of where the producer is actually connected to.
            recorder.recordEndPoint(remoteAddress);
            recorder.recordAttribute(ActiveMQClientConstants.ACTIVEMQ_BROKER_URL, remoteAddress);
        } else {
            recorder.recordException(throwable);
        }
    } catch (Throwable t) {
        logger.warn("AFTER error. Cause:{}", t.getMessage(), t);
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) ActiveMQSessionGetter(com.navercorp.pinpoint.plugin.activemq.client.field.getter.ActiveMQSessionGetter) ActiveMQSession(org.apache.activemq.ActiveMQSession) SocketGetter(com.navercorp.pinpoint.plugin.activemq.client.field.getter.SocketGetter) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) Transport(org.apache.activemq.transport.Transport) SocketAddress(java.net.SocketAddress) Socket(java.net.Socket) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Aggregations

SocketGetter (com.navercorp.pinpoint.plugin.activemq.client.field.getter.SocketGetter)4 ActiveMQConnection (org.apache.activemq.ActiveMQConnection)4 Transport (org.apache.activemq.transport.Transport)4 ActiveMQSessionGetter (com.navercorp.pinpoint.plugin.activemq.client.field.getter.ActiveMQSessionGetter)2 TransportGetter (com.navercorp.pinpoint.plugin.activemq.client.field.getter.TransportGetter)2 Socket (java.net.Socket)2 SocketAddress (java.net.SocketAddress)2 ActiveMQSession (org.apache.activemq.ActiveMQSession)2 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)2 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)1 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)1 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)1 MessageDispatch (org.apache.activemq.command.MessageDispatch)1