Network Logging (Ktor)

Network logging with the Luciq Ktor plugin and NetworkLogger in KMP.

The Luciq KMP library provides automatic network logging for Ktor HttpClient: it intercepts requests and responses, injects W3C trace headers for distributed tracing, and sends logs to the native Luciq SDK for bug reports and APMKmp.

Install the plugin

Add the plugin to your HttpClient:

Kotlin
import ai.luciq.kmp.interceptors.LuciqKtorPlugin

val client = HttpClient(Engine) {
    install(LuciqKtorPlugin)
}

All requests made with this client are logged (URL, method, headers, body, timing, status). The plugin also injects a W3C traceparent header when the native SDK supports it.

How it works

  1. Request: The plugin captures URL, method, headers, and body, and may add a traceparent header.

  2. Response: It captures status, headers, and body, computes duration, and sends a NetworkData record to the native SDK via NetworkLoggerKmp.networkLog.

  3. Errors: Failed requests are logged with error domain and message.

Body size may be truncated by the native SDK. Obfuscation and omission callbacks (see Obfuscation & Omission) are applied before sending to the native SDK.

Manual logging

If you use another HTTP client, build a NetworkData instance and call:

You can get a W3C header for your request with:

Body and auto-masking

Last updated