-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "Add "nav-call-id" to client calls.""
This reverts commit adb63e9.
- Loading branch information
1 parent
adb63e9
commit 042254c
Showing
5 changed files
with
50 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/kotlin/no/nav/klage/config/WebClientCustomizer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
) | ||
} | ||
) | ||
} | ||
} |