diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 517cb1d..d47e646 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,8 +1,8 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES plugins { - id("org.springframework.boot") version "3.1.4" + id("org.springframework.boot") version "3.2.0-SNAPSHOT" + id("io.spring.dependency-management") version "1.1.3" kotlin("jvm") version "1.9.10" kotlin("plugin.spring") version "1.9.10" } @@ -16,12 +16,12 @@ java { repositories { mavenCentral() + maven { url = uri("https://repo.spring.io/milestone") } + maven { url = uri("https://repo.spring.io/snapshot") } } dependencies { - implementation(platform(BOM_COORDINATES)) implementation(platform("org.zalando:logbook-bom:3.4.0")) - implementation(platform("io.micrometer:micrometer-tracing-bom:1.1.5")) implementation("org.springframework.boot:spring-boot-starter-webflux") implementation("org.springframework.boot:spring-boot-starter-security") runtimeOnly("org.springframework.boot:spring-boot-starter-actuator") @@ -35,7 +35,7 @@ dependencies { implementation("org.zalando:logbook-spring-boot-starter") implementation("org.zalando:logbook-spring-boot-webflux-autoconfigure") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-slf4j:1.7.3") - compileOnly("org.springframework.boot:spring-boot-devtools") + developmentOnly("org.springframework.boot:spring-boot-devtools") testImplementation("org.springframework.boot:spring-boot-starter-test") } diff --git a/app/src/main/kotlin/com/grassehh/app/configuration/TracingConfiguration.kt b/app/src/main/kotlin/com/grassehh/app/configuration/TracingConfiguration.kt index 11c05bb..0a48696 100644 --- a/app/src/main/kotlin/com/grassehh/app/configuration/TracingConfiguration.kt +++ b/app/src/main/kotlin/com/grassehh/app/configuration/TracingConfiguration.kt @@ -10,15 +10,32 @@ import io.netty.channel.ChannelDuplexHandler import io.netty.channel.ChannelHandlerContext import io.netty.channel.ChannelPromise import jakarta.annotation.PostConstruct +import kotlinx.coroutines.slf4j.MDCContext +import kotlinx.coroutines.withContext import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +import org.springframework.web.server.CoWebFilter +import org.springframework.web.server.CoWebFilterChain +import org.springframework.web.server.ServerWebExchange +import org.springframework.web.server.WebFilter import reactor.core.publisher.Hooks import reactor.netty.Metrics @Configuration class TracingConfiguration(private val observationRegistry: ObservationRegistry, private val tracer: Tracer) { + + @Bean + fun coroutineWebFilter(): WebFilter { + return object : CoWebFilter() { + override suspend fun filter(exchange: ServerWebExchange, chain: CoWebFilterChain) + = withContext(MDCContext()) { + chain.filter(exchange) + } + } + } + @Bean - fun contextSnapshotFactory() = ContextSnapshotFactory.builder().build() + fun contextSnapshotFactory() = ContextSnapshotFactory.builder().build(); @PostConstruct fun postConstruct() { diff --git a/settings.gradle.kts b/settings.gradle.kts index b45d44e..6240c84 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,2 +1,10 @@ +pluginManagement { + repositories { + maven { url = uri("https://repo.spring.io/milestone") } + maven { url = uri("https://repo.spring.io/snapshot") } + gradlePluginPortal() + } +} + rootProject.name = "spring-boot-3-tracing-coroutine" include("app")