Skip to main content

Privacy and network traffic

note

Looking for the previous SDK? See the 6.x network privacy page.

Disabling network traffic collection

Network capture can be disabled via the CaptureNetwork option — see configuration.

Sanitizing network events

7.0 uses the generic EventFilter<T> interface. Its single filter(event, callback) method hands you the event and a Callback1 to invoke with the result: call callback.run(event) to keep the (possibly mutated) NetworkEvent, or callback.run(null) to drop it. The event type is NetworkEvent (package com.bugsee.library.contracts.exchange), which exposes getters/setters for the event fields (the no-body reason is exposed via getBodyAbsenceReason()).

Bugsee.setNetworkEventFilter((event, callback) -> {
// URL
String url = event.getUrl();
if (url != null && url.contains("token")) {
event.setUrl(url.replaceAll("token=\\S+", "token=[REDACTED]"));
}

// Headers
Map<String, String> headers = event.getHeaders();
if (headers != null) {
headers.remove("Authorization");
event.setHeaders(headers);
}

// Body
String body = event.getBody();
if (body != null && body.contains("\"password\"")) {
event.setBody("[REDACTED]");
}

// Error text (captured for failed requests)
if (event.getErrorDescription() != null) {
event.setErrorDescription("…");
}

callback.run(event); // keep
// callback.run(null); // drop
});

Capture from OkHttp 3/4, Ktor 2/3, and Cronet is wired automatically by the Bugsee Gradle plugin through the matching extension modules — no manual interceptor registration is required.

Declaring the filter in the manifest

You can also point Bugsee at a network filter from AndroidManifest.xml, with no code. Add a com.bugsee.filter.network-event <meta-data> whose value is a class that implements EventFilter<NetworkEvent> and has a public no-arg constructor. The benefit: the filter is in force from the very first captured event, even under auto-initialization, before any of your own code runs.

<application>
<meta-data android:name="com.bugsee.filter.network-event"
android:value="com.example.MyNetworkFilter" />
</application>
import androidx.annotation.Keep;
import com.bugsee.library.contracts.common.Callback1;
import com.bugsee.library.contracts.exchange.EventFilter;
import com.bugsee.library.contracts.exchange.NetworkEvent;

@Keep // referenced only by name in the manifest — keep it from R8
public class MyNetworkFilter implements EventFilter<NetworkEvent> {
public MyNetworkFilter() { } // required public no-arg constructor

@Override
public void filter(NetworkEvent event, Callback1<NetworkEvent> callback) {
String url = event.getUrl();
if (url != null && url.contains("token")) {
event.setUrl(url.replaceAll("token=\\S+", "token=[REDACTED]"));
}
callback.run(event); // pass null to drop
}
}

A filter set in code with Bugsee.setNetworkEventFilter(...) takes precedence over the manifest one. Because the class is referenced only by name, keep it from R8 — annotate it @Keep or add -keep class com.example.MyNetworkFilter { <init>(); }.

The same mechanism is available for logs and breadcrumbs.

Found an issue, typo, or wrong statement on this page? Report it now →