java - 无法使用 spring-boot 应用程序从 Jaeger UI 跟踪服务
问题描述
无法在 Jaeger UI (localhost:16686/search) 上跟踪 springboot 应用程序的服务。在这里,我能够成功运行应用程序,但无法在 jaeger ui 中获得服务(默认一个 jaeger-query 除外)。
我使用 docker cmd 启动了 jaeger 服务,
docker run --rm -it --network=host jaegertracing/all-in-one
在http://localhost:16686/search上打开 Jaeger UI
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
import com.uber.jaeger.Configuration;
import com.uber.jaeger.samplers.ProbabilisticSampler;
@SpringBootApplication
public class DemoOpentracing1Application {
@Bean
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
return restTemplateBuilder.build();
}
@Bean
public io.opentracing.Tracer jaegerTracer() {
return new Configuration("spring-boot", new Configuration.SamplerConfiguration(ProbabilisticSampler.TYPE, 1),
new Configuration.ReporterConfiguration())
.getTracer();
}
public static void main(String[] args) {
SpringApplication.run(DemoOpentracing1Application.class, args);
}
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
public class HelloController {
@Autowired
private RestTemplate restTemplate;
@RequestMapping("/hello")
public String hello() {
return "Hello from Spring Boot!";
}
@RequestMapping("/chaining")
public String chaining() {
ResponseEntity<String> response = restTemplate.getForEntity("http://localhost:8082/hello", String.class);
return "Chaining + " + response.getBody();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo_opentracing1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo_opentracing1</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-spring-web-autoconfigure</artifactId>
<version>0.0.4</version>
</dependency>
<dependency>
<groupId>com.uber.jaeger</groupId>
<artifactId>jaeger-core</artifactId>
<version>0.18.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
带有演示的 Github 存储库:https ://github.com/pavolloffay/opentracing-java-examples 。请帮我解决这个问题。
解决方案
问题是您的 Jaeger 收集器无法从您在 docker 命令中指定的外部 docker 网络主机访问。这仅在您的 Spring Boot 应用程序也部署在主机网络上时才有效。尝试按如下方式运行 Jaeger:
docker run -d --name jaeger \
-e COLLECTOR_ZIPKIN_HTTP_PORT=9411 \
-p 5775:5775/udp \
-p 6831:6831/udp \
-p 6832:6832/udp \
-p 5778:5778 \
-p 16686:16686 \
-p 14268:14268 \
-p 14250:14250 \
-p 9411:9411 \
jaegertracing/all-in-one:1.17
它应该触发。
推荐阅读
- javascript - 如何显示文档选择器对话框 - Alfresco 6
- android - 类 DescriptorExtractor 在适用于 Android 的 opencv 4.1.0 中不可用
- azure - 需要在电子邮件通知中发送发布测试结果图表
- postgresql - 禁止用户的所有者对该表进行 GRANTing
- r - kable 降价报告中的所有表格
- excel - 如何修复在没有按钮但不使用按钮时执行的 VBA 回归代码
- javascript - 在 GoDaddy 服务器上使用 javascript 写入文本文件
- json - 正确查询此 JSON 对象
- asp.net - 可以从本地主机发布到服务器数据库,但是当发布到服务器时,我得到“错误:52 - 无法找到本地数据库运行时安装。”
- python - Django 问卷,每个答案有几个分数类别