Search in sources :

Example 46 with SpanRecord

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

the class AbstractCommonTraceInterceptor method afterTrace.

@Override
public SpanRecord afterTrace(Advice advice) {
    SpanRecord record = new SpanRecord();
    record.setMethod(advice.getBehaviorName());
    record.setResponse(advice.getReturnObj());
    record.setClusterTest(Pradar.isClusterTest());
    record.setService(advice.getTarget().getClass().getName());
    return record;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord)

Example 47 with SpanRecord

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

the class AbstractCommonTraceInterceptor method beforeTrace.

@Override
public SpanRecord beforeTrace(Advice advice) {
    SpanRecord record = new SpanRecord();
    record.setMethod(advice.getBehaviorName());
    record.setRequest(advice.getParameterArray());
    record.setClusterTest(Pradar.isClusterTest());
    record.setService(advice.getTarget().getClass().getName());
    return record;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord)

Example 48 with SpanRecord

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

the class HttpClientv3MethodInterceptor method beforeTrace.

@Override
public SpanRecord beforeTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    final HttpMethod method = (HttpMethod) args[1];
    if (method == null) {
        return null;
    }
    InnerWhiteListCheckUtil.check();
    try {
        SpanRecord record = new SpanRecord();
        int port = method.getURI().getPort();
        record.setService(method.getURI().getPath());
        record.setMethod(StringUtils.upperCase(method.getName()));
        Header header = method.getRequestHeader("content-length");
        if (header != null && StringUtils.isNotBlank(header.getValue())) {
            try {
                record.setRequestSize(Integer.valueOf(header.getValue()));
            } catch (NumberFormatException e) {
            }
        }
        if ("get".equals(record.getMethod()) || "GET".equals(record.getMethod()) || "head".equals(record.getMethod()) || "HEAD".equals(record.getMethod())) {
            record.setRequest(toMap(method.getQueryString()));
        } else {
            Map parameters = new HashMap();
            buildParameters(method.getParams(), parameters);
            parameters.putAll(toMap(method.getQueryString()));
            record.setRequest(parameters);
        }
        record.setMiddlewareName(HttpClientConstants.HTTP_CLIENT_NAME_3X);
        record.setRemoteIp(method.getURI().getHost());
        record.setPort(port);
        return record;
    } catch (URIException e) {
        return null;
    }
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) URIException(org.apache.commons.httpclient.URIException) Header(org.apache.commons.httpclient.Header) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 49 with SpanRecord

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

the class HttpClientv3MethodInterceptor method exceptionTrace.

@Override
public SpanRecord exceptionTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    HttpMethod method = (HttpMethod) args[1];
    if (method == null) {
        return null;
    }
    try {
        SpanRecord record = new SpanRecord();
        if (advice.getThrowable() instanceof SocketTimeoutException) {
            record.setResultCode(ResultCode.INVOKE_RESULT_TIMEOUT);
        } else {
            record.setResultCode(ResultCode.INVOKE_RESULT_FAILED);
        }
        record.setRequest(method.getParams());
        record.setResponse(advice.getThrowable());
        InnerWhiteListCheckUtil.check();
        // record.setResponseSize(method.getResponseBody() == null ? 0 : method.getResponseBody().length);
        return record;
    } catch (Throwable e) {
        Pradar.responseSize(0);
    }
    return null;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) SocketTimeoutException(java.net.SocketTimeoutException) JSONObject(com.alibaba.fastjson.JSONObject) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 50 with SpanRecord

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

the class HttpClientv3MethodInterceptor method afterTrace.

@Override
public SpanRecord afterTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    HttpMethod method = (HttpMethod) args[1];
    if (method == null) {
        return null;
    }
    try {
        SpanRecord record = new SpanRecord();
        Integer code = (Integer) advice.getReturnObj();
        String msg = method.getURI().toString() + "->" + code;
        record.setResultCode(code + "");
        record.setResponse(msg);
        InnerWhiteListCheckUtil.check();
        // record.setResponseSize(method.getResponseBody() == null ? 0 : method.getResponseBody().length);
        return record;
    } catch (Throwable e) {
        Pradar.responseSize(0);
    }
    return null;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) JSONObject(com.alibaba.fastjson.JSONObject) HttpMethod(org.apache.commons.httpclient.HttpMethod)

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