Search in sources :

Example 51 with SpanRecord

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

the class HttpClientv4MethodInterceptor method exceptionTrace.

@Override
public SpanRecord exceptionTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    HttpRequest request = (HttpRequest) args[1];
    SpanRecord record = new SpanRecord();
    InnerWhiteListCheckUtil.check();
    if (advice.getThrowable() instanceof SocketTimeoutException) {
        record.setResultCode(ResultCode.INVOKE_RESULT_TIMEOUT);
    } else {
        record.setResultCode(ResultCode.INVOKE_RESULT_FAILED);
    }
    try {
        record.setRequest(getParameters(request));
    } catch (Throwable e) {
    }
    record.setResponse(advice.getThrowable());
    return record;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) SocketTimeoutException(java.net.SocketTimeoutException) JSONObject(com.alibaba.fastjson.JSONObject)

Example 52 with SpanRecord

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

the class HttpClientv4MethodInterceptor method afterTrace.

@Override
public SpanRecord afterTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    HttpRequest request = (HttpRequest) args[1];
    SpanRecord record = new SpanRecord();
    if (advice.getReturnObj() instanceof HttpResponse) {
        HttpResponse response = (HttpResponse) advice.getReturnObj();
        try {
            record.setResponseSize(response == null ? 0 : response.getEntity().getContentLength());
        } catch (Throwable e) {
            record.setResponseSize(0);
        }
        int code = response.getStatusLine().getStatusCode();
        record.setResultCode(code + "");
    }
    InnerWhiteListCheckUtil.check();
    try {
        record.setRequest(getParameters(request));
    } catch (Throwable e) {
    }
    return record;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) JSONObject(com.alibaba.fastjson.JSONObject)

Example 53 with SpanRecord

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

the class HttpClientv4MethodInterceptor1 method beforeTrace.

@Override
public SpanRecord beforeTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    final HttpUriRequest request = (HttpUriRequest) args[0];
    if (request == null) {
        return null;
    }
    InnerWhiteListCheckUtil.check();
    String host = request.getURI().getHost();
    int port = request.getURI().getPort();
    String path = request.getURI().getPath();
    SpanRecord record = new SpanRecord();
    record.setService(path);
    String method = request.getMethod();
    record.setMethod(method);
    record.setRemoteIp(host);
    record.setPort(port);
    record.setMiddlewareName(HttpClientConstants.HTTP_CLIENT_NAME_4X);
    Header[] headers = request.getHeaders("content-length");
    if (headers != null && headers.length != 0) {
        try {
            Header header = headers[0];
            record.setRequestSize(Integer.valueOf(header.getValue()));
        } catch (NumberFormatException e) {
        }
    }
    // OSS 使用httpclient的时候会验证crc,提前读取request的stream流导致crc验证无法通过,先注释
    return record;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) JSONObject(com.alibaba.fastjson.JSONObject)

Example 54 with SpanRecord

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

the class HttpClientv5MethodInterceptor method afterTrace.

@Override
public SpanRecord afterTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    HttpRequest request = (HttpRequest) args[1];
    SpanRecord record = new SpanRecord();
    if (advice.getReturnObj() instanceof ClassicHttpResponse) {
        ClassicHttpResponse response = (ClassicHttpResponse) advice.getReturnObj();
        try {
            record.setResponseSize(response == null ? 0 : response.getEntity().getContentLength());
        } catch (Throwable e) {
            record.setResponseSize(0);
        }
        int code = response.getCode();
        record.setResultCode(code + "");
    }
    try {
        record.setRequest(getParameters(request));
    } catch (Throwable e) {
    }
    return record;
}
Also used : ClassicHttpRequest(org.apache.hc.core5.http.ClassicHttpRequest) HttpRequest(org.apache.hc.core5.http.HttpRequest) SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) ClassicHttpResponse(org.apache.hc.core5.http.ClassicHttpResponse) BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) JSONObject(com.alibaba.fastjson.JSONObject)

Example 55 with SpanRecord

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

the class HttpClientv5MethodInterceptor1 method afterTrace.

@Override
public SpanRecord afterTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    HttpRequest request = (HttpRequest) args[0];
    SpanRecord record = new SpanRecord();
    if (advice.getReturnObj() instanceof ClassicHttpResponse) {
        ClassicHttpResponse response = (ClassicHttpResponse) advice.getReturnObj();
        try {
            record.setResponseSize(response == null ? 0 : response.getEntity().getContentLength());
        } catch (Throwable e) {
            record.setResponseSize(0);
        }
        int code = response.getCode();
        record.setResultCode(code + "");
    } else {
        record.setResponse(advice.getReturnObj());
    }
    try {
        if (request.getHeaders(HeaderMark.DONT_READ_INPUT) == null || request.getHeaders(HeaderMark.DONT_READ_INPUT).length == 0) {
            record.setRequest(getParameters(request));
        }
    } catch (Throwable e) {
    }
    return record;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) BasicClassicHttpResponse(org.apache.hc.core5.http.message.BasicClassicHttpResponse) JSONObject(com.alibaba.fastjson.JSONObject)

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