首页 文章

在Zipkin中命名外部依赖项以绘制它

提问于
浏览
0

我正在使用Zipkin和Spring Sleuth来显示痕迹 . 当我在本地使用它时,http://localhost:9411/zipkin/dependency/会在生态系统中显示一个很好的依赖关系图 . 有时,来自外部的后端生态系统被调用,而那些不会显示在该图中 . 是否可以注释一个电话(让_667993可能,我该怎么办?

这将是我的代码基准:

@Bean
RestTemplate restTemplate() {
    return new RestTemplate();
}

@RequestMapping("/")
public String callExternalBackend() {
    return restTemplate.getForObject("https://httpbin.org/get", String.class);
}

在某个地方我想输入 httpbin 所以这个调用是在Zipkin的依赖图中绘制的 .

谢谢!


// Edit 基于当前的解决方案我'm using Spring Cloud Finchley and added the following line before restTemplate'的电话:

@RequestMapping("/")
public String callBackend() {
    spanCustomizer.tag("peer.service", "httpbin");
    return restTemplate.getForObject("https://httpbin.org/get", String.class);
}

我只是在这个类中注入 SpanCustomizer . Span被发送到Zipkin,我看到标签已设置:

enter image description here

不幸的是,它没有在依赖关系视图中绘制 . 还有什么我需要配置,可能在Zipkin而不是在 Sleuth ?

1 回答

  • 1

    EDGWARE

    你看过文件了吗?如果您在Edgware版本中使用Spring Cloud Sleuth,如果您阅读了 Sleuth 部分,您会发现这篇文章的一部分https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_custom_sa_tag_in_zipkin

    让我为你复制一下

    54.5 Zipkin中的自定义SA标记有时,您希望创建一个手动Span,它将对未检测的外部服务进行包装 . 您可以做的是使用peer.service标记创建一个span,该标记将包含您要调用的服务的值 . 下面你可以看到一个包含在这样一个范围内的Redis调用的例子 .

    org.springframework.cloud.sleuth.Span newSpan = tracer.createSpan("redis");
    try {
        newSpan.tag("redis.op", "get");
        newSpan.tag("lc", "redis");
        newSpan.logEvent(org.springframework.cloud.sleuth.Span.CLIENT_SEND);
        // call redis service e.g
        // return (SomeObj) redisTemplate.opsForHash().get("MYHASH", someObjKey);
    } finally {
        newSpan.tag("peer.service", "redisService");
        newSpan.tag("peer.ipv4", "1.2.3.4");
        newSpan.tag("peer.port", "1234");
        newSpan.logEvent(org.springframework.cloud.sleuth.Span.CLIENT_RECV);
        tracer.close(newSpan);
    }
    

    [重要]重要提示请记住不要同时添加peer.service标记和SA标记!您只需要添加peer.service .

    FINCHLEY

    SA 标签不适用于Finchley . 您必须使用 Span 上的 remoteEndpoint 以下列方式执行此操作 .

    Span span = tracer.newTrace().name("redis"); 
        span.remoteEndpoint(Endpoint.newBuilder().serviceName("redis").build()); 
        span.kind(CLIENT);
        try(SpanInScope ws = tracer.withSpanInScope(span.start())) {
              // add any tags / annotations on the span
              // return (SomeObj) redisTemplate.opsForHash().get("MYHASH", someObjKey);
        } finally {
          span.finish();
        }
    

相关问题