【问题标题】:Cannot see the trace data in zipkin在 zipkin 中看不到跟踪数据
【发布时间】:2017-03-26 06:29:08
【问题描述】:

我是 zipkin 和用于分发跟踪的勇敢 api 的新手。我已经在我的 localhost 上设置了一个 zipkin 服务器,监听端口 9411。我已经执行了下面的函数,但我的 zipkin 服务器中没有显示跟踪数据。有人能指出我错过了什么吗?

public static void main(String[] args) {
    Sender sender = OkHttpSender.create("http://localhost:9411/api/v1/spans");
    Reporter reporter = AsyncReporter.builder(sender).build();

    // Now, create a tracer with the service name you want to see in Zipkin.
    Tracer tracer = Tracer.newBuilder()
            .localServiceName("my-service")
            .reporter(reporter)
            .build();
    Span twoPhase = tracer.newTrace().name("twoPhase").start();
    try {
        Span prepare = tracer.newChild(twoPhase.context()).name("prepare").start();
        try {
            System.out.print("prepare");
        } finally {
            prepare.finish();
        }
        Span commit = tracer.newChild(twoPhase.context()).name("commit").start();
        try {
            System.out.print("commit");
        } finally {
            commit.finish();
        }
    } finally {
        twoPhase.finish();
    }
}

【问题讨论】:

    标签: instrumentation zipkin


    【解决方案1】:

    这似乎是一个时间问题。

    如果我们添加一些延迟,例如,在子跨度执行之间添加一些延迟,例如

    Thread.sleep(1);
    

    中间

    Span prepare = tracer.newChild(twoPhase.context()).name("prepare").start();
    try {                                                                
        System.out.print("prepare");                                     
    } finally {                                                          
        prepare.finish();                                                
    }                                                                    
    Thread.sleep(1); // <<<                                                                                                                                                         
    Span commit = tracer.newChild(twoPhase.context()).name("commit").start();
    try {                                                                
        System.out.print("commit");                                      
    } finally {                                                          
        commit.finish();                                                 
    }
    

    然后我们可以看到跨度:

    我之前遇到过类似的情况,当 Zipkin 丢弃跨度时,我(错误地)分配了错误的时间戳。

    为了便于参考和复制:我设置了一个project 来复制这个问题/“修复”。

    【讨论】:

      猜你喜欢
      • 2023-03-27
      • 2021-12-24
      • 2019-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-17
      • 2020-05-08
      • 2020-07-27
      相关资源
      最近更新 更多