TP-12345 | added session id check for touch,sww and savi api logs.Handled save api logs on another thread.

This commit is contained in:
AMAN SINGH
2023-04-28 17:13:34 +05:30
parent d2b89cffb9
commit 0970f455cf

View File

@@ -656,38 +656,38 @@ object AlfredManager {
}
fun saveApiLog(request: Request, response: Response, startTime: Long, endTime: Long) {
var bytesSent = 0L
var byteReceived = 0L
if (request.body != null) {
val buffer = Buffer()
request.body!!.writeTo(buffer)
bytesSent = buffer.size
}
if (response.body != null) {
val responseBody = response.body
val source = responseBody?.source()
source?.request(Long.MAX_VALUE)
val buffer = source?.buffer()
byteReceived = buffer?.size ?: 0
}
var errorMessage: String? = null
val duration: Long = endTime - startTime
val errorType: String? = null
if (response.code != CODE_API_SUCCESS) {
errorMessage = response.message
}
val attributes: HashMap<String, Any> = hashMapOf()
attributes[AlfredConstants.URL] = request.url.toString()
attributes[AlfredConstants.METHOD] = request.method
attributes[AlfredConstants.RESPONSE_CODE] = response.code
attributes[AlfredConstants.ERROR_MESSAGE] = errorMessage.toString()
attributes[AlfredConstants.ERROR_TYPE] = errorType.toString()
attributes[AlfredConstants.START_TIME] = startTime
attributes[AlfredConstants.END_TIME] = endTime
attributes[AlfredConstants.DURATION_IN_MS] = duration.toDouble()
attributes[AlfredConstants.BYTES_RECEIVED] = byteReceived
attributes[AlfredConstants.BYTES_SENT] = bytesSent
coroutineDispatcher.executor.execute {
var bytesSent = 0L
var byteReceived = 0L
request.body?.let { requestBody ->
val buffer = Buffer()
requestBody.writeTo(buffer)
bytesSent = buffer.size
}
response.body?.let { responseBody ->
val source = responseBody.source()
source.request(Long.MAX_VALUE)
val buffer = source.buffer()
byteReceived = buffer.size
}
var errorMessage: String? = null
val duration: Long = endTime - startTime
val errorType: String? = null
if (response.code != CODE_API_SUCCESS) {
errorMessage = response.message
}
val attributes = hashMapOf<String, Any>().apply {
this[AlfredConstants.URL] = request.url.toString()
this[AlfredConstants.METHOD] = request.method
this[AlfredConstants.RESPONSE_CODE] = response.code
this[AlfredConstants.ERROR_MESSAGE] = errorMessage.toString()
this[AlfredConstants.ERROR_TYPE] = errorType.toString()
this[AlfredConstants.START_TIME] = startTime
this[AlfredConstants.END_TIME] = endTime
this[AlfredConstants.DURATION_IN_MS] = duration.toDouble()
this[AlfredConstants.BYTES_RECEIVED] = byteReceived
this[AlfredConstants.BYTES_SENT] = bytesSent
}
val appPerformanceEvent = buildAppPerformanceEvent(
AlfredConstants.API_METRIC_EVENT_NAME, API_METRICS, attributes
)
@@ -759,28 +759,30 @@ object AlfredManager {
}
}
fun handleTouchEvent(
currentTouchEvent: MotionEvent?, screenName: String? = null, moduleName: String? = null
currentTouchEvent: MotionEvent?,
screenName: String? = null,
moduleName: String? = null
) {
if (config.getAlfredStatus() && config.getEnableRecordingStatus()) {
coroutineDispatcher.executor.execute {
if (currentTouchEvent?.action == ACTION_DOWN) {
previousTouchEvent.action = currentTouchEvent.action
previousTouchEvent.positionX = currentTouchEvent.rawX
previousTouchEvent.positionY = currentTouchEvent.rawY
}
if (currentTouchEvent?.action == ACTION_UP) {
val touchEventData = getTouchEvent(currentTouchEvent, previousTouchEvent)
val touchEventProperties = touchEventData.second
touchEventProperties[AlfredConstants.SCREEN_WIDTH] = getScreenWidth().toString()
touchEventProperties[AlfredConstants.SCREEN_HEIGHT] = getScreenHeight().toString()
val event = buildEvent(
touchEventData.first,
touchEventProperties,
screenName = screenName,
moduleName = moduleName
)
AlfredDispatcher.addTaskToQueue(AddEventTask(event, applicationContext))
if (config.getAlfredSessionId().isNotEmpty()) {
coroutineDispatcher.executor.execute {
if (currentTouchEvent?.action == ACTION_DOWN) {
previousTouchEvent.action = currentTouchEvent.action
previousTouchEvent.positionX = currentTouchEvent.rawX
previousTouchEvent.positionY = currentTouchEvent.rawY
}
if (currentTouchEvent?.action == ACTION_UP) {
val touchEventData = getTouchEvent(currentTouchEvent, previousTouchEvent)
val event = buildEvent(
touchEventData.first,
touchEventData.second,
screenName = screenName,
moduleName = moduleName
)
AlfredDispatcher.addTaskToQueue(AddEventTask(event, applicationContext))
}
}
}
}
@@ -844,17 +846,22 @@ object AlfredManager {
}
}
fun handleSWWEvent(
screenName: String? = null, swwEventProperties: Map<String, String>
) {
coroutineDispatcher.executor.execute {
val event = buildEvent(
AlfredConstants.ERROR_LOG,
swwEventProperties as HashMap<String, String>,
screenName = screenName,
moduleName = currentModuleName
)
AlfredDispatcher.addTaskToQueue(AddEventTask(event, applicationContext))
if (config.getAlfredStatus() && config.getEnableRecordingStatus()) {
if (config.getAlfredSessionId().isNotEmpty()) {
coroutineDispatcher.executor.execute {
val event = buildEvent(
AlfredConstants.ERROR_LOG,
swwEventProperties as HashMap<String, String>,
screenName = screenName,
moduleName = currentModuleName
)
AlfredDispatcher.addTaskToQueue(AddEventTask(event, applicationContext))
}
}
}
}