okhttp / okhttp3 / 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).

Events are typically nested with this structure:

This nesting is typical but not strict. For example, when calls use “Expect: continue” the request body start and end events occur within the response header events. Similarly, duplex calls interleave the request and response bodies.

Since connections may be reused, the proxy selection, DNS, and connect events may not be present for a call. In future releases of OkHttp these events may also occur concurrently to permit multiple routes to be attempted simultaneously.

Events and sequences of events may be repeated for retries and follow-ups.

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.


Name Summary
Factory interface Factory


Name Summary
<init> Listener for metrics events. Extend this class to monitor the quantity, size, and duration of your application’s HTTP calls.EventListener()


Name Summary
cacheConditionalHit Invoked when a response will be served from the cache or network based on validating the cached Response freshness. Will be followed by cacheHit or cacheMiss after the network Response is available.open fun cacheConditionalHit(call:Call, cachedResponse:Response):Unit
cacheHit Invoked when a result is served from the cache. The Response provided is the top level Response and normal event sequences will not be received.open fun cacheHit(call:Call, response:Response):Unit
cacheMiss Invoked when a response will be served from the network. The Response will be available from normal event sequences.open fun cacheMiss(call:Call):Unit
callEnd Invoked immediately after a call has completely ended. This includes delayed consumption of response body by the caller.open fun callEnd(call:Call):Unit
callFailed Invoked when a call fails permanently.open fun callFailed(call:Call, ioe:IOException):Unit
callStart 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.open fun callStart(call:Call):Unit
canceled Invoked when a call is canceled.open fun canceled(call:Call):Unit
connectEnd Invoked immediately after a socket connection was attempted.open fun connectEnd(call:Call, inetSocketAddress:InetSocketAddress, proxy:Proxy, protocol:Protocol?):Unit
connectFailed Invoked when a connection attempt fails. This failure is not terminal if further routes are available and failure recovery is enabled.open fun connectFailed(call:Call, inetSocketAddress:InetSocketAddress, proxy:Proxy, protocol:Protocol?, ioe:IOException):Unit
connectionAcquired Invoked after a connection has been acquired for the call.open fun connectionAcquired(call:Call, connection:Connection):Unit
connectionReleased Invoked after a connection has been released for the call.open fun connectionReleased(call:Call, connection:Connection):Unit
connectStart Invoked just prior to initiating a socket connection.open fun connectStart(call:Call, inetSocketAddress:InetSocketAddress, proxy:Proxy):Unit
dnsEnd Invoked immediately after a DNS lookup.open fun dnsEnd(call:Call, domainName:String, inetAddressList:List<InetAddress>):Unit
dnsStart Invoked just prior to a DNS lookup. See Dns.lookup.open fun dnsStart(call:Call, domainName:String):Unit
proxySelectEnd Invoked after proxy selection.open fun proxySelectEnd(call:Call, url:HttpUrl, proxies:List<Proxy>):Unit
proxySelectStart Invoked prior to a proxy selection.open fun proxySelectStart(call:Call, url:HttpUrl):Unit
requestBodyEnd Invoked immediately after sending a request body.open fun requestBodyEnd(call:Call, byteCount:Long):Unit
requestBodyStart Invoked just prior to sending a request body. Will only be invoked for request allowing and having a request body to send.open fun requestBodyStart(call:Call):Unit
requestFailed Invoked when a request fails to be written.open fun requestFailed(call:Call, ioe:IOException):Unit
requestHeadersEnd Invoked immediately after sending request headers.open fun requestHeadersEnd(call:Call, request:Request):Unit
requestHeadersStart Invoked just prior to sending request headers.open fun requestHeadersStart(call:Call):Unit
responseBodyEnd Invoked immediately after receiving a response body and completing reading it.open fun responseBodyEnd(call:Call, byteCount:Long):Unit
responseBodyStart Invoked when data from the response body is first available to the application.open fun responseBodyStart(call:Call):Unit
responseFailed Invoked when a response fails to be read.open fun responseFailed(call:Call, ioe:IOException):Unit
responseHeadersEnd Invoked immediately after receiving response headers.open fun responseHeadersEnd(call:Call, response:Response):Unit
responseHeadersStart Invoked when response headers are first returned from the server.open fun responseHeadersStart(call:Call):Unit
satisfactionFailure Invoked when a call fails due to cache rules. For example, we’re forbidden from using the network and the cache is insufficientopen fun satisfactionFailure(call:Call, response:Response):Unit
secureConnectEnd Invoked immediately after a TLS connection was attempted.open fun secureConnectEnd(call:Call, handshake:Handshake?):Unit
secureConnectStart Invoked just prior to initiating a TLS connection.open fun secureConnectStart(call:Call):Unit

Companion Object Properties

Name Summary
NONE val NONE:EventListener