Search in sources :

Example 6 with SlowOperContext

use of com.creditease.uav.apm.slowoper.spi.SlowOperContext in project uavstack by uavorg.

the class DubboConsumerAdapter method afterDoCap.

@Override
public void afterDoCap(InvokeChainContext context, Object[] args) {
    if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
        Span span = (Span) context.get(InvokeChainConstants.PARAM_SPAN_KEY);
        if (span == null) {
            return;
        }
        SlowOperContext slowOperContext = new SlowOperContext();
        // 根据返回码确定当前是否有异常(由于IT位置已经解析过,此处直接使用)
        int respCode = (Integer) context.get(CaptureConstants.INFO_CLIENT_RESPONSECODE);
        if (respCode == -1) {
            slowOperContext.put(SlowOperConstants.PROTOCOL_METHOD_RETURN, parseReturn(context.get(CaptureConstants.INFO_CLIENT_RESPONSESTATE)));
        } else {
            Result result = (Result) args[2];
            slowOperContext.put(SlowOperConstants.PROTOCOL_METHOD_RETURN, parseReturn(result.getValue()));
        }
        Object[] params = { span, slowOperContext };
        UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.SlowOperSupporter", "runCap", span.getEndpointInfo().split(",")[0], InvokeChainConstants.CapturePhase.DOCAP, context, params);
    }
}
Also used : SlowOperContext(com.creditease.uav.apm.slowoper.spi.SlowOperContext) Span(com.creditease.uav.apm.invokechain.span.Span) Result(com.alibaba.dubbo.rpc.Result)

Example 7 with SlowOperContext

use of com.creditease.uav.apm.slowoper.spi.SlowOperContext in project uavstack by uavorg.

the class DubboProviderAdapter method afterDoCap.

@Override
public void afterDoCap(InvokeChainContext context, Object[] args) {
    if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
        String url = (String) context.get(CaptureConstants.INFO_APPSERVER_CONNECTOR_REQUEST_URL);
        Span span = this.spanFactory.getRemoveSpanFromContext(url);
        if (span == null) {
            return;
        }
        SlowOperContext slowOperContext = new SlowOperContext();
        // 根据返回码确定当前是否有异常(由于IT位置已经解析过,此处直接使用)
        String respCode = (String) context.get(CaptureConstants.INFO_APPSERVER_CONNECTOR_RESPONSECODE);
        if (respCode.equals("-1")) {
            slowOperContext.put(SlowOperConstants.PROTOCOL_METHOD_RETURN, parseReturn(context.get(CaptureConstants.INFO_APPSERVER_CONNECTOR_RESPONSESTATE)));
        } else {
            Result result = (Result) args[2];
            slowOperContext.put(SlowOperConstants.PROTOCOL_METHOD_RETURN, parseReturn(result.getValue()));
        }
        Object[] params = { span, slowOperContext };
        UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.SlowOperSupporter", "runCap", span.getEndpointInfo().split(",")[0], InvokeChainConstants.CapturePhase.DOCAP, context, params);
    }
}
Also used : SlowOperContext(com.creditease.uav.apm.slowoper.spi.SlowOperContext) Span(com.creditease.uav.apm.invokechain.span.Span) Result(com.alibaba.dubbo.rpc.Result)

Example 8 with SlowOperContext

use of com.creditease.uav.apm.slowoper.spi.SlowOperContext in project uavstack by uavorg.

the class DubboProviderAdapter method afterPreCap.

@Override
public void afterPreCap(InvokeChainContext context, Object[] args) {
    String url = (String) context.get(CaptureConstants.INFO_APPSERVER_CONNECTOR_REQUEST_URL);
    Span span = this.spanFactory.getSpanFromContext(url);
    if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
        SlowOperContext slowOperContext = new SlowOperContext();
        // dubbo虽属于rpc,但从其使用方式上属于方法级
        Invocation invocation = (Invocation) args[1];
        slowOperContext.put(SlowOperConstants.PROTOCOL_METHOD_PARAMS, parseParams(invocation.getArguments()));
        Object[] params = { span, slowOperContext };
        UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.SlowOperSupporter", "runCap", span.getEndpointInfo().split(",")[0], InvokeChainConstants.CapturePhase.PRECAP, context, params);
    }
}
Also used : SlowOperContext(com.creditease.uav.apm.slowoper.spi.SlowOperContext) Invocation(com.alibaba.dubbo.rpc.Invocation) Span(com.creditease.uav.apm.invokechain.span.Span)

Example 9 with SlowOperContext

use of com.creditease.uav.apm.slowoper.spi.SlowOperContext in project uavstack by uavorg.

the class RocketMQPushConsumerAdapter method afterPreCap.

