Skip to main content

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():

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

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

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

Ktor

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

HttpClient client = new 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:

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

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

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

Picasso

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

Picasso picasso = new Picasso.Builder(context) //context - activity or application instance.
.loader(new 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:

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

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

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

Glide

Glide uses HttpUrlConnection by default, so its 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.

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);
}
}

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.