# Network

Network requests and responses can be logged for APM and bug reports. The KMP library provides:

1. **Luciq Ktor plugin** – Intercepts Ktor `HttpClient` calls, injects W3C trace headers, and logs requests/responses.
2. **NetworkLogger** – Manual logging and callbacks for obfuscation and omission.

### Ktor plugin

Install the plugin on your `HttpClient` so all requests and responses are logged and W3C headers are injected:

{% code title="Kotlin" %}

```kotlin
import ai.luciq.kmp.interceptors.LuciqKtorPlugin

val client = HttpClient(engine) {
    install(LuciqKtorPlugin)
}
```

{% endcode %}

No extra code is needed for each request; the plugin handles timing, headers, and body capture (subject to size limits and obfuscation/omission callbacks).

### Manual network logging

If you are not using Ktor or need to log a request from another HTTP client, use `NetworkLoggerKmp.networkLog` with a `NetworkData` instance. Build `NetworkData` with your request/response details (URL, method, headers, body, timestamps, status, etc.). See the [Network Logging (Ktor)](https://docs.luciq.ai/kmp/setup-luciq-for-kmp/network-logging-ktor) section for obfuscation and omission.

### Enable/disable body and auto-masking

{% code title="Kotlin" %}

```kotlin
NetworkLoggerKmp.setNetworkLogBodyEnabled(true)
NetworkLoggerKmp.setNetworkAutoMaskingEnabled(true)
```

{% endcode %}

For full details and W3C header usage, see [Network Logging (Ktor)](https://docs.luciq.ai/kmp/setup-luciq-for-kmp/network-logging-ktor) and [Obfuscation & Omission](https://docs.luciq.ai/kmp/setup-luciq-for-kmp/network-logging-ktor/obfuscation-and-omission).
