Skip to content


We use Okhttp sometimes with Retrofit for networking in Gradle plugins and Android libraries.

Obtaining an OkHttpClient#

Add dependency on http-client module:

dependencies {

Create an instance of HttpClientProvider

val httpClientProvider = HttpClientProvider(statsdSender, timeProvider)

Get the client:

val httpClient = httpClientProvider.provide().build()

Method provide() returns OkHttpClient.Builder so you can configure it further

Required tag#

Obtained client needs some additional information to be able to gather required statistics.

Every request should contain a tag of type RequestMetadata


Missing tag will lead to missing metrics for this api method / service Warning message could be found in logs

Creating OkHttpRequest manually#

    .url("some url")
    .tag(, RequestMetadata("some-service", "some-method"))

Using Retrofit#

interface SomeApi {

    fun someMethod(
        @Body someBody: String,
        @Tag metadata: RequestMetadata = RequestMetadata("some-service", "some-method")
    ): Call<Unit>