Search in sources :

Example 26 with SpanRecord

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

the class HttpRequestExecuteMethodInterceptor method beforeTrace.

@Override
public SpanRecord beforeTrace(Advice advice) {
    InnerWhiteListCheckUtil.check();
    Object target = advice.getTarget();
    final HttpRequest request = (HttpRequest) target;
    SpanRecord record = new SpanRecord();
    record.setService(request.getUrl().getRawPath());
    record.setMethod(StringUtils.upperCase(request.getRequestMethod()));
    record.setRemoteIp(request.getUrl().getHost());
    record.setPort(request.getUrl().getPort());
    final HttpHeaders headers = request.getHeaders();
    record.setRequest(new Object[] { headers, request.getUrl().build() });
    Long contentLength = headers.getContentLength();
    contentLength = contentLength == null ? 0 : contentLength;
    record.setRequestSize(contentLength);
    record.setRemoteIp(request.getUrl().getHost());
    return record;
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) HttpHeaders(com.google.api.client.http.HttpHeaders)

Example 27 with SpanRecord

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

the class ClientCallStartInterceptor method afterTrace.

@Override
public SpanRecord afterTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    Object result = advice.getReturnObj();
    if (args == null || args.length != 2) {
        return null;
    }
    if (!(args[1] instanceof Metadata)) {
        return null;
    }
    SpanRecord record = new SpanRecord();
    record.setResponse(result == null ? 0 : result);
    record.setResultCode(ResultCode.INVOKE_RESULT_SUCCESS);
    return record;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) Metadata(io.grpc.Metadata)

Example 28 with SpanRecord

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

the class FeignMockInterceptor method afterTrace.

@Override
public SpanRecord afterTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    Method method = (Method) args[1];
    if (method == null) {
        logger.info("[debug] thread {} feign method =null , args: [{}]", Thread.currentThread(), JSON.toJSONString(args));
        return null;
    }
    SpanRecord record = new SpanRecord();
    record.setResultCode(ResultCode.INVOKE_RESULT_SUCCESS);
    record.setService(method.getDeclaringClass().getName());
    record.setMethod(method.getName() + getParameterTypesString(method.getParameterTypes()));
    record.setResponse(advice.getReturnObj());
    return record;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) Method(java.lang.reflect.Method)

Example 29 with SpanRecord

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

the class HttpEncoderInterceptor method beforeTrace.

@Override
public SpanRecord beforeTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    final HttpMessage httpMessage = (HttpMessage) args[1];
    final ChannelHandlerContext channelHandlerContext = (ChannelHandlerContext) args[0];
    Map<String, String> context = manager.getDynamicField(httpMessage, NettyConstants.DYNAMIC_FIELD_ASYNC_CONTEXT);
    if (!Pradar.hasInvokeContext(context)) {
        context = Pradar.getInvokeContextMap();
    }
    /**
     * 如果有上下文,则说明是发送请求,作为客户端
     * 否则是作为服务端接收请求
     */
    SpanRecord spanRecord = new SpanRecord();
    spanRecord.setContext(context);
    spanRecord.setRemoteIp(getHost(channelHandlerContext));
    spanRecord.setPort(getPort(channelHandlerContext));
    spanRecord.setService(getUrl(httpMessage));
    spanRecord.setMethod(getMethod(httpMessage));
    if (!Pradar.hasInvokeContext(context)) {
        spanRecord.setClusterTest(isClusterTestRequest(httpMessage));
        Map<String, String> ctx = new HashMap<String, String>();
        for (String key : Pradar.getInvokeContextTransformKeys()) {
            String value = httpMessage.headers().get(key);
            if (value != null) {
                ctx.put(key, value);
            }
        }
        if (!ctx.isEmpty()) {
            spanRecord.setContext(ctx);
        }
    }
    return spanRecord;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) HashMap(java.util.HashMap) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpMessage(io.netty.handler.codec.http.HttpMessage)

Example 30 with SpanRecord

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

the class HttpEncoderInterceptor method exceptionTrace.

@Override
public SpanRecord exceptionTrace(Advice advice) {
    SpanRecord record = new SpanRecord();
    record.setResultCode(ResultCode.INVOKE_RESULT_FAILED);
    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