Skip to content

Commit 0b0a536

Browse files
committed
fix: USER_ENTRY_POINT MDC전이가 끊기는 버그를 수정한다
1 parent b73e25a commit 0b0a536

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/main/kotlin/org/gitanimals/core/OrchestratorExtension.kt

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

33
import org.gitanimals.core.filter.MDCFilter.Companion.TRACE_ID
4+
import org.gitanimals.core.filter.MDCFilter.Companion.USER_ENTRY_POINT
45
import org.gitanimals.core.filter.MDCFilter.Companion.USER_ID
56
import org.rooftop.netx.api.Context
67
import org.rooftop.netx.api.ContextOrchestrate
@@ -17,6 +18,8 @@ open class TraceIdContextOrchestrator<T : Any, V : Any>(
1718
.onSuccess { MDC.put(TRACE_ID, it) }
1819
runCatching { context.decodeContext(USER_ID, String::class) }
1920
.onSuccess { MDC.put(USER_ID, it) }
21+
runCatching { context.decodeContext(USER_ENTRY_POINT, String::class) }
22+
.onSuccess { MDC.put(USER_ENTRY_POINT, it) }
2023

2124
return runCatching {
2225
orchestrate.orchestrate(context, request)
@@ -25,6 +28,8 @@ open class TraceIdContextOrchestrator<T : Any, V : Any>(
2528
throw it
2629
}.also {
2730
MDC.remove(TRACE_ID)
31+
MDC.remove(USER_ID)
32+
MDC.remove(USER_ENTRY_POINT)
2833
}
2934
}
3035

@@ -42,6 +47,8 @@ open class TraceIdContextRollback<T : Any, V : Any?>(
4247
.onSuccess { MDC.put(TRACE_ID, it) }
4348
runCatching { context.decodeContext(USER_ID, String::class) }
4449
.onSuccess { MDC.put(USER_ID, it) }
50+
runCatching { context.decodeContext(USER_ENTRY_POINT, String::class) }
51+
.onSuccess { MDC.put(USER_ENTRY_POINT, it) }
4552

4653
return runCatching {
4754
rollback.rollback(context, request)
@@ -50,6 +57,8 @@ open class TraceIdContextRollback<T : Any, V : Any?>(
5057
throw it
5158
}.also {
5259
MDC.remove(TRACE_ID)
60+
MDC.remove(USER_ID)
61+
MDC.remove(USER_ENTRY_POINT)
5362
}
5463
}
5564

src/main/kotlin/org/gitanimals/core/auth/InternalAuthRequestInterceptor.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ class InternalAuthRequestInterceptor(
2424
MDC.get(USER_ID).toLong()
2525
}.getOrNull()
2626

27-
val userEntryPoint = runCatching {
28-
MDC.get(USER_ENTRY_POINT)
29-
}.getOrNull()
30-
3127
if (userId != null) {
3228
val encrypt = internalAuth.encrypt(userId = userId)
3329

@@ -39,6 +35,13 @@ class InternalAuthRequestInterceptor(
3935
InternalAuth.INTERNAL_AUTH_IV_KEY,
4036
Base64.getEncoder().encodeToString(encrypt.iv),
4137
)
38+
}
39+
40+
val userEntryPoint = runCatching {
41+
MDC.get(USER_ENTRY_POINT)
42+
}.getOrNull()
43+
44+
if (userEntryPoint != null) {
4245
request.headers.add(
4346
InternalAuth.INTERNAL_ENTRY_POINT_KEY,
4447
userEntryPoint,

src/main/kotlin/org/gitanimals/guild/app/CreateGuildFacade.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.gitanimals.guild.app
33
import org.gitanimals.core.TraceIdContextOrchestrator
44
import org.gitanimals.core.TraceIdContextRollback
55
import org.gitanimals.core.filter.MDCFilter.Companion.TRACE_ID
6+
import org.gitanimals.core.filter.MDCFilter.Companion.USER_ENTRY_POINT
67
import org.gitanimals.core.filter.MDCFilter.Companion.USER_ID
78
import org.gitanimals.guild.app.request.CreateGuildRequest
89
import org.gitanimals.guild.app.response.GuildResponse
@@ -44,6 +45,7 @@ class CreateGuildFacade(
4445
IDEMPOTENCY_KEY to UUID.randomUUID().toString(),
4546
TRACE_ID to MDC.get(TRACE_ID),
4647
USER_ID to MDC.get(USER_ID),
48+
USER_ENTRY_POINT to MDC.get(USER_ENTRY_POINT),
4749
),
4850
timeoutMillis = 1.minutes.inWholeMilliseconds,
4951
).decodeResultOrThrow(GuildResponse::class).also {

0 commit comments

Comments
 (0)