Network events

HttpURLConnection, HttpsURLConnection

Bugsee automatically intercepts network requests made with the following clients and libraries, which use these clients as underlying HTTP stack. For other HTTP clients additional actions are required.

OkHttpClient

OkHttp 2.2+ is supported. For OkHttp of versions 2.2 - 2.7.5 you need to call method addNetworkLoggingToOkHttpClient():

!Java

OkHttpClient client = new OkHttpClient();
Bugsee.addNetworkLoggingToOkHttpClient(client);

!Kotlin

val client = OkHttpClient()
Bugsee.addNetworkLoggingToOkHttpClient(client)

For OkHttp 3.x you need to call method addNetworkLoggingToOkHttpBuilder():

!Java

OkHttpClient.Builder builder = new OkHttpClient.Builder();
OkHttpClient client = Bugsee.addNetworkLoggingToOkHttpBuilder(builder)
    .build();

!Kotlin

val builder: OkHttpClient.Builder = OkHttpClient.Builder()
val client: OkHttpClient = Bugsee.addNetworkLoggingToOkHttpBuilder(builder)
    .build()

Ktor

Ktor 2.3+ is supported. You need to call method addNetworkLoggingToKtorHttpClient():

!Java

HttpClient client = new HttpClient(engine, clientConfig);
Bugsee.addNetworkLoggingToKtorHttpClient(client);

!Kotlin

val client = HttpClient(engine, clientConfig)
Bugsee.addNetworkLoggingToKtorHttpClient(client)

Retrofit

Retrofit 1.9+ is supported. For Retrofit 1.9, which uses OkHttp 2.x, you need to set wrapped OkHttpClient to RestAdapter.Builder:

!Java

OkHttpClient client = new OkHttpClient();
Bugsee.addNetworkLoggingToOkHttpClient(client);
RestAdapter restAdapter = new RestAdapter.Builder()                  
    .setClient(new OkClient(client))
    .build();

!Kotlin

val client = OkHttpClient()
Bugsee.addNetworkLoggingToOkHttpClient(client)
val restAdapter: RestAdapter = RestAdapter.Builder()
    .setClient(OkClient(client))
    .build()

For Retrofit 2.x, which uses OkHttp 3.x you need to set wrapped OkHttpClient to Retrofit.Builder:

!Java

OkHttpClient.Builder builder = new OkHttpClient.Builder();
OkHttpClient client = Bugsee.addNetworkLoggingToOkHttpBuilder(builder)
    .build();
Retrofit retrofit = new Retrofit.Builder()               
    .client(client)
    .build();

!Kotlin

val builder: OkHttpClient.Builder = OkHttpClient.Builder()
val client: OkHttpClient = Bugsee.addNetworkLoggingToOkHttpBuilder(builder)
    .build()
val retrofit = Retrofit.Builder()
    .client(client)
    .build()

Picasso

For Picasso 1.x it is necessary to call loader() method:

!Java

Picasso picasso = new Picasso.Builder(context) //context - activity or application instance.
    .loader(new UrlConnectionLoader(context))
    .build();

!Kotlin

val picasso: Picasso = Picasso.Builder(context) //context - activity or application instance.
    .loader(UrlConnectionLoader(context))
    .build()

For Picasso 2.0-2.5.2 it is necessary to call downloader() method with an instance of UrlConnectionDownloader as a parameter:

!Java

Picasso picasso = new Picasso.Builder(context) //context - activity or application instance.
    .downloader(new UrlConnectionDownloader(context))
    .build();

!Kotlin

val picasso = Picasso.Builder(context) //context - activity or application instance.
    .downloader(UrlConnectionDownloader(context))
    .build()

For Picasso 2.7+ some additional actions are required comparing with the previous case:

!Java

OkHttp3Downloader okHttp3Downloader = new OkHttp3Downloader(context); //context - activity or application instance.
Bugsee.addNetworkLoggingToPicassoDownloader(okHttp3Downloader);
Picasso picasso = new Picasso.Builder(context)
    .downloader(okHttp3Downloader)
    .build();

!Kotlin

val okHttp3Downloader = OkHttp3Downloader(context) //context - activity or application instance.

Bugsee.addNetworkLoggingToPicassoDownloader(okHttp3Downloader)
val picasso = Picasso.Builder(context)
    .downloader(okHttp3Downloader)
    .build()

Glide

Glide uses HttpUrlConnection by default, so it's network events are intercepted automatically.

But if you use OkHttpClient as underlying HTTP stack for Glide, additional actions are required. First, add class, which extends OkHttpGlideModule class, with overridden registerComponents() method.

!Java

class CustomGlideModule extends OkHttpGlideModule {
    @Override
    public void registerComponents(Context context, Glide glide, Registry registry) {
        OkHttpClient client = new OkHttpClient();
        Bugsee.addNetworkLoggingToOkHttpClient(client);
        OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory(client);
        registry.replace(GlideUrl.class, InputStream.class, factory);
    }
}

!Kotlin

class CustomGlideModule : OkHttpGlideModule() {
    override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
        val client = OkHttpClient()
        Bugsee.addNetworkLoggingToOkHttpClient(client)
        val factory = OkHttpUrlLoader.Factory(client)
        registry.replace(
            GlideUrl::class.java,
            InputStream::class.java,
            factory
        )
    }
}

Then register this class in <application> node in application manifest.

<application>
<meta-data
    android:name="com.example.CustomGlideModule"
    android:value="GlideModule"/>
</application>

Replace "com.example" by package of your class, which extends OkHttpGlideModule.