@@ -9,6 +9,7 @@ import io.prometheus.client.Counter
9
9
import io.prometheus.client.Summary
10
10
import java.time.YearMonth
11
11
import mu.KotlinLogging
12
+ import mu.withLoggingContext
12
13
import no.nav.dagpenger.inntekt.moshiInstance
13
14
import no.nav.dagpenger.oidc.OidcClient
14
15
@@ -61,41 +62,47 @@ class InntektskomponentHttpClient(
61
62
62
63
val jsonBody = jsonRequestRequestAdapter.toJson(requestBody)
63
64
val timer = clientLatencyStats.startTimer()
64
- try {
65
- val (_, response, result) = with (hentInntektlisteUrl.httpPost()) {
66
- timeout(timeouts.connectionTimeout.toMillis().toInt())
67
- timeoutRead(timeouts.readTimeout.toMillis().toInt())
68
-
69
- authentication().bearer(oidcClient.oidcToken().access_token)
70
- header(" Nav-Consumer-Id" to " dp-inntekt-api" )
71
- header(" Nav-Call-Id" to ulid.nextULID())
72
- body(jsonBody)
73
- awaitResponseResult(moshiDeserializerOf(jsonResponseAdapter))
74
- }
75
-
76
- inntektskomponentStatusCodesCounter.labels(response.statusCode.toString()).inc()
77
-
78
- return result.fold({
79
- it
80
- }, { error ->
81
- val resp = error.response.body().asString(" application/json" )
82
- val detail = runCatching {
83
65
84
- jsonMapAdapter.fromJson(resp)
85
- }.let {
86
- it.getOrNull()?.get(" message" )?.toString() ? : error.message
66
+ val callId = ulid.nextULID()
67
+ withLoggingContext(
68
+ " callId" to callId
69
+ ) {
70
+ try {
71
+ val (_, response, result) = with (hentInntektlisteUrl.httpPost()) {
72
+ timeout(timeouts.connectionTimeout.toMillis().toInt())
73
+ timeoutRead(timeouts.readTimeout.toMillis().toInt())
74
+
75
+ authentication().bearer(oidcClient.oidcToken().access_token)
76
+ header(" Nav-Consumer-Id" to " dp-inntekt-api" )
77
+ header(" Nav-Call-Id" to callId)
78
+ body(jsonBody)
79
+ awaitResponseResult(moshiDeserializerOf(jsonResponseAdapter))
87
80
}
88
81
89
- clientFetchErrors.inc()
90
-
91
- throw InntektskomponentenHttpClientException (
92
- if (response.statusCode == - 1 ) 500 else response.statusCode, // we did not get a response status code, ie timeout/network issues
93
- " Failed to fetch inntekt. Status code ${response.statusCode} . Response message: ${response.responseMessage} . Problem message: $detail " ,
94
- detail
95
- )
96
- })
97
- } finally {
98
- timer.observeDuration()
82
+ inntektskomponentStatusCodesCounter.labels(response.statusCode.toString()).inc()
83
+
84
+ return result.fold({
85
+ it
86
+ }, { error ->
87
+ val resp = error.response.body().asString(" application/json" )
88
+ val detail = runCatching {
89
+
90
+ jsonMapAdapter.fromJson(resp)
91
+ }.let {
92
+ it.getOrNull()?.get(" message" )?.toString() ? : error.message
93
+ }
94
+
95
+ clientFetchErrors.inc()
96
+
97
+ throw InntektskomponentenHttpClientException (
98
+ if (response.statusCode == - 1 ) 500 else response.statusCode, // we did not get a response status code, ie timeout/network issues
99
+ " Failed to fetch inntekt. Status code ${response.statusCode} . Response message: ${response.responseMessage} . Problem message: $detail " ,
100
+ detail
101
+ )
102
+ })
103
+ } finally {
104
+ timer.observeDuration()
105
+ }
99
106
}
100
107
}
101
108
}
0 commit comments