| 知乎专栏 |
首先,在你的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