All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.boot.dubbo.zipkin.ConsumerSpan Maven / Gradle / Ivy

There is a newer version: 1.5.33
Show newest version
package com.alibaba.boot.dubbo.zipkin;


import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.Tracer;

/**
 * Created by wuyu on 2017/5/3.
 */
public class ConsumerSpan implements Filter {


    @Autowired
    private Tracer tracer;

    @Autowired
    private DubboSpanInjector dubboSpanInjector;

    public Result invoke(Invoker invoker, Invocation invocation) throws RpcException {
        URL url = invoker.getUrl();
        String spanName = url.getServiceInterface() + "." + invocation.getMethodName();
        Span newSpan = tracer.createSpan(spanName);
        try {
            dubboSpanInjector.inject(newSpan, RpcContext.getContext());
            newSpan.logEvent(Span.CLIENT_SEND);
            return invoker.invoke(invocation);
        } catch (RpcException e) {
            newSpan.tag("error", e.getMessage());
            throw e;
        } finally {
            if (tracer.isTracing()) {
                tracer.getCurrentSpan().logEvent(Span.CLIENT_RECV);
                tracer.close(tracer.getCurrentSpan());
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy