TP-64593 | Added requestBody in logs (#10582)

This commit is contained in:
Kishan Kumar
2024-04-23 14:41:55 +05:30
committed by GitHub
parent e20a40f304
commit 825163767b
2 changed files with 15 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ package com.navi.common.network.interceptor
import com.navi.alfred.utils.AlfredConstants.STATUS_CODE
import com.navi.analytics.utils.NaviTrackEvent
import com.navi.base.network.util.ApiConstants
import com.navi.common.extensions.safeSubstring
import com.navi.common.network.BaseHttpClient
import com.navi.common.network.handleException
import com.navi.common.network.logIOException
@@ -17,6 +18,7 @@ import com.navi.common.utils.Constants.API_ENDPOINT
import com.navi.common.utils.Constants.API_LATENCY
import com.navi.common.utils.Constants.API_METRIC_EVENT
import com.navi.common.utils.Constants.CONTENT_SIZE_IN_KB
import com.navi.common.utils.Constants.REQUEST_BODY
import com.navi.naviwidgets.utils.VERTICAL
import java.io.IOException
import okhttp3.Interceptor
@@ -26,6 +28,9 @@ import okhttp3.Response
import okhttp3.ResponseBody
class MetricInterceptor : Interceptor {
private val MAX_REQUEST_BODY_LOG_SIZE_LENGTH = 1000
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
@@ -42,6 +47,13 @@ class MetricInterceptor : Interceptor {
} catch (e: Exception) {
0L
}
val requestString = chainResponse.request.toString()
val requestBody =
requestString.safeSubstring(
0,
minOf(MAX_REQUEST_BODY_LOG_SIZE_LENGTH, requestString.length)
)
NaviTrackEvent.trackEventOnClickStream(
eventName = API_METRIC_EVENT,
mapOf(
@@ -49,7 +61,8 @@ class MetricInterceptor : Interceptor {
Pair(API_LATENCY, apiLatency.toString()),
Pair(STATUS_CODE, statusCode.toString()),
Pair(CONTENT_SIZE_IN_KB, byteReceivedInKB.toString()),
Pair(VERTICAL, request.headers[BaseHttpClient.X_TARGET].orEmpty())
Pair(VERTICAL, request.headers[BaseHttpClient.X_TARGET].orEmpty()),
Pair(REQUEST_BODY, requestBody)
)
)

View File

@@ -230,6 +230,7 @@ object Constants {
const val API_ENDPOINT = "endpoint"
const val API_LATENCY = "latency"
const val CONTENT_SIZE_IN_KB = "content_size_kb"
const val REQUEST_BODY = "request_body"
const val API_METRIC_EVENT = "dev_api_metric_event"
const val IS_UPI_APP_AVAILABLE = "isUpiAppAvailable"
const val LIST_OF_INSTALLED_UPI_APPS = "LIST_OF_INSTALLED_UPI_APPS"