Skip to content

Commit

Permalink
chore(okhttp): added a TrafficStats tag to the OkHttp delivery
Browse files Browse the repository at this point in the history
  • Loading branch information
lemnik committed Oct 29, 2024
1 parent 7740900 commit 4387507
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bugsnag.android.okhttp

import android.net.TrafficStats
import com.bugsnag.android.Delivery
import com.bugsnag.android.DeliveryParams
import com.bugsnag.android.DeliveryStatus
Expand Down Expand Up @@ -32,8 +33,13 @@ class OkHttpDelivery @JvmOverloads constructor(
}

val call = client.newCall(requestBuilder.build())
val response = call.execute()
return DeliveryStatus.forHttpResponseCode(response.code)
try {
TrafficStats.setThreadStatsTag(1)
val response = call.execute()
return DeliveryStatus.forHttpResponseCode(response.code)
} finally {
TrafficStats.clearThreadStatsTag()
}
}

override fun deliver(payload: EventPayload, deliveryParams: DeliveryParams): DeliveryStatus {
Expand All @@ -51,9 +57,14 @@ class OkHttpDelivery @JvmOverloads constructor(
}

val call = client.newCall(requestBuilder.build())
val response = call.execute()

return DeliveryStatus.forHttpResponseCode(response.code)
try {
TrafficStats.setThreadStatsTag(1)
val response = call.execute()
return DeliveryStatus.forHttpResponseCode(response.code)
} finally {
TrafficStats.clearThreadStatsTag()
}
} catch (oom: OutOfMemoryError) {
// attempt to persist the payload on disk. This approach uses streams to write to a
// file, which takes less memory than serializing the payload into a ByteArray, and
Expand Down

0 comments on commit 4387507

Please sign in to comment.