Skip to content

Commit

Permalink
Revert "Revert "Add "nav-call-id" to client calls.""
Browse files Browse the repository at this point in the history
This reverts commit adb63e9.
  • Loading branch information
oyvind-wedoe committed Oct 8, 2024
1 parent adb63e9 commit 042254c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ val mockitoInlineVersion = "5.2.0"
val testContainersVersion = "1.19.8"
val mockkVersion = "1.13.10"
val springMockkVersion = "4.0.2"
val otelVersion = "1.42.1"

val githubUser: String by project
val githubPassword: String by project
Expand Down Expand Up @@ -52,6 +53,8 @@ dependencies {

implementation("io.micrometer:micrometer-registry-prometheus")

implementation("io.opentelemetry:opentelemetry-api:$otelVersion")

implementation("org.projectreactor:reactor-spring:1.0.1.RELEASE")

implementation("org.flywaydb:flyway-core")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ class FileClientConfiguration(private val webClientBuilder: WebClient.Builder) {
fun fileWebClient(): WebClient =
webClientBuilder
.baseUrl(url)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.build()
}
2 changes: 0 additions & 2 deletions src/main/kotlin/no/nav/klage/config/PdlClientConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class PdlClientConfiguration(private val webClientBuilder: WebClient.Builder) {
fun pdlWebClient(): WebClient {
return webClientBuilder
.baseUrl(pdlUrl)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader("Nav-Consumer-Id", username)
.defaultHeader("TEMA", "KLA")
//Fra behandlingskatalogen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@ class SafselvbetjeningClientConfiguration(private val webClientBuilder: WebClien
fun safselvbetjeningWebClient(): WebClient =
webClientBuilder
.baseUrl(url)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.build()
}
47 changes: 47 additions & 0 deletions src/main/kotlin/no/nav/klage/config/WebClientCustomizer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package no.nav.klage.config

import io.opentelemetry.api.trace.Span
import org.springframework.boot.web.reactive.function.client.WebClientCustomizer
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.stereotype.Component
import org.springframework.web.reactive.function.client.ClientRequest
import org.springframework.web.reactive.function.client.ExchangeFilterFunction
import org.springframework.web.reactive.function.client.WebClient
import reactor.core.publisher.Mono
import reactor.netty.http.client.HttpClient

/**
* Common configuration for all web clients.
*/
@Component
class WebClientCustomizer : WebClientCustomizer {

override fun customize(webClientBuilder: WebClient.Builder) {
val headersWithTraceId = listOf(
"Nav-Call-Id",
"Nav-Callid",
"X-Correlation-ID",
)

webClientBuilder
.clientConnector(ReactorClientHttpConnector(HttpClient.newConnection()))
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.filter(
ExchangeFilterFunction.ofRequestProcessor { request ->
val traceId = Span.current().spanContext.traceId
Mono.just(
ClientRequest.from(request)
.headers { headers ->
headersWithTraceId.forEach { headerName ->
headers[headerName] = traceId
}
}
.build()
)
}
)
}
}

0 comments on commit 042254c

Please sign in to comment.