@Override
public void afterPreCap(InvokeChainContext context, Object[] args) {
    if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
        String storeKey = (String) context.get(InvokeChainConstants.CLIENT_SPAN_THREADLOCAL_STOREKEY);
        Span span = this.spanFactory.getSpanFromContext(storeKey);
        if (span == null) {
            return;
        }
        @SuppressWarnings("unchecked") List<MessageExt> exts = (List<MessageExt>) args[0];
        String content;
        try {
            content = new String(exts.get(0).getBody(), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            content = "unsupported encoding,defalut is utf-8.try to set ContentEncoding to fit.";
        }
        SlowOperContext slowOperContext = new SlowOperContext();
        slowOperContext.put(SlowOperConstants.PROTOCOL_MQ_RABBIT_BODY, content);
        Object[] params = { span, slowOperContext };
        UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.SlowOperSupporter", "runCap", span.getEndpointInfo().split(",")[0], InvokeChainConstants.CapturePhase.PRECAP, context, params);
    }
}
Also used : MessageExt(com.alibaba.rocketmq.common.message.MessageExt) SlowOperContext(com.creditease.uav.apm.slowoper.spi.SlowOperContext) UnsupportedEncodingException(java.io.UnsupportedEncodingException) List(java.util.List) Span(com.creditease.uav.apm.invokechain.span.Span)

Example 10 with SlowOperContext

use of com.creditease.uav.apm.slowoper.spi.SlowOperContext in project uavstack by uavorg.

the class RabbitmqProducerAdapter method afterPreCap.

@Override
public void afterPreCap(InvokeChainContext context, Object[] args) {
    AMQP.BasicProperties props = (BasicProperties) args[0];
    Map<String, Object> header = new HashMap<String, Object>();
    String storeKey = (String) context.get(InvokeChainConstants.CLIENT_SPAN_THREADLOCAL_STOREKEY);
    Span span = this.spanFactory.getSpanFromContext(storeKey);
    String spanMeta = this.spanFactory.getSpanMeta(span);
    header.put(InvokeChainConstants.PARAM_MQHEAD_SPANINFO, spanMeta);
    if (props == null) {
        props = new AMQP.BasicProperties.Builder().headers(header).build();
    } else {
        if (props.getHeaders() != null) {
            header.putAll(props.getHeaders());
        }
        props = new AMQP.BasicProperties.Builder().appId(props.getAppId()).clusterId(props.getClusterId()).contentEncoding(props.getContentEncoding()).contentType(props.getContentType()).correlationId(props.getCorrelationId()).deliveryMode(props.getDeliveryMode()).expiration(props.getExpiration()).headers(header).messageId(props.getMessageId()).priority(props.getPriority()).replyTo(props.getReplyTo()).timestamp(props.getTimestamp()).type(props.getType()).userId(props.getUserId()).build();
    }
    context.put(InvokeChainConstants.PARAM_MQHEAD_INFO, props);
    if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
        byte[] body = (byte[]) args[1];
        SlowOperContext slowOperContext = new SlowOperContext();
        if (props == null || StringHelper.isEmpty(props.getContentEncoding())) {
            String content = "";
            try {
                content = new String(body, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                content = "unsupported encoding,defalut is utf-8.try to set ContentEncoding to fit.";
            }
            slowOperContext.put(SlowOperConstants.PROTOCOL_MQ_RABBIT_BODY, content);
        } else {
            String encoding = props.getContentEncoding();
            String content = "";
            try {
                content = new String(body, encoding);
            } catch (UnsupportedEncodingException e) {
                content = "ContentEncoding is " + encoding + " .but content is unsupported this encoding.";
            }
            slowOperContext.put(SlowOperConstants.PROTOCOL_MQ_RABBIT_BODY, content);
        }
        Object[] params = { span, slowOperContext };
        UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.SlowOperSupporter", "runCap", span.getEndpointInfo().split(",")[0], InvokeChainConstants.CapturePhase.PRECAP, context, params);
    }
}
Also used : SlowOperContext(com.creditease.uav.apm.slowoper.spi.SlowOperContext) BasicProperties(com.rabbitmq.client.AMQP.BasicProperties) HashMap(java.util.HashMap) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Span(com.creditease.uav.apm.invokechain.span.Span) BasicProperties(com.rabbitmq.client.AMQP.BasicProperties) AMQP(com.rabbitmq.client.AMQP)

Aggregations

SlowOperContext (com.creditease.uav.apm.slowoper.spi.SlowOperContext)21 Span (com.creditease.uav.apm.invokechain.span.Span)20 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 IOException (java.io.IOException)3 Header (org.apache.http.Header)3 HttpEntity (org.apache.http.HttpEntity)3 BufferedHttpEntity (org.apache.http.entity.BufferedHttpEntity)3 Invocation (com.alibaba.dubbo.rpc.Invocation)2 Result (com.alibaba.dubbo.rpc.Result)2 SlowOperSpan (com.creditease.uav.apm.slowoper.span.SlowOperSpan)2 AMQP (com.rabbitmq.client.AMQP)2 BasicProperties (com.rabbitmq.client.AMQP.BasicProperties)2 HttpMethod (org.apache.commons.httpclient.HttpMethod)2 HttpResponse (org.apache.http.HttpResponse)2 Message (com.alibaba.rocketmq.common.message.Message)1 MessageExt (com.alibaba.rocketmq.common.message.MessageExt)1 DataLogger (com.creditease.monitor.log.DataLogger)1 RewriteIvcRequestWrapper (com.creditease.uav.apm.RewriteIvcRequestWrapper)1 RewriteIvcResponseWrapper (com.creditease.uav.apm.RewriteIvcResponseWrapper)1 BufferedReader (java.io.BufferedReader)1