Skip to content

Commit ce1864e

Browse files
committed
refactor: 모든 api 요청에 traceId를 포함한다
1 parent 71d4eb8 commit ce1864e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/main/kotlin/org/gitanimals/guild/infra/HttpClientConfigurer.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package org.gitanimals.guild.infra
22

3+
import org.gitanimals.core.filter.MDCFilter.Companion.TRACE_ID
34
import org.gitanimals.guild.app.IdentityApi
45
import org.gitanimals.guild.app.RenderApi
6+
import org.slf4j.MDC
57
import org.springframework.context.annotation.Bean
68
import org.springframework.context.annotation.Configuration
79
import org.springframework.context.annotation.Profile
@@ -17,6 +19,9 @@ class HttpClientConfigurer {
1719
fun identityApiHttpClient(): IdentityApi {
1820
val restClient = RestClient
1921
.builder()
22+
.defaultHeaders {
23+
it.add(TRACE_ID, MDC.get(TRACE_ID))
24+
}
2025
.defaultStatusHandler(httpClientErrorHandler())
2126
.baseUrl("https://api.gitanimals.org")
2227
.build()
@@ -32,6 +37,9 @@ class HttpClientConfigurer {
3237
fun renderApiHttpClient(): RenderApi {
3338
val restClient = RestClient
3439
.builder()
40+
.defaultHeaders {
41+
it.add(TRACE_ID, MDC.get(TRACE_ID))
42+
}
3543
.defaultStatusHandler(httpClientErrorHandler())
3644
.baseUrl("https://render.gitanimals.org")
3745
.build()

src/main/kotlin/org/gitanimals/render/infra/RestIdentityApi.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package org.gitanimals.render.infra
22

33
import org.gitanimals.core.AUTHORIZATION_EXCEPTION
4+
import org.gitanimals.core.filter.MDCFilter.Companion.TRACE_ID
45
import org.gitanimals.render.app.IdentityApi
6+
import org.slf4j.MDC
57
import org.springframework.http.HttpHeaders
68
import org.springframework.stereotype.Component
79
import org.springframework.web.client.RestClient
@@ -15,6 +17,7 @@ class RestIdentityApi : IdentityApi {
1517
return restClient.get()
1618
.uri("/users")
1719
.header(HttpHeaders.AUTHORIZATION, token)
20+
.header(TRACE_ID, MDC.get(TRACE_ID))
1821
.exchange { _, response ->
1922
runCatching {
2023
response.bodyTo(IdentityApi.UserResponse::class.java)

0 commit comments

Comments
 (0)