Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 12 additions & 107 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,116 +11,21 @@ env:
GRADLE_OPTS: "-Dorg.gradle.jvmargs=-Xmx4096M -Dorg.gradle.daemon=false -Dorg.gradle.parallel=true -Dorg.gradle.caching=true"

jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
build:
name: Build Library (Android + iOS)
runs-on: macOS-latest
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Run unit tests
run: ./gradlew jvmTest
- name: Set up JDK 21
uses: actions/setup-java@v5
with:
distribution: 'zulu'
java-version: 21

# - name: Upload test reports
# uses: actions/upload-artifact@v7
# with:
# name: test-reports
# path: "**/build/reports/tests/"
- name: Assemble library modules
run: ./gradlew assemble

build-android:
name: Build Android
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Build Android APKs
run: ./gradlew :sample:ktor:assembleDebug :sample:ktor:assembleRelease :sample:okhttp:assembleDebug :sample:okhttp:assembleRelease

# - name: Upload Android APKs
# uses: actions/upload-artifact@v7
# with:
# name: android-apks
# path: "**/build/outputs/apk/**/*.apk"

# build-ios:
# name: Build iOS simulator app
# runs-on: macos-latest
# needs: test
# steps:
# - name: Checkout
# uses: actions/checkout@v6
#
# - name: Build iOS simulator app
# run: |
# xcodebuild build \
# -project sample/ktor/iosApp/iosApp.xcodeproj \
# -configuration Debug \
# -scheme ios \
# -sdk iphonesimulator \
# -arch arm64 \
# -derivedDataPath ./build \
# -verbose

# - name: Upload App Folder
# uses: actions/upload-artifact@v7
# with:
# name: iphonesimulator-app
# path: build/Build/Products/Debug-iphonesimulator/*

build-desktop-macos:
name: Build Desktop macOS
runs-on: macos-latest
needs: test
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Build macOS DMGs
run: ./gradlew :sample:ktor:packageDmg :sample:okhttp:packageDmg

# - name: Upload macOS DMGs
# uses: actions/upload-artifact@v7
# with:
# name: desktop-macos-dmg
# path: "**/build/compose/binaries/main/dmg/*.dmg"

build-desktop-windows:
name: Build Desktop Windows
runs-on: windows-latest
needs: test
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v5.0.0

- name: Build Windows MSIs
run: ./gradlew :sample:ktor:packageMsi :sample:okhttp:packageMsi

# - name: Upload Windows MSIs
# uses: actions/upload-artifact@v7
# with:
# name: desktop-windows-msi
# path: "**/build/compose/binaries/main/msi/*.msi"

build-desktop-linux:
name: Build Desktop Linux
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Build Linux DEBs and RPMs
run: ./gradlew :sample:ktor:packageDeb :sample:ktor:packageRpm :sample:okhttp:packageDeb :sample:okhttp:packageRpm

# - name: Upload Linux DEBs and RPMs
# uses: actions/upload-artifact@v7
# with:
# name: desktop-linux-deb
# path: |
# **/build/compose/binaries/main/deb/*.deb
# **/build/compose/binaries/main/rpm/*.rpm
- name: Run API check
run: ./gradlew apiCheck
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ jobs:
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com

- name: Set up JDK 24
- name: Set up JDK 21
uses: actions/setup-java@v5
with:
distribution: 'zulu'
java-version: 24
java-version: 21

- name: Set up Python
uses: actions/setup-python@v6
Expand Down
56 changes: 19 additions & 37 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name: Publish to MavenCentral
name: Publish to GitHub Packages

on:
release:
types: [released, prereleased]
workflow_dispatch:

permissions:
contents: write
contents: read
packages: write

jobs:
check:
Expand All @@ -15,51 +17,31 @@ jobs:
- name: Checkout
uses: actions/checkout@v6

- name: Set up JDK 21
uses: actions/setup-java@v5
with:
distribution: 'zulu'
java-version: 21

