https://github.com/cosminmihumdc/ktormonitor
Powerful tool to monitor Ktor Client requests and responses, making it easier to debug and analyze network communication.
https://github.com/cosminmihumdc/ktormonitor
android android-library client http ios jvm jvm-library kotlin kotlin-multiplatform ktor ktor-client ktor-plugin linux macos proxy wasm windows
Last synced: about 2 months ago
JSON representation
Powerful tool to monitor Ktor Client requests and responses, making it easier to debug and analyze network communication.
- Host: GitHub
- URL: https://github.com/cosminmihumdc/ktormonitor
- Owner: CosminMihuMDC
- License: apache-2.0
- Created: 2025-01-26T16:29:25.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2026-01-18T16:14:01.000Z (2 months ago)
- Last Synced: 2026-01-19T00:36:36.669Z (2 months ago)
- Topics: android, android-library, client, http, ios, jvm, jvm-library, kotlin, kotlin-multiplatform, ktor, ktor-client, ktor-plugin, linux, macos, proxy, wasm, windows
- Language: Kotlin
- Homepage:
- Size: 92.5 MB
- Stars: 186
- Watchers: 1
- Forks: 16
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
[](https://search.maven.org/artifact/ro.cosminmihu.ktor/ktor-monitor-logging)
[](https://github.com/CosminMihuMDC/KtorMonitor/blob/main/LICENSE)
[](https://cosminmihumdc.github.io/KtorMonitor)
[](https://kotlinlang.slack.com/archives/C0AB9GA32H0)
[](https://klibs.io/project/CosminMihuMDC/KtorMonitor)
[](https://cosminmihumdc.github.io/KtorMonitor)
[](https://cosminmihumdc.github.io/KtorMonitor/api)
[](https://github.com/CosminMihuMDC/KtorMonitor)
[](https://github.com/CosminMihuMDC/KtorMonitor/fork)
#
KtorMonitor
Powerful tool to monitor [Ktor Client](https://ktor.io/) requests and responses, making it easier to debug and analyze network communication.

## ✨ Features
* 🌐**Ktor Network Monitoring**: Real-time interception and logging of [Ktor Client](https://ktor.io/) traffic.
* 📱**Kotlin Multiplatform (KMP)**: Full support for **Android**, **iOS**, **Desktop (JVM)**, **Wasm**, and **JS**.
* 🛠️**Highly Configurable**: Customize retention periods, content length limits, and notification behavior.
* 🔒**Security First**: Redact sensitive headers (e.g., *Authorization*).
* 📂**Data Export**: Save request/response details to local files for easier debugging or sharing.
* 🎨**Rich Previews**: Built-in viewers for *JSON*, *XML*, *HTML*, *CSS*, *Form Data*, *Image* (*JPG*, *PNG*, *SVG*, *GIF*, *WEBP*).
* 📡**SSE & WebSockets**: Track one-way streams (*SSE*) and bidirectional traffic (*WebSockets*).
* 🛡️**Production Safe**: No-Op version to ensure monitoring code is excluded from your production builds.
By default, **```KtorMonitor```**:
* **android** → *isActive* for ```debug``` builds and disabled for ```release``` builds
* **ios** → *isActive* for ```debug``` builds and disabled for ```release``` builds
* **desktop** -> *isActive* for all builds
* **wasm** → *isActive* for all builds
* **js** → *isActive* for all builds
## 📦 Setup (Kotlin Multiplatform)
### 
```kotlin
kotlin {
sourceSets {
commonMain.dependencies {
implementation("ro.cosminmihu.ktor:ktor-monitor-logging:1.10.0")
}
}
}
```
**For Release Builds (No-Op)**
To isolate KtorMonitor from release builds, use the `ktor-monitor-logging-no-op` variant. This ensures the monitor code is not included in production artifact.
```kotlin
kotlin {
sourceSets {
commonMain.dependencies {
implementation("ro.cosminmihu.ktor:ktor-monitor-logging-no-op:1.10.0")
}
}
}
```
## 📦 Setup (Android only)
### 
```kotlin
dependencies {
debugImplementation("ro.cosminmihu.ktor:ktor-monitor-logging:1.10.0")
releaseImplementation("ro.cosminmihu.ktor:ktor-monitor-logging-no-op:1.10.0")
}
```
For ***Android minSdk < 26***, [Core Library Desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) is required.
###
Install Ktor Client Plugin
```kotlin
HttpClient {
install(KtorMonitorLogging) {
sanitizeHeader { header -> header == "Authorization" }
filter { request -> !request.url.host.contains("cosminmihu.ro") }
showNotification = true
retentionPeriod = RetentionPeriod.OneHour
maxContentLength = ContentLength.Default
}
}
```
- ```sanitizeHeader``` - sanitize sensitive headers to avoid their values appearing in the logs
- ```filter``` - filter logs for calls matching a predicate.
- ```showNotification``` - Keep track of latest requests and responses into notification. Default is **true**. Android and iOS only. Notifications permission needs to be granted.
- ```retentionPeriod``` - The retention period for the logs. Default is **1h**.
- ```maxContentLength``` - The maximum length of the content that will be logged. After this, body will be truncated. Default is **250_000**. To log the entire body use ```ContentLength.Full```.
## 🧩 Integration
Add the UI component to your application based on your targeted platform.
Compose Multiplatform (Common)
* Use ```KtorMonitor``` Composable
```kotlin
@Composable
fun Composable() {
KtorMonitor()
}
```
Android
- If ```showNotifcation = true``` and **android.permission.POST_NOTIFICATIONS** is granted, the library will display a notification showing a summary of ongoing KTOR activity. Tapping on the notification launches the full ```KtorMonitor```.
- Apps can optionally use the ```KtorMonitor()``` Composable directly into own Composable code.
- For ***Android minSdk < 26***, [Core Library Desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) is required.
iOS
* If ```showNotifcation = true``` and notification permission is granted, the library will display a notification showing a summary of ongoing KTOR activity.
* Use ```KtorMonitorViewController```
```kotlin
fun MainViewController() = KtorMonitorViewController()
```
```swift
struct KtorMonitorView: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIViewController {
MainViewControllerKt.MainViewController()
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}
struct ContentView: View {
var body: some View {
KtorMonitorView()
.ignoresSafeArea()
}
}
```
Desktop (Compose)
* Use ```KtorMonitorWindow``` Composable
```kotlin
fun main() = application {
var showKtorMonitor by rememberSaveable { mutableStateOf(false) }
KtorMonitorWindow(
onCloseRequest = { showKtorMonitor = false },
show = showKtorMonitor
)
}
```
* Use ```KtorMonitorWindow``` Composable with ```KtorMonitorMenuItem```
```kotlin
fun main() = application {
var showKtorMonitor by rememberSaveable { mutableStateOf(false) }
Tray(
icon = painterResource(Res.drawable.ic_launcher),
menu = {
KtorMonitorMenuItem { showKtorMonitor = true }
}
)
KtorMonitorWindow(
show = showKtorMonitor,
onCloseRequest = { showKtorMonitor = false }
)
}
```
Desktop (Swing)
* Use ```KtorMonitorPanel``` Swing Panel
```kotlin
fun main() = application {
SwingUtilities.invokeLater {
val frame = JFrame()
frame.add(KtorMonitorPanel, BorderLayout.CENTER)
frame.isVisible = true
}
}
```
Wasm / Js
* Web targets require a few additional webpack steps.
```kotlin
kotlin {
sourceSets {
webMain.dependencies {
implementation(devNpm("copy-webpack-plugin", "9.1.0"))
}
}
}
```
```javascript
// {project}/webpack.config.d/sqljs.js
config.resolve = {
fallback: {
fs: false,
path: false,
crypto: false,
}
};
const CopyWebpackPlugin = require('copy-webpack-plugin');
config.plugins.push(
new CopyWebpackPlugin({
patterns: [
'../../node_modules/sql.js/dist/sql-wasm.wasm'
]
})
);
```
```kotlin
ComposeViewport {
App()
}
```
## ✍️ Feedback
Found a bug or have a feature request? [File an issue](https://github.com/CosminMihuMDC/KtorMonitor/issues/new).
## 🙌 Acknowledgments
[](http://kotlinlang.org)
[](https://www.jetbrains.com/lp/compose-multiplatform)
[](https://developer.android.com/about/versions/16)
[](https://ktor.io)
[](https://sqldelight.github.io/sqldelight)
Community discussions on Slack — join us in the [#ktormonitor](https://kotlinlang.slack.com/archives/C0AB9GA32H0) channel.
Documentation is available at [KtorMonitor Documentation](https://cosminmihumdc.github.io/KtorMonitor).
API is available at [KtorMonitor API](https://cosminmihumdc.github.io/KtorMonitor/api).
KtorMonitor is available also on JetBrains' [klibs.io](https://klibs.io/project/CosminMihuMDC/KtorMonitor).
Some parts of this project are reusing ideas that are originally coming from [Chucker](https://github.com/ChuckerTeam/chucker).
Thanks to ChuckerTeam for Chucker!
Thanks to JetBrains for Ktor and Kotlin!
## 💸 Sponsors
KtorMonitor is maintained and improved during nights, weekends and whenever team has free time. If you use KtorMonitor in your project, please consider sponsoring us.
You can sponsor us by clicking [♥ Sponsor](https://github.com/sponsors/CosminMihuMDC).

## 🙏🏻 Credits
KtorMonitor is brought to you by these [contributors](https://github.com/CosminMihuMDC/KtorMonitor/graphs/contributors).