Skip to content

Commit

Permalink
feat: re-add interceptor that logs http requests and responses (#12756)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpefaur committed Jun 11, 2024
1 parent 7bc949b commit b703bcc
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import okio.Buffer
import org.openapitools.client.infrastructure.ClientException
import org.openapitools.client.infrastructure.ServerException
import java.io.IOException
Expand Down Expand Up @@ -93,6 +94,7 @@ object AcceptanceTestUtils {
chain.proceed(builder.build())
},
)
.addInterceptor(LoggingInterceptor)
.connectTimeout(Duration.ofSeconds(DEFAULT_TIMEOUT))
.readTimeout(Duration.ofSeconds(DEFAULT_TIMEOUT))
.build()
Expand Down Expand Up @@ -162,4 +164,28 @@ object AcceptanceTestUtils {
.toList()
return AirbyteCatalog(updatedStreams)
}

// logs http requests and responses
private object LoggingInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val request: Request = chain.request()
val requestLogMessage =
buildString {
append("Request: ${request.method} ${request.url}")
request.body?.let { body ->
val buffer = Buffer()
body.writeTo(buffer)
append(" body: ${buffer.readUtf8()}")
}
}
logger.info(requestLogMessage)

val response: Response = chain.proceed(request)
// we don't log the response body because it can be very large which can heavily increase
// the test duration + it doesn't add a lot of information
logger.info("Response: ${response.code} ${request.url} ")

return response
}
}
}

0 comments on commit b703bcc

Please sign in to comment.