Search in sources :

Example 41 with SpanRecord

use of com.pamirs.pradar.interceptor.SpanRecord in project LinkAgent by shulieTech.

the class ChannelNBasicPublishInterceptor method beforeTrace.

@Override
public SpanRecord beforeTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    if (args == null || args.length == 0) {
        return null;
    }
    String exchange = (String) args[0];
    String routingKey = (String) args[1];
    byte[] body = (byte[]) args[5];
    SpanRecord record = new SpanRecord();
    Channel channel = (Channel) advice.getTarget();
    Connection connection = channel.getConnection();
    record.setRemoteIp(connection.getAddress().getHostAddress());
    record.setPort(connection.getPort() + "");
    record.setService(exchange);
    record.setMethod(routingKey);
    record.setRequestSize(body.length);
    record.setRequest(body);
    return record;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) Channel(com.rabbitmq.client.Channel) Connection(com.rabbitmq.client.Connection)

Example 42 with SpanRecord

use of com.pamirs.pradar.interceptor.SpanRecord in project LinkAgent by shulieTech.

the class QueueingConsumerHandleInterceptor method beforeTrace.

@Override
public SpanRecord beforeTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    if (args == null || args.length == 0 || args[0] == null) {
        return null;
    }
    Object target = advice.getTarget();
    Class<?>[] classes = target.getClass().getClasses();
    if (classes.length != 1) {
        return null;
    }
    Object deliveryObj = args[0];
    if (deliveryObj == null) {
        return null;
    }
    SpanRecord record = new SpanRecord();
    try {
        Envelope envelope = Reflect.on(deliveryObj).get(RabbitmqConstants.DYNAMIC_FIELD_ENVELOPE);
        if (envelope == null) {
            // 说明是毒药,已经报错了
            return null;
        }
        record.setService(envelope.getExchange());
        record.setMethod(envelope.getRoutingKey());
    } catch (ReflectException e) {
    }
    try {
        AMQP.BasicProperties properties = Reflect.on(deliveryObj).get(RabbitmqConstants.DYNAMIC_FIELD_PROPERTIES);
        Map<String, Object> headers = properties.getHeaders();
        if (headers != null) {
            Map<String, String> rpcContext = new HashMap<String, String>();
            for (String key : Pradar.getInvokeContextTransformKeys()) {
                Object tmp = headers.get(key);
                if (tmp != null) {
                    String value = tmp.toString();
                    if (!StringUtil.isEmpty(value)) {
                        rpcContext.put(key, value);
                    }
                }
            }
            record.setContext(rpcContext);
        }
    } catch (ReflectException e) {
    }
    try {
        byte[] body = Reflect.on(deliveryObj).get(RabbitmqConstants.DYNAMIC_FIELD_BODY);
        record.setRequestSize(body.length);
        record.setRequest(body);
    } catch (ReflectException e) {
    }
    return record;
}
Also used : HashMap(java.util.HashMap) Envelope(com.rabbitmq.client.Envelope) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) AMQP(com.rabbitmq.client.AMQP)

Example 43 with SpanRecord

use of com.pamirs.pradar.interceptor.SpanRecord in project LinkAgent by shulieTech.

the class QueueingConsumerHandleInterceptor method exceptionTrace.

@Override
public SpanRecord exceptionTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    if (args == null || args.length == 0 || args[0] == null) {
        return null;
    }
    Object target = advice.getTarget();
    Class<?>[] classes = target.getClass().getClasses();
    if (classes.length != 1) {
        return null;
    }
    Object deliveryObj = args[0];
    if (deliveryObj == null) {
        return null;
    }
    SpanRecord record = new SpanRecord();
    record.setResultCode(ResultCode.INVOKE_RESULT_FAILED);
    record.setResponse(advice.getThrowable());
    return record;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord)

Example 44 with SpanRecord

use of com.pamirs.pradar.interceptor.SpanRecord in project LinkAgent by shulieTech.

the class SpringBlockingQueueConsumerDeliveryInterceptorV2 method exceptionTrace.

@Override
public SpanRecord exceptionTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    if (args == null || args[0] == null) {
        return null;
    }
    SpanRecord record = new SpanRecord();
    record.setResultCode(ResultCode.INVOKE_RESULT_FAILED);
    record.setResponse(advice.getThrowable());
    return record;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord)

Example 45 with SpanRecord

use of com.pamirs.pradar.interceptor.SpanRecord in project LinkAgent by shulieTech.

the class SpringBlockingQueueConsumerDeliveryInterceptorV2 method afterTrace.

@Override
public SpanRecord afterTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    if (args == null || args[0] == null) {
        return null;
    }
    SpanRecord record = new SpanRecord();
    return record;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord)

Aggregations

SpanRecord (com.pamirs.pradar.interceptor.SpanRecord)199 JSONObject (com.alibaba.fastjson.JSONObject)19 SocketTimeoutException (java.net.SocketTimeoutException)15 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)13 ReflectException (com.shulie.instrument.simulator.api.reflect.ReflectException)11 HashMap (java.util.HashMap)10 List (java.util.List)8 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)6 Request (com.weibo.api.motan.rpc.Request)6 HeaderProcessor (com.pamirs.attach.plugin.apache.kafka.header.HeaderProcessor)5 WrapperRequest (com.pamirs.attach.plugin.hessian.common.WrapperRequest)5 URI (java.net.URI)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Metadata (io.grpc.Metadata)4 ServerAddress (com.mongodb.ServerAddress)3 Channel (com.rabbitmq.client.Channel)3 Connection (com.rabbitmq.client.Connection)3 Field (java.lang.reflect.Field)3 Method (java.lang.reflect.Method)3 URL (java.net.URL)3