> For the complete documentation index, see [llms.txt](https://docs.luciq.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.luciq.ai/references/report-data/logging/network-logging-android.md).

# Network Logging - Android

API reference for network logging in Android with Luciq. Configure network monitoring APIs to capture HTTP requests and responses in your Android app.

Network logs are automatically collected by Luciq when possible. There are many way to configure and manipulate these logs from the code.

### Logging `HttpUrlConnection` Requests

To log network requests, use `LuciqNetworkLog` then use the following method at the `HttpUrlConnection`, `requestBody` and `responseBody`. A more detailed example can be found [here](https://docs.luciq.ai/android/set-up-luciq-for-android/logs-and-profiling/report-logs-for-android).

**Logging `HttpUrlConnection` Requests**

{% tabs fullWidth="true" %}
{% tab title="Java" %}

```java
LuciqNetworkLog networkLog = new LuciqNetworkLog();
networkLog.Log(urlConnection, requestBody, responseBody);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
LuciqNetworkLog networkLog = new LuciqNetworkLog()
networkLog.Log(urlConnection, requestBody, responseBody)
```

{% endtab %}
{% endtabs %}

### Logging `Okhttp` Requests

In order to log Okhttp requests, first make sure that you compiled Luciq with a network interceptor. By adding the following to your Gradle: `implementation 'com.luciq.library:luciq-with-okhttp-interceptor:8+'`

An example of the implementation can be found on the right hand side of this section.

**Logging `Okhttp` Requests**

First, start by compiling Luciq with a network interceptor using this API.

```groovy
implementation 'com.luciq.library:luciq-with-okhttp-interceptor:11.5.4'
```

Then to log Oktthp requests, use the `LuciqOkhttpInterceptor` as shown in the following example.

{% tabs fullWidth="true" %}
{% tab title="Java" %}

```java
LuciqOkhttpInterceptor luciqOkhttpInterceptor = new LuciqOkhttpInterceptor();

OkHttpClient client = new OkHttpClient.Builder()
    .addInterceptor(interceptor)
    .addInterceptor(luciqOkhttpInterceptor)
    .build();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val luciqOkhttpInterceptor = LuciqOkhttpInterceptor()

val client = OkHttpClient.Builder()
         .addInterceptor(interceptor)
         .addInterceptor(luciqOkhttpInterceptor)
         .build()
```

{% endtab %}
{% endtabs %}

### Modifying Requests

If you want to modify a network request before it gets sent to the dashboard, you may follow the steps below.

1. Create a `NetworkLogListener` object and modify the captured network log as shown below.

{% tabs fullWidth="true" %}
{% tab title="Java" %}

```java
NetworkLogListener networkLogListener = new NetworkLogListener() {
    @Override
    public NetworkLogSnapshot onNetworkLogCaptured(NetworkLogSnapshot networkLog) {
        //Modify the received networkLog parameter
        return networkLog;
    }
};
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val networkLogListener = NetworkLogListener { networkLog: NetworkLogSnapshot ->
    //Modify the received networkLog parameter
    return@NetworkLogListener networkLog
}
```

{% endtab %}
{% endtabs %}

2. Register the created `NetworkLogListener` to your `LuciqOkHttpInterceptor` object. This can be done through two different methods:

a. Pass it in the constructor.

```
val luciqOkhttpInterceptor = LuciqOkhttpInterceptor(networkLogListener)
```

b. Call registerNetworkLogsListener method on LuciqOkhttpInterceptor object.

```
val luciqOkhttpInterceptor = LuciqOkhttpInterceptor()
luciqOkhttpInterceptor.registerNetworkLogsListener(networkLogListener)
```

If you want to remove the network listener, you can do so using this API.

{% tabs fullWidth="true" %}
{% tab title="Java" %}

```java
luciqOkhttpInterceptor.removeNetworkLogsListener();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
luciqOkhttpInterceptor.removeNetworkLogsListener()
```

{% endtab %}
{% endtabs %}

### Partial Success for GraphQL Requests

Luciq flags GraphQL requests that return an HTTP `2xx` response with a non-empty `errors` array as partial successes. When this happens, the captured network log carries a `partial_success` flag, making mixed success/failure GraphQL responses explicit in both Bug Reporting and Session Replay.

Partial-success flagging for GraphQL responses is available starting from Android SDK **v19.9.0**.

### Identifying Cancelled Requests

`NetworkLogSnapshot.isCanceled` is `true` when your app cancelled an OkHttp request before it completed, such as a `Call.cancel()`. Cancelled requests are captured as failures; return `null` from the listener to drop them.

{% tabs fullWidth="true" %}
{% tab title="Java" %}

```java
NetworkLogListener networkLogListener = new NetworkLogListener() {
    @Override
    public NetworkLogSnapshot onNetworkLogCaptured(NetworkLogSnapshot networkLog) {
        return networkLog.isCanceled() ? null : networkLog;
    }
};
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val networkLogListener = NetworkLogListener { networkLog: NetworkLogSnapshot ->
    if (networkLog.isCanceled) null else networkLog
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
`isCanceled` is available starting from **SDK v19.10.1** and applies to **OkHttp requests only** — logs captured through UrlConnection, WebView, or gRPC always report `false`.

The property is read-only, is never sent to the dashboard, and is not carried over by `copy()` — read it before creating a modified copy.
{% endhint %}

### Naming Client-Side Failures

When a request fails on the client side before any response arrives, APM records it under the name of the failure, such as `UnknownHostException`. If an interceptor added after Luciq's wraps every failure in your own exception, read `NetworkLogSnapshot.exception` and set `NetworkLogSnapshot.failureName` to record the original failure instead.

* `exception`: **Throwable** (read-only) — The exception the SDK caught. `null` when a response was received, and for gRPC, WebView, and manually logged requests.
* `failureName`: **String** — The name APM records. Defaults to the class name of `exception`, or the gRPC status name. `null` when the request did not fail on the client side.

{% tabs fullWidth="true" %}
{% tab title="Java" %}

```java
NetworkLogListener networkLogListener = new NetworkLogListener() {
    @Override
    public NetworkLogSnapshot onNetworkLogCaptured(NetworkLogSnapshot networkLog) {
        Throwable error = networkLog.getException();
        if (error instanceof MyNetworkException && error.getCause() != null) {
            networkLog.setFailureName(error.getCause().getClass().getSimpleName());
        }
        return networkLog;
    }
};
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val networkLogListener = NetworkLogListener { networkLog: NetworkLogSnapshot ->
    val error = networkLog.exception
    if (error is MyNetworkException) {
        error.cause?.let { networkLog.failureName = it::class.java.simpleName }
    }
    networkLog
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
`exception` and `failureName` are available starting from **SDK v19.16.0**.

The SDK trims `failureName` and keeps at most 100 characters; a `null` or blank value keeps the SDK's name. APM always records the new name; a bug report may keep the failure text it captured instead. Neither property is carried over by `copy()`.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.luciq.ai/references/report-data/logging/network-logging-android.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
