Skip to content

Commit

Permalink
Merge pull request #37 from ShreyashKore/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ShreyashKore authored Oct 24, 2024
2 parents 3201d9d + 77f2888 commit 14f94a9
Show file tree
Hide file tree
Showing 38 changed files with 2,659 additions and 255 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ This is used to determine the location to store the database file.
import data.db.setApplicationId

fun main() {
setApplicationId("com.example.myapp")
// ...
setApplicationId("com.example.myapp")
// ...
}
```

Expand All @@ -80,10 +80,10 @@ You can customize Inspektor using the `InspektorConfig` object. Here are the ava

```kotlin
install(Inspektor) {
level = LogLevel.HEADERS
maxContentLength = 100_000
filter { request -> request.url.host.contains("example.com") }
sanitizeHeader { header -> header == "Authorization" }
level = LogLevel.HEADERS
maxContentLength = 100_000
filter { request -> request.url.host.contains("example.com") }
sanitizeHeader { header -> header == "Authorization" }
}
```

Expand Down
10 changes: 6 additions & 4 deletions data/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
Expand All @@ -6,10 +9,9 @@ plugins {

kotlin {
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import kotlin.collections.Set;
import kotlin.String;
import kotlinx.datetime.Instant;

PRAGMA user_version = 1;
PRAGMA user_version = 3;

CREATE TABLE IF NOT EXISTS HttpTransaction (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
Expand Down Expand Up @@ -34,7 +34,12 @@ CREATE TABLE IF NOT EXISTS HttpTransaction (
responseHeaders TEXT AS Set<Map.Entry<String, List<String>>>,
responseHeadersSize INTEGER,
responseBody TEXT,
isResponseBodyEncoded INTEGER AS Boolean DEFAULT 0
isResponseBodyEncoded INTEGER AS Boolean DEFAULT 0,
originalRequestHeaders TEXT AS Set<Map.Entry<String, List<String>>>,
originalRequestBody TEXT,
originalResponseCode INTEGER,
originalResponseHeaders TEXT AS Set<Map.Entry<String, List<String>>>,
originalResponseBody TEXT
);

CREATE INDEX IF NOT EXISTS HttpTransaction_method ON HttpTransaction(method);
Expand Down Expand Up @@ -63,7 +68,9 @@ SELECT * FROM HttpTransaction WHERE requestDate BETWEEN :startDate AND :endDate

getAllLatestWithLimit:
SELECT id, requestDate, tookMs, protocol, method, host, path, scheme, responseCode,
requestPayloadSize, responsePayloadSize, error FROM HttpTransaction WHERE requestDate BETWEEN :startDate AND :endDate AND
requestPayloadSize, responsePayloadSize, error, CASE WHEN originalResponseBody IS NULL
AND originalResponseHeaders IS NULL AND originalResponseBody IS NULL AND originalResponseHeaders IS NULL
THEN 0 ELSE 1 END AS isOverriddenNum FROM HttpTransaction WHERE requestDate BETWEEN :startDate AND :endDate AND
(responseCode LIKE :codeQuery AND path LIKE :pathQuery) ORDER BY requestDate DESC;

insert:
Expand All @@ -82,17 +89,21 @@ INSERT INTO HttpTransaction(
requestPayloadSize,
requestContentType,
requestHeaders,
originalRequestHeaders,
requestHeadersSize,
requestBody,
originalRequestBody,
isRequestBodyEncoded,
responseCode,
responseMessage,
error,
responsePayloadSize,
responseContentType,
responseHeaders,
originalResponseHeaders,
responseHeadersSize,
responseBody,
originalResponseBody,
isResponseBodyEncoded
)
VALUES ?;
Expand All @@ -114,17 +125,21 @@ INSERT OR REPLACE INTO HttpTransaction(
requestPayloadSize,
requestContentType,
requestHeaders,
originalRequestHeaders,
requestHeadersSize,
requestBody,
originalRequestBody,
isRequestBodyEncoded,
responseCode,
responseMessage,
error,
responsePayloadSize,
responseContentType,
responseHeaders,
originalResponseHeaders,
responseHeadersSize,
responseBody,
originalResponseBody,
isResponseBodyEncoded
)
VALUES ?;
Expand All @@ -147,10 +162,12 @@ SET responseCode = ?,
responsePayloadSize = ?,
responseContentType = ?,
responseHeaders = ?,
originalResponseHeaders = ?,
responseHeadersSize = ?,
responseTlsVersion = ?,
responseCipherSuite = ?,
responseBody = ?,
originalResponseBody = ?,
isResponseBodyEncoded = ?
WHERE id = :id;

Expand Down
5 changes: 5 additions & 0 deletions data/src/commonMain/sqldelight/migrations/1.sqm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE HttpTransaction ADD COLUMN originalRequestHeaders TEXT;
ALTER TABLE HttpTransaction ADD COLUMN originalRequestBody TEXT;
ALTER TABLE HttpTransaction ADD COLUMN originalResponseCode INTEGER;
ALTER TABLE HttpTransaction ADD COLUMN originalResponseHeaders TEXT;
ALTER TABLE HttpTransaction ADD COLUMN originalResponseBody TEXT;
6 changes: 4 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ startupRuntime = "1.2.0"
lifecycle = "2.8.2"
androidx-navigation = "2.8.0-alpha10"
jsontree = "2.3.0"

kstore = "0.8.0"

[libraries]
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
Expand Down Expand Up @@ -62,7 +62,9 @@ sqlDelight-driver-android = { module = "app.cash.sqldelight:android-driver", ver
sqlDelight-driver-native = { module = "app.cash.sqldelight:native-driver", version.ref = "sqlDelight" }
sqlDelight-driver-js = { module = "app.cash.sqldelight:web-worker-driver", version.ref = "sqlDelight" }
sqlDelight-coroutines-extensions = { module = "app.cash.sqldelight:coroutines-extensions", version.ref = "sqlDelightCoroutinesExtensions" }
multiplatformSettings = { module = "com.russhwolf:multiplatform-settings", version.ref = "multiplatformSettings" }
multiplatformSettings = { module = "com.russhwolf:multiplatform-settings-no-arg", version.ref = "multiplatformSettings" }
kstore = { module = "io.github.xxfast:kstore", version.ref = "kstore" }
kstore-file = { module = "io.github.xxfast:kstore-file", version.ref = "kstore" }
jsontree = { module = "com.sebastianneubauer.jsontree:jsontree", version.ref = "jsontree" }

[plugins]
Expand Down
2 changes: 2 additions & 0 deletions inspektor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ kotlin {
implementation(libs.multiplatformSettings)
implementation(libs.ktor.client.logging)
implementation(libs.jsontree)
implementation(libs.kstore)
implementation(libs.kstore.file)
implementation(project(":data"))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.gyanoba.inspektor.platform

import com.gyanoba.inspektor.utils.ContextInitializer.Companion.appContext

internal actual fun getAppDataDir(): String {
return appContext.dataDir.absolutePath
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.gyanoba.inspektor.platform

import platform.Foundation.NSDocumentDirectory
import platform.Foundation.NSSearchPathForDirectoriesInDomains
import platform.Foundation.NSUserDomainMask

internal actual fun getAppDataDir(): String {
return NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory,
NSUserDomainMask,
true,
).first() as String
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ internal class HttpClientCallLogger(
private val requestLogged = atomic(false)
private val responseLogged = atomic(false)

fun addOriginalRequest(
headers: Set<Map.Entry<String, List<String>>>,
body: String?,
) {
transactionLog.apply {
this.originalRequestHeaders = headers
this.originalRequestBody = body
}
}

fun addRequestInfo(
url: String,
host: String?,
Expand Down Expand Up @@ -64,6 +74,16 @@ internal class HttpClientCallLogger(
transactionLog.error = exception.toString()
}

fun addOriginalResponse(
headers: Set<Map.Entry<String, List<String>>>,
body: String?,
) {
transactionLog.apply {
this.originalResponseHeaders = headers
this.originalResponseBody = body
}
}

fun addResponseInfo(
protocol: String?,
responseCode: Int?,
Expand Down
Loading

0 comments on commit 14f94a9

Please sign in to comment.