【发布时间】:2022-12-22 21:16:28
【问题描述】:
我正在替换 Spring Cloud Sleuth,以使用新的 Micrometer Tracing for Spring Boot 3 生成日志相关性。
我一直在关注this blog post配置一个sample project
traceId/spanId 似乎不会根据请求自动生成:
@GetMapping("/hello")
fun hello(): String {
val currentSpan: Span? = tracer.currentSpan()
logger.info("Hello!")
return "hello"
}
currentSpan 为 null,日志显示空字符串:
2022-11-28T14:53:05.335+01:00 INFO [server,,] 9176 --- [ctor-http-nio-2] d.DemotracingApplication$$SpringCGLIB$$0 : Hello!
这是我当前的配置:
logging.pattern.level=%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]
以及依赖项:
dependencies {
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.boot:spring-boot-starter-aop")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("io.micrometer:micrometer-tracing-bridge-brave")
implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")
implementation("io.micrometer:micrometer-registry-prometheus")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("io.projectreactor:reactor-test")
}
为什么它不起作用?
编辑:
WebMVC 应用不受此问题影响,升级后会记录关联信息。
不过,Webflux 应用程序的行为似乎发生了变化。还有open issue about this。
【问题讨论】:
标签: spring-boot spring-webflux micrometer micrometer-tracing