Search in sources :

Example 21 with Span

use of com.creditease.uav.apm.invokechain.span.Span 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 22 with Span

use of com.creditease.uav.apm.invokechain.span.Span in project uavstack by uavorg.

the class MQSlowOperHandler method doCap.

@Override
public void doCap(InvokeChainContext context, Object[] args) {
    Span span = (Span) args[0];
    DataLogger invokeChainLogger = this.getAppInvokeChainLogger(span.getAppid());
    if (invokeChainLogger == null) {
        return;
    }
    SlowOperSpan slowOperSpan = this.spanFactory.getRemoveSlowOperSpanFromContext(this.getSlowOperSpanKey(span));
    if (slowOperSpan == null) {
        return;
    }
    invokeChainLogger.logData(slowOperSpan.toString());
}
Also used : SlowOperSpan(com.creditease.uav.apm.slowoper.span.SlowOperSpan) DataLogger(com.creditease.monitor.log.DataLogger) Span(com.creditease.uav.apm.invokechain.span.Span) SlowOperSpan(com.creditease.uav.apm.slowoper.span.SlowOperSpan)

Example 23 with Span

use of com.creditease.uav.apm.invokechain.span.Span in project uavstack by uavorg.

the class ApacheAsyncHttpClientAdapter method afterPreCap.

@Override
public void afterPreCap(InvokeChainContext context, Object[] args) {
    HttpAsyncRequestProducer requestProducer = null;
    HttpRequest request = null;
    if (args.length == 4) {
        requestProducer = (HttpAsyncRequestProducer) args[0];
    } else if (args.length == 5) {
        requestProducer = (HttpAsyncRequestProducer) args[1];
    } else {
        return;
    }
    try {
        request = requestProducer.generateRequest();
    } catch (Exception e) {
    // ignore
    }
    if (request == null) {
        return;
    }
    /**
     * after precap the client's span is created, set the span meta into http request header
     */
    String url = (String) context.get(InvokeChainConstants.CLIENT_SPAN_THREADLOCAL_STOREKEY);
    Span span = this.spanFactory.getSpanFromContext(url);
    String spanMeta = this.spanFactory.getSpanMeta(span);
    request.removeHeaders(InvokeChainConstants.PARAM_HTTPHEAD_SPANINFO);
    request.addHeader(InvokeChainConstants.PARAM_HTTPHEAD_SPANINFO, spanMeta);
    /**
     * store span into context for async
     */
    context.put(InvokeChainConstants.PARAM_SPAN_KEY, span);
    handleSlowOperSupporter(request, span, context);
}
Also used : HttpRequest(org.apache.http.HttpRequest) HttpAsyncRequestProducer(org.apache.http.nio.protocol.HttpAsyncRequestProducer) Span(com.creditease.uav.apm.invokechain.span.Span)

Example 24 with Span

use of com.creditease.uav.apm.invokechain.span.Span in project uavstack by uavorg.

the class JaxWSAdapter 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);
    List<String> spanValue = new ArrayList<String>(1);
    spanValue.add(spanMeta);
    Map<String, List<String>> header = new HashMap<String, List<String>>(1);
    header.put(InvokeChainConstants.PARAM_HTTPHEAD_SPANINFO, spanValue);
    String method = (String) context.get(CaptureConstants.INFO_CLIENT_REQUEST_ACTION);
    List<String> methodValue = new ArrayList<String>(1);
    methodValue.add(method);
    header.put(InvokeChainConstants.CLIENT_IT_METHOD, methodValue);
    context.put(InvokeChainConstants.PARAM_HTTPHEAD_SPANINFO, header);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Span(com.creditease.uav.apm.invokechain.span.Span)

Example 25 with Span

use of com.creditease.uav.apm.invokechain.span.Span 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)

Aggregations

Span (com.creditease.uav.apm.invokechain.span.Span)37 SlowOperContext (com.creditease.uav.apm.slowoper.spi.SlowOperContext)20 DataLogger (com.creditease.monitor.log.DataLogger)6 SlowOperSpan (com.creditease.uav.apm.slowoper.span.SlowOperSpan)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 Invocation (com.alibaba.dubbo.rpc.Invocation)2 Result (com.alibaba.dubbo.rpc.Result)2 AMQP (com.rabbitmq.client.AMQP)2 BasicProperties (com.rabbitmq.client.AMQP.BasicProperties)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 HttpMethod (org.apache.commons.httpclient.HttpMethod)2 Header (org.apache.http.Header)2 HttpEntity (org.apache.http.HttpEntity)2 HttpRequest (org.apache.http.HttpRequest)2 HttpResponse (org.apache.http.HttpResponse)2 BufferedHttpEntity (org.apache.http.entity.BufferedHttpEntity)2 Message (com.alibaba.rocketmq.common.message.Message)1