- name: Run api check
run: ./gradlew apiCheck

docs:
name: Generate Docs
runs-on: macOS-latest
needs: check
steps:
- uses: actions/checkout@v6
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: actions/setup-python@v6
with:
python-version: 3.x
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v5
with:
key: mkdocs-material-${{ env.cache_id }}
path: ~/.cache
restore-keys: |
mkdocs-material-
- run: rm -rf docs/api
- run: ./gradlew clean dokkaGenerate
- run: pip install mkdocs-material
- run: mkdocs gh-deploy --force --config-file docs/mkdocs.yml

publish:
name: Release and Publish
name: Publish to GitHub Packages
runs-on: macOS-latest
needs: docs
needs: check
steps:
- name: Check out code
uses: actions/checkout@v6

- name: Set up JDK 21
uses: actions/setup-java@v5
with:
distribution: 'zulu'
java-version: 24
- name: Publish to MavenCentral
run: ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache
java-version: 21

- name: Publish to GitHub Packages
run: ./gradlew publishAllPublicationsToGitHubPackagesRepository --no-configuration-cache
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY_CONTENTS }}
USERNAME: ${{ github.actor }}
USER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99 changes: 28 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Maven Central](https://img.shields.io/maven-central/v/ro.cosminmihu.ktor/ktor-monitor-logging?logo=apachemaven&label=Maven%20Central&link=https://search.maven.org/artifact/ro.cosminmihu.ktor/ktor-monitor-logging/)](https://search.maven.org/artifact/ro.cosminmihu.ktor/ktor-monitor-logging)
[![GitHub Packages](https://img.shields.io/badge/GitHub%20Packages-robustrade%3Aktor--monitor-2088FF?logo=github&logoColor=white)](https://github.com/Robustrade/KtorMonitor/packages)
[![License](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?label=Licence&logo=lintcode&logoColor=white&color=#3DA639)](https://github.com/CosminMihuMDC/KtorMonitor/blob/main/LICENSE)
[![Platforms](https://img.shields.io/badge/Platforms-Android%20+%20iOS%20+%20JVM%20+%20Wasm%20+%20Js-brightgreen?logo=kotlin&logoColor=white&color=8d69e0)](https://cosminmihumdc.github.io/KtorMonitor)
[![Platforms](https://img.shields.io/badge/Platforms-Android%20+%20iOS-brightgreen?logo=kotlin&logoColor=white&color=8d69e0)](https://cosminmihumdc.github.io/KtorMonitor)
[![Slack](https://img.shields.io/badge/Slack-kotlinlang-4A164B?logo=sololearn&logoColor=white)](https://kotlinlang.slack.com/archives/C0AB9GA32H0)
[![JetBrains Klibs.io](https://img.shields.io/badge/JetBrains-klibs.io-4284F3?logo=jetbrains&logoColor=white)](https://klibs.io/project/CosminMihuMDC/KtorMonitor)
[![Documentation](https://img.shields.io/badge/Docs-gray?logo=readthedocs&logoColor=white)](https://cosminmihumdc.github.io/KtorMonitor)
Expand All @@ -26,6 +26,26 @@ Powerful tool to monitor [Ktor Client](https://ktor.io/), [OkHttp](https://squar
* 📡**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.

## 📦 Repository (GitHub Packages)

This fork is published to **GitHub Packages** under the `robustrade` group (not Maven Central).
Add the GitHub Packages repository — authenticated with a GitHub token that has `read:packages` —
to your `settings.gradle.kts`:

```kotlin
dependencyResolutionManagement {
repositories {
maven {
url = uri("https://maven.pkg.github.com/Robustrade/KtorMonitor")
credentials {
username = System.getenv("USERNAME")
password = System.getenv("USER_TOKEN")
}
}
}
}
```

## 📦 Setup (Kotlin Multiplatform) for [Ktor Client](https://ktor.io/)

### <img src="https://upload.wikimedia.org/wikipedia/commons/6/6b/Gradle_logo.svg" width="100"/>
Expand All @@ -34,7 +54,7 @@ Powerful tool to monitor [Ktor Client](https://ktor.io/), [OkHttp](https://squar
kotlin {
sourceSets {
commonMain.dependencies {
implementation("ro.cosminmihu.ktor:ktor-monitor-logging:1.13.0")
implementation("robustrade:ktor-monitor-logging:1.13.0")
}
}
}
Expand All @@ -48,7 +68,7 @@ To isolate KtorMonitor from release builds, use the `ktor-monitor-logging-no-op`
kotlin {
sourceSets {
commonMain.dependencies {
implementation("ro.cosminmihu.ktor:ktor-monitor-logging-no-op:1.13.0")
implementation("robustrade:ktor-monitor-logging-no-op:1.13.0")
}
}
}
Expand All @@ -60,8 +80,8 @@ kotlin {

```kotlin
dependencies {
debugImplementation("ro.cosminmihu.ktor:ktor-monitor-logging:1.13.0")
releaseImplementation("ro.cosminmihu.ktor:ktor-monitor-logging-no-op:1.13.0")
debugImplementation("robustrade:ktor-monitor-logging:1.13.0")
releaseImplementation("robustrade:ktor-monitor-logging-no-op:1.13.0")
}
```

Expand All @@ -88,71 +108,8 @@ HttpClient {
- ```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```.

## 📦 Setup (Android & JVM) for [OkHttp](https://square.github.io/okhttp/)

### <img src="https://upload.wikimedia.org/wikipedia/commons/6/6b/Gradle_logo.svg" width="100"/>

```kotlin
dependencies {
debugImplementation("`ro.cosminmihu.ktor:ktor-monitor-okhttp-interceptor:1.13.0")
releaseImplementation("ro.cosminmihu.ktor:ktor-monitor-okhttp-interceptor-no-op:1.13.0")
}
```

For ***Android minSdk < 26***, [Core Library Desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) is required.

### <img src="https://pw-renderer-production-c.squarecdn.com/6d6a21f1ace5b8a7c93127a6f77087418f6ac596/_svelte/favicon.ico" width="30" style="background:#eee;"/> Install OkHttp Interceptor

```kotlin
OkHttpClient.Builder()
.addNetworkInterceptor(
KtorMonitorInterceptor {
sanitizeHeader { header -> header == "Authorization" }
filter { request -> !request.url.host.contains("cosminmihu.ro") }
showNotification = true
retentionPeriod = RetentionPeriod.OneHour
maxContentLength = ContentLength.Default
}
)
.build()
```

- ```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```.

## 📦 Setup (Android & JVM) for [http4k](https://www.http4k.org/)

### <img src="https://upload.wikimedia.org/wikipedia/commons/6/6b/Gradle_logo.svg" width="100"/>

```kotlin
dependencies {
debugImplementation("ro.cosminmihu.ktor:ktor-monitor-http4k-filter:1.13.0")
releaseImplementation("ro.cosminmihu.ktor:ktor-monitor-http4k-filter-no-op:1.13.0")
}
```

For ***Android minSdk < 26***, [Core Library Desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) is required.

### <img src="https://images.opencollective.com/http4k/4b91f7a/logo/256.png" width="30" style="background:#eee;"/> Install http4k Filter

```kotlin
KtorMonitorFilter {
sanitizeHeader { header -> header == "Authorization" }
filter { request -> !request.uri.host.contains("cosminmihu.ro") }
showNotification = true
retentionPeriod = RetentionPeriod.OneHour
maxContentLength = ContentLength.Default
}.then(JavaHttpClient())
```

- ```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 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```.
> **Note:** This fork targets **Android + iOS only** for consumption by `kulu-kmp`. The upstream
> OkHttp and http4k integrations are not published here.

## 🧩 Integration

Expand Down
Loading