Skip to content

Instantly share code, notes, and snippets.

@segabond
Last active February 22, 2019 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save segabond/18c33a1c4e5f25c400792c0cb8a2106f to your computer and use it in GitHub Desktop.
Save segabond/18c33a1c4e5f25c400792c0cb8a2106f to your computer and use it in GitHub Desktop.
KTOR MDC correlation ID
fun Application.myApp() {
install(CallLogging) {
mdc("correlationId") { call ->
call.request.header("X-Correlation-ID") ?:
}
}
}
fun configureHttpClient() =
HttpClient(Apache) {
defaultRequest {
MDC.get("correlationId")?.also {
header("X-Correlation-ID", it)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment