Search in sources :

Example 96 with SpanRecord

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

the class HttpClientv4MethodInterceptor1 method exceptionTrace.

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

Example 97 with SpanRecord

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

the class HttpClientv4MethodInterceptor1 method afterTrace.

@Override
public SpanRecord afterTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    HttpUriRequest request = (HttpUriRequest) args[0];
    SpanRecord record = new SpanRecord();
    InnerWhiteListCheckUtil.check();
    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 + "");
    } 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) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) JSONObject(com.alibaba.fastjson.JSONObject)

Example 98 with SpanRecord

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

the class HttpClientv5MethodInterceptor method exceptionTrace.

@Override
public SpanRecord exceptionTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    HttpRequest request = (HttpRequest) args[1];
    SpanRecord record = new SpanRecord();
    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 : ClassicHttpRequest(org.apache.hc.core5.http.ClassicHttpRequest) HttpRequest(org.apache.hc.core5.http.HttpRequest) SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) SocketTimeoutException(java.net.SocketTimeoutException) JSONObject(com.alibaba.fastjson.JSONObject)

Example 99 with SpanRecord

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

the class HttpClientv5MethodInterceptor method beforeTrace.

@Override
public SpanRecord beforeTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    HttpHost httpHost = (HttpHost) args[0];
    final HttpRequest request = (HttpRequest) args[1];
    if (httpHost == null) {
        return null;
    }
    URI uri = null;
    try {
        uri = request.getUri();
    } catch (URISyntaxException e) {
        logger.error("获取不到url", e);
    }
    String host = httpHost.getHostName();
    int port = httpHost.getPort();
    String path = uri.getPath();
    SpanRecord record = new SpanRecord();
    record.setService(path);
    String reqStr = request.toString();
    String httpType = StringUtils.upperCase(reqStr.substring(0, reqStr.indexOf(" ")));
    record.setMethod(httpType);
    record.setRemoteIp(host);
    record.setPort(port);
    record.setMiddlewareName(HttpClientConstants.HTTP_CLIENT_NAME_5X);
    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) {
        }
    }
    record.setRemoteIp(httpHost.getHostName());
    return record;
}
Also used : ClassicHttpRequest(org.apache.hc.core5.http.ClassicHttpRequest) HttpRequest(org.apache.hc.core5.http.HttpRequest) SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) Header(org.apache.hc.core5.http.Header) HttpHost(org.apache.hc.core5.http.HttpHost) JSONObject(com.alibaba.fastjson.JSONObject) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 100 with SpanRecord

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

the class HttpClientv5MethodInterceptor1 method beforeTrace.

@Override
public SpanRecord beforeTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    final HttpRequest request = (HttpRequest) args[0];
    if (request == null) {
        return null;
    }
    URI uri = null;
    try {
        uri = request.getUri();
    } catch (URISyntaxException e) {
        logger.error("获取不到url", e);
    }
    String host = uri.getHost();
    int port = uri.getPort();
    String path = uri.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_5X);
    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) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

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