Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
public final class com/bugsnag/android/okhttp/BugsnagOkHttpPlugin : okhttp3/EventListener, com/bugsnag/android/Plugin {
public final class com/bugsnag/android/okhttp/BugsnagOkHttpPlugin : com/bugsnag/android/okhttp/util/DelegateEventListener, com/bugsnag/android/Plugin {
public fun <init> ()V
public fun <init> (Lkotlin/jvm/functions/Function0;)V
public synthetic fun <init> (Lkotlin/jvm/functions/Function0;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lokhttp3/EventListener;)V
public fun <init> (Lokhttp3/EventListener;Lkotlin/jvm/functions/Function0;)V
public synthetic fun <init> (Lokhttp3/EventListener;Lkotlin/jvm/functions/Function0;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun callEnd (Lokhttp3/Call;)V
public fun callFailed (Lokhttp3/Call;Ljava/io/IOException;)V
public fun callStart (Lokhttp3/Call;)V
Expand All @@ -22,3 +23,34 @@ public final class com/bugsnag/android/okhttp/OkHttpDelivery : com/bugsnag/andro
public fun deliver (Lcom/bugsnag/android/Session;Lcom/bugsnag/android/DeliveryParams;)Lcom/bugsnag/android/DeliveryStatus;
}

public class com/bugsnag/android/okhttp/util/DelegateEventListener : okhttp3/EventListener {
public fun <init> (Lokhttp3/EventListener;)V
public fun cacheConditionalHit (Lokhttp3/Call;Lokhttp3/Response;)V
public fun cacheHit (Lokhttp3/Call;Lokhttp3/Response;)V
public fun cacheMiss (Lokhttp3/Call;)V
public fun callEnd (Lokhttp3/Call;)V
public fun callFailed (Lokhttp3/Call;Ljava/io/IOException;)V
public fun callStart (Lokhttp3/Call;)V
public fun canceled (Lokhttp3/Call;)V
public fun connectEnd (Lokhttp3/Call;Ljava/net/InetSocketAddress;Ljava/net/Proxy;Lokhttp3/Protocol;)V
public fun connectFailed (Lokhttp3/Call;Ljava/net/InetSocketAddress;Ljava/net/Proxy;Lokhttp3/Protocol;Ljava/io/IOException;)V
public fun connectStart (Lokhttp3/Call;Ljava/net/InetSocketAddress;Ljava/net/Proxy;)V
public fun connectionAcquired (Lokhttp3/Call;Lokhttp3/Connection;)V
public fun connectionReleased (Lokhttp3/Call;Lokhttp3/Connection;)V
public fun dnsEnd (Lokhttp3/Call;Ljava/lang/String;Ljava/util/List;)V
public fun dnsStart (Lokhttp3/Call;Ljava/lang/String;)V
protected final fun getDelegateEventListener ()Lokhttp3/EventListener;
public fun proxySelectEnd (Lokhttp3/Call;Lokhttp3/HttpUrl;Ljava/util/List;)V
public fun proxySelectStart (Lokhttp3/Call;Lokhttp3/HttpUrl;)V
public fun requestBodyStart (Lokhttp3/Call;)V
public fun requestFailed (Lokhttp3/Call;Ljava/io/IOException;)V
public fun requestHeadersEnd (Lokhttp3/Call;Lokhttp3/Request;)V
public fun requestHeadersStart (Lokhttp3/Call;)V
public fun responseBodyStart (Lokhttp3/Call;)V
public fun responseFailed (Lokhttp3/Call;Ljava/io/IOException;)V
public fun responseHeadersStart (Lokhttp3/Call;)V
public fun satisfactionFailure (Lokhttp3/Call;Lokhttp3/Response;)V
public fun secureConnectEnd (Lokhttp3/Call;Lokhttp3/Handshake;)V
public fun secureConnectStart (Lokhttp3/Call;)V
}

1 change: 1 addition & 0 deletions bugsnag-plugin-android-okhttp/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<ID>MagicNumber:BugsnagOkHttpPlugin.kt$399</ID>
<ID>MagicNumber:BugsnagOkHttpPlugin.kt$400</ID>
<ID>MagicNumber:BugsnagOkHttpPlugin.kt$599</ID>
<ID>TooManyFunctions:DelegateEventListener.kt$DelegateEventListener : EventListener</ID>
</CurrentIssues>
</SmellBaseline>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.annotation.VisibleForTesting
import com.bugsnag.android.BreadcrumbType
import com.bugsnag.android.Client
import com.bugsnag.android.Plugin
import com.bugsnag.android.okhttp.util.DelegateEventListener
import com.bugsnag.android.shouldDiscardNetworkBreadcrumb
import okhttp3.Call
import okhttp3.EventListener
Expand All @@ -25,8 +26,9 @@ import java.util.concurrent.ConcurrentHashMap
* https://square.github.io/okhttp/4.x/okhttp/okhttp3/-response-body/#the-response-body-must-be-closed
*/
class BugsnagOkHttpPlugin @JvmOverloads constructor(
delegateEventListener: EventListener? = null,
internal val timeProvider: () -> Long = { System.currentTimeMillis() }
) : Plugin, EventListener() {
) : Plugin, DelegateEventListener(delegateEventListener) {

internal val requestMap = ConcurrentHashMap<Call, NetworkRequestMetadata>()
private var client: Client? = null
Expand All @@ -40,24 +42,39 @@ class BugsnagOkHttpPlugin @JvmOverloads constructor(
}

override fun callStart(call: Call) {
super.callStart(call)
requestMap[call] = NetworkRequestMetadata(timeProvider())
}

override fun requestBodyEnd(call: Call, byteCount: Long) {
super.requestBodyEnd(call, byteCount)
requestMap[call]?.requestBodyCount = byteCount
}

override fun responseBodyEnd(call: Call, byteCount: Long) {
super.responseBodyEnd(call, byteCount)
requestMap[call]?.responseBodyCount = byteCount
}

override fun responseHeadersEnd(call: Call, response: Response) {
super.responseHeadersEnd(call, response)
requestMap[call]?.status = response.code
}

override fun callEnd(call: Call) = captureNetworkBreadcrumb(call)
override fun callFailed(call: Call, ioe: IOException) = captureNetworkBreadcrumb(call)
override fun canceled(call: Call) = captureNetworkBreadcrumb(call)
override fun callEnd(call: Call) {
super.callEnd(call)
captureNetworkBreadcrumb(call)
}

override fun callFailed(call: Call, ioe: IOException) {
super.callFailed(call, ioe)
captureNetworkBreadcrumb(call)
}

override fun canceled(call: Call) {
super.canceled(call)
captureNetworkBreadcrumb(call)
}

private fun captureNetworkBreadcrumb(call: Call) {
client?.apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package com.bugsnag.android.okhttp.util

import okhttp3.Call
import okhttp3.Connection
import okhttp3.EventListener
import okhttp3.Handshake
import okhttp3.HttpUrl
import okhttp3.Protocol
import okhttp3.Request
import okhttp3.Response
import java.io.IOException
import java.net.InetAddress
import java.net.InetSocketAddress
import java.net.Proxy

open class DelegateEventListener(
protected val delegateEventListener: EventListener?
) : EventListener() {
override fun callStart(call: Call) {
delegateEventListener?.callStart(call)
}

override fun callEnd(call: Call) {
delegateEventListener?.callEnd(call)
}

override fun callFailed(call: Call, ioe: IOException) {
delegateEventListener?.callFailed(call, ioe)
}

override fun canceled(call: Call) {
delegateEventListener?.canceled(call)
}

override fun cacheConditionalHit(call: Call, cachedResponse: Response) {
delegateEventListener?.cacheConditionalHit(call, cachedResponse)
}

override fun cacheHit(call: Call, response: Response) {
delegateEventListener?.cacheHit(call, response)
}

override fun cacheMiss(call: Call) {
delegateEventListener?.cacheMiss(call)
}

override fun connectEnd(
call: Call,
inetSocketAddress: InetSocketAddress,
proxy: Proxy,
protocol: Protocol?
) {
delegateEventListener?.connectEnd(call, inetSocketAddress, proxy, protocol)
}

override fun connectFailed(
call: Call,
inetSocketAddress: InetSocketAddress,
proxy: Proxy,
protocol: Protocol?,
ioe: IOException
) {
delegateEventListener?.connectFailed(call, inetSocketAddress, proxy, protocol, ioe)
}

override fun connectStart(
call: Call,
inetSocketAddress: InetSocketAddress,
proxy: Proxy
) {
delegateEventListener?.connectStart(call, inetSocketAddress, proxy)
}

override fun connectionAcquired(call: Call, connection: Connection) {
delegateEventListener?.connectionAcquired(call, connection)
}

override fun connectionReleased(call: Call, connection: Connection) {
delegateEventListener?.connectionReleased(call, connection)
}

override fun dnsEnd(
call: Call,
domainName: String,
inetAddressList: List<@JvmSuppressWildcards InetAddress>
) {
delegateEventListener?.dnsEnd(call, domainName, inetAddressList)
}

override fun dnsStart(call: Call, domainName: String) {
delegateEventListener?.dnsStart(call, domainName)
}

override fun proxySelectEnd(
call: Call,
url: HttpUrl,
proxies: List<@JvmSuppressWildcards Proxy>
) {
delegateEventListener?.proxySelectEnd(call, url, proxies)
}

override fun proxySelectStart(call: Call, url: HttpUrl) {
delegateEventListener?.proxySelectStart(call, url)
}

override fun requestBodyStart(call: Call) {
delegateEventListener?.requestBodyStart(call)
}

override fun requestFailed(call: Call, ioe: IOException) {
delegateEventListener?.requestFailed(call, ioe)
}

override fun requestHeadersEnd(call: Call, request: Request) {
delegateEventListener?.requestHeadersEnd(call, request)
}

override fun requestHeadersStart(call: Call) {
delegateEventListener?.requestHeadersStart(call)
}

override fun responseBodyStart(call: Call) {
delegateEventListener?.responseBodyStart(call)
}

override fun responseFailed(call: Call, ioe: IOException) {
delegateEventListener?.responseFailed(call, ioe)
}

override fun responseHeadersStart(call: Call) {
delegateEventListener?.responseHeadersStart(call)
}

override fun satisfactionFailure(call: Call, response: Response) {
delegateEventListener?.satisfactionFailure(call, response)
}

override fun secureConnectEnd(call: Call, handshake: Handshake?) {
delegateEventListener?.secureConnectEnd(call, handshake)
}

override fun secureConnectStart(call: Call) {
delegateEventListener?.secureConnectStart(call)
}
}
Loading
Loading