Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

第 39 章 Spring Boot 4 + OpenTelemetry

目录

39.1. 依赖配置
39.2. 定义 Span
39.3. 日志追踪

39.1. 依赖配置

首先,在你的pom.xml中添加依赖:

		
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-opentelemetry</artifactId>
</dependency>		
		
		

然后在application.yml中添加配置:# application.yml

		
spring:
  application:
    name: meeting-service # 服务名称,会出现在追踪中
		
management:
  tracing:
    sampling:
      probability: 1.0 # 采样率,生产环境可调低
  otlp:
    tracing:
      endpoint: http://localhost:4318 # OTLP接收端点
  metrics:
    export:
      otlp:
        enabled: true