okhttp / okhttp3 / EventListener

EventListener

abstract class EventListener

Listener for metrics events. Extend this class to monitor the quantity, size, and duration of your application's HTTP calls.

All start/connect/acquire events will eventually receive a matching end/release event, either successful (non-null parameters), or failed (non-null throwable). The first common parameters of each event pair are used to link the event in case of concurrent or repeated events e.g. dnsStart(call, domainName) -> dnsEnd(call, domainName, inetAddressList).

Nesting is as follows

Request events are ordered:

requestHeaders -> requestBody -> responseHeaders -> responseBody

Since connections may be reused, the dns and connect events may not be present for a call, or may be repeated in case of failure retries, even concurrently in case of happy eyeballs type scenarios. A redirect cross domain, or to use https may cause additional connection and request events.

All event methods must execute fast, without external locking, cannot throw exceptions, attempt to mutate the event parameters, or be re-entrant back into the client. Any IO - writing to files or network should be done asynchronously.

Types

Factory

interface Factory

Constructors

<init>

EventListener()

Listener for metrics events. Extend this class to monitor the quantity, size, and duration of your application's HTTP calls.

Functions

callEnd

open fun callEnd(call: Call): Unit

Invoked immediately after a call has completely ended. This includes delayed consumption of response body by the caller.

callFailed

open fun callFailed(call: Call, ioe: IOException): Unit

Invoked when a call fails permanently.

callStart

open fun callStart(call: Call): Unit

Invoked as soon as a call is enqueued or executed by a client. In case of thread or stream limits, this call may be executed well before processing the request is able to begin.

connectEnd

open fun connectEnd(call: Call, inetSocketAddress: InetSocketAddress, proxy: Proxy, protocol: Protocol?): Unit

Invoked immediately after a socket connection was attempted.

connectFailed

open fun connectFailed(call: Call, inetSocketAddress: InetSocketAddress, proxy: Proxy, protocol: Protocol?, ioe: IOException): Unit

Invoked when a connection attempt fails. This failure is not terminal if further routes are available and failure recovery is enabled.

connectionAcquired

open fun connectionAcquired(call: Call, connection: Connection): Unit

Invoked after a connection has been acquired for the call.

connectionReleased

open fun connectionReleased(call: Call, connection: Connection): Unit

Invoked after a connection has been released for the call.

connectStart

open fun connectStart(call: Call, inetSocketAddress: InetSocketAddress, proxy: Proxy): Unit

Invoked just prior to initiating a socket connection.

dnsEnd

open fun dnsEnd(call: Call, domainName: String, inetAddressList: List<InetAddress>): Unit

Invoked immediately after a DNS lookup.

dnsStart

open fun dnsStart(call: Call, domainName: String): Unit

Invoked just prior to a DNS lookup. See Dns.lookup.

requestBodyEnd

open fun requestBodyEnd(call: Call, byteCount: Long): Unit

Invoked immediately after sending a request body.

requestBodyStart

open fun requestBodyStart(call: Call): Unit

Invoked just prior to sending a request body. Will only be invoked for request allowing and having a request body to send.

requestFailed

open fun requestFailed(call: Call, ioe: IOException): Unit

Invoked when a request fails to be written.

requestHeadersEnd

open fun requestHeadersEnd(call: Call, request: Request): Unit

Invoked immediately after sending request headers.

requestHeadersStart

open fun requestHeadersStart(call: Call): Unit

Invoked just prior to sending request headers.

responseBodyEnd

open fun responseBodyEnd(call: Call, byteCount: Long): Unit

Invoked immediately after receiving a response body and completing reading it.

responseBodyStart

open fun responseBodyStart(call: Call): Unit

Invoked just prior to receiving the response body.

responseFailed

open fun responseFailed(call: Call, ioe: IOException): Unit

Invoked when a response fails to be read.

responseHeadersEnd

open fun responseHeadersEnd(call: Call, response: Response): Unit

Invoked immediately after receiving response headers.

responseHeadersStart

open fun responseHeadersStart(call: Call): Unit

Invoked just prior to receiving response headers.

secureConnectEnd

open fun secureConnectEnd(call: Call, handshake: Handshake?): Unit

Invoked immediately after a TLS connection was attempted.

secureConnectStart

open fun secureConnectStart(call: Call): Unit

Invoked just prior to initiating a TLS connection.

Companion Object Properties

NONE

val NONE: EventListener