Search in sources :

Example 11 with SlowOperContext

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

the class JdbcDriverAdapter 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);
        SlowOperContext slowOperContext = new SlowOperContext();
        if (context.get(CaptureConstants.INFO_CLIENT_RESPONSECODE).toString().equals("-1")) {
            slowOperContext.put(SlowOperConstants.PROTOCOL_JDBC_RESULT, context.get(CaptureConstants.INFO_CLIENT_RESPONSESTATE));
        } else {
            Method method = (Method) args[0];
            if (method.getName().equals("execute")) {
                boolean res = (Boolean) args[1];
                if (res) {
                    Statement statement = (Statement) args[2];
                    try {
                        slowOperContext.put(SlowOperConstants.PROTOCOL_JDBC_RESULT, sqlResultSetParse(statement.getResultSet()));
                    } catch (SQLException e) {
                    // 由于rc的值即可判断是否有异常,故ignore
                    }
                } else {
                    Statement statement = (Statement) args[2];
                    try {
                        slowOperContext.put(SlowOperConstants.PROTOCOL_JDBC_RESULT, statement.getUpdateCount());
                    } catch (SQLException e) {
                    // 由于rc的值即可判断是否有异常,故ignore
                    }
                }
            } else if (method.getName().equals("executeBatch")) {
                int[] res = (int[]) args[1];
                StringBuilder builder = new StringBuilder("[ ");
                for (int value : res) {
                    builder.append(value + " ");
                }
                builder.append("]");
                slowOperContext.put(SlowOperConstants.PROTOCOL_JDBC_RESULT, builder.toString());
            } else {
                Statement statement = (Statement) args[2];
                try {
                    slowOperContext.put(SlowOperConstants.PROTOCOL_JDBC_RESULT, statement.getUpdateCount());
                } catch (Exception e) {
                    slowOperContext.put(SlowOperConstants.PROTOCOL_JDBC_RESULT, method.getName() + " unsupport!!!");
                }
            }
        }
        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) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Method(java.lang.reflect.Method) Span(com.creditease.uav.apm.invokechain.span.Span) SQLException(java.sql.SQLException)

Example 12 with SlowOperContext

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

the class ServerSpanAdapter 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();
        // 防止有没有拦截住的请求
        if (RewriteIvcRequestWrapper.class.isAssignableFrom(args[0].getClass()) && RewriteIvcResponseWrapper.class.isAssignableFrom(args[1].getClass())) {
            RewriteIvcRequestWrapper request = (RewriteIvcRequestWrapper) args[0];
            slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_REQ_BODY, request.getContent().toString());
            request.clearBodyContent();
            RewriteIvcResponseWrapper response = (RewriteIvcResponseWrapper) args[1];
            slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_RSP_HEADER, getResponHeaders(response));
            slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_RSP_BODY, response.getContent().toString());
            response.clearBodyContent();
        } else {
            slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_REQ_BODY, "unsupported request");
            HttpServletResponse response = (HttpServletResponse) args[1];
            slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_RSP_HEADER, getResponHeaders(response));
            slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_RSP_BODY, "unsupported response");
        }
        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) HttpServletResponse(javax.servlet.http.HttpServletResponse) Span(com.creditease.uav.apm.invokechain.span.Span) RewriteIvcRequestWrapper(com.creditease.uav.apm.RewriteIvcRequestWrapper) RewriteIvcResponseWrapper(com.creditease.uav.apm.RewriteIvcResponseWrapper)

Example 13 with SlowOperContext

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

the class RocketMQProducerAdapter method afterPreCap.

@Override
public void afterPreCap(InvokeChainContext context, Object[] args) {
    String storeKey = (String) context.get(InvokeChainConstants.CLIENT_SPAN_THREADLOCAL_STOREKEY);
    Span span = this.spanFactory.getSpanFromContext(storeKey);
    String spanMeta = this.spanFactory.getSpanMeta(span);
    Message msg = (Message) args[0];
    msg.putUserProperty(InvokeChainConstants.PARAM_MQHEAD_SPANINFO, spanMeta);
    if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
        SlowOperContext slowOperContext = new SlowOperContext();
        String content;
        try {
            content = new String(msg.getBody(), "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);
        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) Message(com.alibaba.rocketmq.common.message.Message) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Span(com.creditease.uav.apm.invokechain.span.Span)

Example 14 with SlowOperContext

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

the class JdbcDriverAdapter method afterPreCap.

@Override
public void afterPreCap(InvokeChainContext context, Object[] args) {
    if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
        @SuppressWarnings("unchecked") String sql = sqlParse(args[0].toString(), (List<Map<Integer, String>>) args[1]);
        SlowOperContext slowOperContext = new SlowOperContext();
        slowOperContext.put(SlowOperConstants.PROTOCOL_JDBC_SQL, sql);
        String url = (String) context.get(InvokeChainConstants.CLIENT_SPAN_THREADLOCAL_STOREKEY);
        Span span = this.spanFactory.getSpanFromContext(url);
        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) Map(java.util.Map) Span(com.creditease.uav.apm.invokechain.span.Span)

Example 15 with SlowOperContext

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

the class DubboConsumerAdapter method afterPreCap.

@Override
public void afterPreCap(InvokeChainContext context, Object[] args) {
    String url = (String) context.get(InvokeChainConstants.CLIENT_SPAN_THREADLOCAL_STOREKEY);
    Span span = this.spanFactory.getSpanFromContext(url);
    String spanMeta = this.spanFactory.getSpanMeta(span);
    RpcContext.getContext().setAttachment(InvokeChainConstants.PARAM_RPCHEAD_SPANINFO, spanMeta);
    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)

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