Skip to content

Commit c1100f3

Browse files
committed
fix(core): Preserve MDC context in configureLifecycle
Preserve the MDC context when starting new threads in `configureLifecycle`. Signed-off-by: Martin Nonnenmacher <[email protected]>
1 parent 47300d0 commit c1100f3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

core/src/main/kotlin/plugins/Lifecycle.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import org.eclipse.apoapsis.ortserver.utils.logging.withMdcContext
3232

3333
import org.koin.ktor.ext.inject
3434

35+
import org.slf4j.MDC
36+
3537
/**
3638
* Configure actions that are triggered by
3739
* [lifecycle events][https://ktor.io/docs/events.html#handle-events-application].
@@ -40,7 +42,10 @@ fun Application.configureLifecycle() {
4042
environment.monitor.subscribe(DatabaseReady) {
4143
val authorizationService by inject<AuthorizationService>()
4244

45+
val mdcContext = MDC.getCopyOfContextMap()
46+
4347
thread {
48+
MDC.setContextMap(mdcContext)
4449
runBlocking(Dispatchers.IO) {
4550
syncRoles(authorizationService)
4651
}

0 commit comments

Comments
 (0)