Search in sources :

Example 1 with RemoteAddressFieldAccessor

use of com.navercorp.pinpoint.plugin.kafka.field.accessor.RemoteAddressFieldAccessor in project pinpoint by naver.

the class ConsumerConstructor_V_2_7_Interceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    if (throwable != null) {
        return;
    }
    if (!(target instanceof RemoteAddressFieldAccessor)) {
        return;
    }
    Map consumerConfig = getMap(args);
    if (consumerConfig == null) {
        return;
    }
    String remoteAddress = getRemoteAddress(consumerConfig);
    ((RemoteAddressFieldAccessor) target)._$PINPOINT$_setRemoteAddress(remoteAddress);
}
Also used : RemoteAddressFieldAccessor(com.navercorp.pinpoint.plugin.kafka.field.accessor.RemoteAddressFieldAccessor) Map(java.util.Map)

Example 2 with RemoteAddressFieldAccessor

use of com.navercorp.pinpoint.plugin.kafka.field.accessor.RemoteAddressFieldAccessor in project pinpoint by naver.

the class ConsumerPollInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    if (!(target instanceof RemoteAddressFieldAccessor)) {
        return;
    }
    String remoteAddress = ((RemoteAddressFieldAccessor) target)._$PINPOINT$_getRemoteAddress();
    remoteAddress = StringUtils.defaultIfEmpty(remoteAddress, KafkaConstants.UNKNOWN);
    if (result instanceof ConsumerRecords) {
        Iterator consumerRecordIterator = ((ConsumerRecords) result).iterator();
        while (consumerRecordIterator.hasNext()) {
            Object consumerRecord = consumerRecordIterator.next();
            if (consumerRecord instanceof RemoteAddressFieldAccessor) {
                ((RemoteAddressFieldAccessor) consumerRecord)._$PINPOINT$_setRemoteAddress(remoteAddress);
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) RemoteAddressFieldAccessor(com.navercorp.pinpoint.plugin.kafka.field.accessor.RemoteAddressFieldAccessor) ConsumerRecords(org.apache.kafka.clients.consumer.ConsumerRecords)

Example 3 with RemoteAddressFieldAccessor

use of com.navercorp.pinpoint.plugin.kafka.field.accessor.RemoteAddressFieldAccessor in project pinpoint by naver.

the class ProducerConstructorInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    if (throwable != null) {
        return;
    }
    if (!(target instanceof RemoteAddressFieldAccessor)) {
        return;
    }
    ProducerConfig producerConfig = getProducerConfig(args);
    if (producerConfig != null) {
        String remoteAddress = getRemoteAddress(producerConfig);
        ((RemoteAddressFieldAccessor) target)._$PINPOINT$_setRemoteAddress(remoteAddress);
        return;
    }
    // Version 2.2.0+ is supported.
    Map map = getMap(args);
    if (map != null) {
        Object remoteAddressObject = map.get(KafkaConstants.CONFIG_BOOTSTRAP_SERVERS_KEY);
        String remoteAddress = getRemoteAddress0(remoteAddressObject);
        ((RemoteAddressFieldAccessor) target)._$PINPOINT$_setRemoteAddress(remoteAddress);
        return;
    }
}
Also used : ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) RemoteAddressFieldAccessor(com.navercorp.pinpoint.plugin.kafka.field.accessor.RemoteAddressFieldAccessor) Map(java.util.Map)

Example 4 with RemoteAddressFieldAccessor

use of com.navercorp.pinpoint.plugin.kafka.field.accessor.RemoteAddressFieldAccessor in project pinpoint by naver.

the class ConsumerConstructorInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    if (throwable != null) {
        return;
    }
    if (!(target instanceof RemoteAddressFieldAccessor)) {
        return;
    }
    ConsumerConfig consumerConfig = getConsumerConfig(args);
    if (consumerConfig == null) {
        return;
    }
    String remoteAddress = getRemoteAddress(consumerConfig);
    ((RemoteAddressFieldAccessor) target)._$PINPOINT$_setRemoteAddress(remoteAddress);
}
Also used : RemoteAddressFieldAccessor(com.navercorp.pinpoint.plugin.kafka.field.accessor.RemoteAddressFieldAccessor) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig)

Aggregations

RemoteAddressFieldAccessor (com.navercorp.pinpoint.plugin.kafka.field.accessor.RemoteAddressFieldAccessor)4 Map (java.util.Map)2 Iterator (java.util.Iterator)1 ConsumerConfig (org.apache.kafka.clients.consumer.ConsumerConfig)1 ConsumerRecords (org.apache.kafka.clients.consumer.ConsumerRecords)1 ProducerConfig (org.apache.kafka.clients.producer.ProducerConfig)1