当前位置: 首页 > 知识库问答 >
问题:

Jaeger、logback和Sleuth协同工作的问题

终翔
2023-03-14

我正在开发一个Spring Boot应用程序,其中的日志是通过logback完成的,并且集成了Jaeger用于检测。

MyService.java

@SpringBootApplication
public class Myservice{


public static void main(String[] args) {
    SpringApplication.run(Myservice.class, args);
}

@Bean
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
    return restTemplateBuilder.build();
}

 @Bean
  public io.opentracing.Tracer jaegerTracer() {
    Builder builder = new Builder("Myservice",
        new RemoteReporter(new HttpSender(http://192.168.1.20:14268/api/traces), 10,
        65000, new Metrics(new StatsFactoryImpl(new NullStatsReporter()))),
        new ConstSampler(true))
        .registerInjector(Builtin.HTTP_HEADERS, new B3TextMapCodec())
        .registerExtractor(Builtin.HTTP_HEADERS, new B3TextMapCodec());
    return builder.build();
  }
}
<?xml version="1.0" encoding="UTF-8"?>
<configuration >
 <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<springProperty scope="context" name="springAppName"
    source="spring.application.name" />
<appender name="consoleAppender" 
class="ch.qos.logback.core.ConsoleAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            Minimum logging level to be presented in the console logs
            <level>INFO</level>
        </filter>
    <encoder 
class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
        <providers>
            <pattern>
                <pattern>
                    {
                    "service": "${springAppName:-}",
                    "trace": "%X{X-B3-TraceId:-}",
                    "span": "%X{X-B3-SpanId:-}"
                    }
                </pattern>
            </pattern>
         </providers>
    </encoder>
</appender>

<root level="INFO">
    <appender-ref ref="consoleAppender" />
</root>
</configuration>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.4.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-core</artifactId>
        <version>3.1.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>

    <!-- JPA Data Dependency -->

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <!-- Oracle driver Dependency -->

    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.3</version>
    </dependency>
<!-- Opentracing with Jaeger Dependency -->

    <dependency>
        <groupId>io.opentracing</groupId>
        <artifactId>opentracing-api</artifactId>
        <version>0.31.0</version>
    </dependency>
    <dependency>
        <groupId>io.opentracing.contrib</groupId>
        <artifactId>opentracing-spring-cloud-starter</artifactId>
        <version>0.1.4</version>
    </dependency>
    <dependency>
        <groupId>com.uber.jaeger</groupId>
        <artifactId>jaeger-core</artifactId>
        <version>0.24.0</version>
    </dependency>
    <dependency>
        <groupId>com.uber.jaeger</groupId>
        <artifactId>jaeger-b3</artifactId>
        <version>0.24.0</version>
    </dependency>

    <!-- Logback Dependency -->

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.2.3</version>
    </dependency>
    <dependency>
        <groupId>net.logstash.logback</groupId>
        <artifactId>logstash-logback-encoder</artifactId>
        <version>4.10</version>
    </dependency>
{"service" : "Myservice", "trace": "", "span":""}
    <!-- spring-cloud-sleuth dependency -->

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>Camden.SR1</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-sleuth</artifactId>
        <version>2.0.1.RELEASE</version>
    </dependency>

我尝试了Zipkin而不是Jaeger,但同样的事情发生了。我的申请有什么问题?依赖性有问题吗?

共有1个答案

汝弘深
2023-03-14

您将使用Camden发行版train和boot2.0和Sleuth2.0。那是完全不相容的。请从头生成一个从start.spring.io开始的项目,请不要为spring云项目手动放任何版本,请再试一次。尝试使用Finchley释放列车而不是Camden

 类似资料:
  • 我读了很多关于这两种技术的文章,我觉得我对它们有很好的了解。然而,有一件重要的事情我似乎不太明白。OAuth用于授权,而OpenID Connect用于身份验证。但是,在面向OAuth的rfc(https://tools.ietf.org/html/RFC6749#section-4.1)中,它说我们有一个步骤来验证资源所有者(在授权代码授予中是步骤(B))。在我看来,我们已经在OAuth中有身份

  • 项目落户GitHub后,一定希望有越来越多的人能参与其中。GitHub提供了包括传统的问题追踪系统、维基,还包括了分布式版本控制系统特有的协同工具。 4.1. Fork + Pull模式 4.2. 共享版本库 4.3. 组织和团队 4.4. 代码评注 4.5. 缺陷跟踪 4.6. 维基

  • 问题内容: 我遇到了一个有趣的问题,一个以苹果为中心的用户将渴望在Filemaker Pro上运行数据库,而我们已经有多个数据库在MS SQL上运行。 FM Pro在外观上令人赞叹,作为与客户合作的前端看起来不错,但我更喜欢SQL。 有人同时使用吗?您是否可以轻松地在SQL和FM Pro之间运行任务以将数据更新到FM Pro(比如说隔夜)?是否有人出于任何目的将SQL从FM Pro更改为可以吗?

  • 问题内容: 我很难让这些组件正确地编织在一起。我已经安装了Spark并且可以成功工作,我可以在本地,独立运行作业,也可以通过YARN运行作业。据我所知,我已经按照此处和此处建议的步骤进行操作 我正在使用Ubuntu,而我拥有的各种组件版本是 Spark Spark 1.5.1-bin-hadoop2.6 Hadoop hadoop-2.6.1 蒙哥 2.6.10 *从 https://github

  • 完全相同的问题,因为Ubuntu WSL与docker无法找到 但我的要求不同——我想 坚持使用WSL1(出于本主题以外的原因) 也就是说,我有WSL1和Docker for Windows彼此并行安装。这是我目前的信息: 我看不到“资源”中的集成- 只是我遇到了上面的问题——我的可以在任何地方工作,在CMD、Powershell、git bash等中,只是不在我的WSL中。 我找到的所有解决方案

  • 要想团队协作使用Git,就需要用到Git协议。 3.1.1. Git支持的协议 首先来看看数据交换需要使用的协议。 Git提供了丰富的协议支持,包括:SSH、GIT、HTTP、HTTPS、FTP、FTPS、RSYNC及前面已经看到的本地协议等。各种不同协议的URL写法如表15-1所示。 表 15-1:Git支持的协议一览表 协议名称 语法格式 说明 SSH协议(1) ssh://[user@]ex