Search in sources :

Example 16 with SlowOperContext

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

the class RabbitmqConsumerAdapter method afterPreCap.

@Override
public void afterPreCap(InvokeChainContext context, Object[] args) {
    if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
        AMQP.BasicProperties props = (BasicProperties) args[2];
        byte[] body = (byte[]) args[3];
        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);
        }
        String url = (String) context.get(CaptureConstants.INFO_APPSERVER_CONNECTOR_REQUEST_URL);
        Span span = this.spanFactory.getSpanFromContext(url);
        if (span == null || span.getEndpointInfo() == null) {
            if (logger.isDebugable()) {
                logger.debug("Span of context is null, url=" + url, null);
            }
            return;
        }
        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 : BasicProperties(com.rabbitmq.client.AMQP.BasicProperties) SlowOperContext(com.creditease.uav.apm.slowoper.spi.SlowOperContext) AMQP(com.rabbitmq.client.AMQP) BasicProperties(com.rabbitmq.client.AMQP.BasicProperties) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Span(com.creditease.uav.apm.invokechain.span.Span)

Example 17 with SlowOperContext

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

the class MethodSpanAdapter method afterDoCap.

@Override
public void afterDoCap(InvokeChainContext context, Object[] args) {
    if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
        String storekey = (String) context.get(InvokeChainConstants.METHOD_SPAN_STOREKEY);
        if (storekey == null) {
            return;
        }
        Span span = (Span) context.get(storekey);
        if (span == null) {
            return;
        }
        SlowOperContext slowOperContext = new SlowOperContext();
        slowOperContext.put(SlowOperConstants.PROTOCOL_METHOD_RETURN, parseReturn(args));
        Object[] params = { span, slowOperContext };
        UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.SlowOperSupporter", "runCap", SlowOperConstants.SLOW_OPER_METHOD, InvokeChainConstants.CapturePhase.DOCAP, context, params);
    }
}
Also used : SlowOperContext(com.creditease.uav.apm.slowoper.spi.SlowOperContext) Span(com.creditease.uav.apm.invokechain.span.Span)

Example 18 with SlowOperContext

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

the class MethodSpanAdapter 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.METHOD_SPAN_STOREKEY);
        Span span = (Span) context.get(storekey);
        SlowOperContext slowOperContext = new SlowOperContext();
        slowOperContext.put(SlowOperConstants.PROTOCOL_METHOD_PARAMS, parseParams(args));
        Object[] params = { span, slowOperContext };
        // 由于使用Endpoint Info不能区分方法级,故此处使用常量
        UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.SlowOperSupporter", "runCap", SlowOperConstants.SLOW_OPER_METHOD, InvokeChainConstants.CapturePhase.PRECAP, context, params);
    }
}
Also used : SlowOperContext(com.creditease.uav.apm.slowoper.spi.SlowOperContext) Span(com.creditease.uav.apm.invokechain.span.Span)

Example 19 with SlowOperContext

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

the class ServerSpanAdapter method afterPreCap.

@Override
public void afterPreCap(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.getSpanFromContext(url);
        SlowOperContext slowOperContext = new SlowOperContext();
        HttpServletRequest request = (HttpServletRequest) args[0];
        // 由于会存在没有拦截住的情况,但当前无论拦截与未拦截的情况均可以使用HttpServletRequest获取header,故此处预留出来
        // if (RewriteIvcRequestWrapper.class.isAssignableFrom(args[0].getClass())) {
        // }
        // else {
        // 
        // }
        // 当前将所有header信息打印出来,后续可能只打印用户自定义的将UAV的header过滤
        // 提取参数并放入header里
        String parameters = JSONHelper.toString(request.getParameterMap());
        if (parameters == null) {
            parameters = "{}";
        }
        slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_REQ_HEADER, getRequestHeaders(request) + parameters);
        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 : HttpServletRequest(javax.servlet.http.HttpServletRequest) SlowOperContext(com.creditease.uav.apm.slowoper.spi.SlowOperContext) Span(com.creditease.uav.apm.invokechain.span.Span)

Example 20 with SlowOperContext

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

the class AbstractSlowOperHandler method preCap.

@Override
public void preCap(InvokeChainContext context, Object[] args) {
    Span span = (Span) args[0];
    SlowOperSpan slowOperSpan = this.spanFactory.buildSlowOperSpan(span);
    SlowOperContext slowOperContext = (SlowOperContext) args[1];
    buildSpanContent(slowOperContext, slowOperSpan);
    this.spanFactory.setSlowOperSpanToContext(this.getSlowOperSpanKey(span), slowOperSpan);
}
Also used : SlowOperSpan(com.creditease.uav.apm.slowoper.span.SlowOperSpan) SlowOperContext(com.creditease.uav.apm.slowoper.spi.SlowOperContext) Span(com.creditease.uav.apm.invokechain.span.Span) SlowOperSpan(com.creditease.uav.apm.slowoper.span.SlowOperSpan)

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