
Monitors network requests and responses, enhancing debugging and analysis of client-server interactions. Features include header sanitization, log retention, and content length management with platform-specific integrations.
Powerful tool to monitor Ktor Client requests and responses, making it easier to debug and analyze network communication.
By default, KtorMonitor:
debug builds and disabled for release buildsdebug builds and disabled for release buildskotlin {
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 {
sourceSets {
commonMain.dependencies {
implementation("ro.cosminmihu.ktor:ktor-monitor-logging-no-op:1.10.0")
}
}
}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 is required.
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 logsfilter - 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.Add the UI component to your application based on your targeted platform.
KtorMonitor Composable@Composable
fun Composable() {
KtorMonitor()
}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.KtorMonitor() Composable directly into own Composable code.If showNotifcation = true and notification permission is granted, the library will display a notification showing a summary of ongoing KTOR activity.
Use KtorMonitorViewController
fun MainViewController() = KtorMonitorViewController()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()
}
}KtorMonitorWindow Composablefun main() = application {
var showKtorMonitor by rememberSaveable { mutableStateOf(false) }
KtorMonitorWindow(
onCloseRequest = { showKtorMonitor = false },
show = showKtorMonitor
)
}KtorMonitorWindow Composable with KtorMonitorMenuItem
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 }
)
}KtorMonitorPanel Swing Panelfun main() = application {
SwingUtilities.invokeLater {
val frame = JFrame()
frame.add(KtorMonitorPanel, BorderLayout.CENTER)
frame.isVisible = true
}
}kotlin {
sourceSets {
webMain.dependencies {
implementation(devNpm("copy-webpack-plugin", "9.1.0"))
}
}
}// {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'
]
})
);ComposeViewport {
App()
}Found a bug or have a feature request? File an issue.
Community discussions on Slack β join us in the #ktormonitor channel.
Documentation is available at KtorMonitor Documentation.
API is available at KtorMonitor API.
KtorMonitor is available also on JetBrains' klibs.io.
Some parts of this project are reusing ideas that are originally coming from Chucker.
Thanks to ChuckerTeam for Chucker!
Thanks to JetBrains for Ktor and Kotlin!
Medium article: Ktor Monitor
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.
KtorMonitor is brought to you by these contributors.
Powerful tool to monitor Ktor Client requests and responses, making it easier to debug and analyze network communication.
By default, KtorMonitor:
debug builds and disabled for release buildsdebug builds and disabled for release buildskotlin {
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 {
sourceSets {
commonMain.dependencies {
implementation("ro.cosminmihu.ktor:ktor-monitor-logging-no-op:1.10.0")
}
}
}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 is required.
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 logsfilter - 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.Add the UI component to your application based on your targeted platform.
KtorMonitor Composable@Composable
fun Composable() {
KtorMonitor()
}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.KtorMonitor() Composable directly into own Composable code.If showNotifcation = true and notification permission is granted, the library will display a notification showing a summary of ongoing KTOR activity.
Use KtorMonitorViewController
fun MainViewController() = KtorMonitorViewController()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()
}
}KtorMonitorWindow Composablefun main() = application {
var showKtorMonitor by rememberSaveable { mutableStateOf(false) }
KtorMonitorWindow(
onCloseRequest = { showKtorMonitor = false },
show = showKtorMonitor
)
}KtorMonitorWindow Composable with KtorMonitorMenuItem
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 }
)
}KtorMonitorPanel Swing Panelfun main() = application {
SwingUtilities.invokeLater {
val frame = JFrame()
frame.add(KtorMonitorPanel, BorderLayout.CENTER)
frame.isVisible = true
}
}kotlin {
sourceSets {
webMain.dependencies {
implementation(devNpm("copy-webpack-plugin", "9.1.0"))
}
}
}// {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'
]
})
);ComposeViewport {
App()
}Found a bug or have a feature request? File an issue.
Community discussions on Slack β join us in the #ktormonitor channel.
Documentation is available at KtorMonitor Documentation.
API is available at KtorMonitor API.
KtorMonitor is available also on JetBrains' klibs.io.
Some parts of this project are reusing ideas that are originally coming from Chucker.
Thanks to ChuckerTeam for Chucker!
Thanks to JetBrains for Ktor and Kotlin!
Medium article: Ktor Monitor
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.
KtorMonitor is brought to you by these contributors.