Skip to content

Commit

Permalink
connecting client trace id to x-request-id
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfmurdock committed Jul 16, 2023
1 parent 2cf83e1 commit 9c4e7d3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class MasterCommander(private val getIdentityToken: suspend () -> String) : Comm
MemoryRepositoryCatalog("test-user", backend, Clock.System)
.sdk
} else {
couplingSdk(getIdentityToken, defaultClient(getLocationAndBasename()), LoggingActionPipe(traceId))
val locationAndBasename = getLocationAndBasename()
couplingSdk(getIdentityToken, defaultClient(locationAndBasename, traceId), LoggingActionPipe(traceId))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ interface DynamoDatatypeSyntax {

fun Json.getDynamoDateTimeValue(property: String) = this[property].unsafeCast<String?>()
?.let {
println("THING $it")
LocalDateTime(
year = it.slice(0..3).toInt(),
month = it.slice(4..5).toInt().let { Month.values()[it - 1] },
month = it.slice(4..5).toInt().let { monthNumber -> Month.values()[monthNumber - 1] },
dayOfMonth = it.slice(6..7).toInt(),
hour = it.slice(8..9).toInt(),
minute = it.slice(10..11).toInt(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.zegreatrob.coupling.sdk

import com.benasher44.uuid.Uuid
import com.benasher44.uuid.uuid4
import io.ktor.client.HttpClient
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
Expand All @@ -13,7 +14,7 @@ import io.ktor.http.Url
import io.ktor.http.encodedPath
import io.ktor.serialization.kotlinx.json.json

fun defaultClient(locationAndBasename: Pair<String, String>?) = HttpClient {
fun defaultClient(locationAndBasename: Pair<String, String>?, traceId: Uuid? = null) = HttpClient {
install(ContentNegotiation) {
json()
}
Expand All @@ -23,7 +24,7 @@ fun defaultClient(locationAndBasename: Pair<String, String>?) = HttpClient {
expectSuccess = false
defaultRequest {
header(UserAgent, "CouplingSdk")
header("X-Request-ID", uuid4())
header("X-Request-ID", traceId ?: uuid4())
locationAndBasename
?.let { (location, basename) ->
url {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private val ktorLogger = KotlinLogging.logger("ktor")
fun buildClient(): HttpClient {
setupPlatformSpecificKtorSettings()

val client = defaultClient(null).config {
val client = defaultClient(null, uuid4()).config {
followRedirects = false
expectSuccess = false
defaultRequest { url("$baseUrl") }
Expand Down

0 comments on commit 9c4e7d3

Please sign in to comment.