Skip to content

Commit

Permalink
feat: when showDebugLogs is true, include client http logs in the trace
Browse files Browse the repository at this point in the history
  • Loading branch information
kkostov committed Dec 3, 2024
1 parent 2968c84 commit 346c48c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The Kotlin SDK for TelemetryDeck is available from Maven Central and can be used

```groovy
dependencies {
implementation 'com.telemetrydeck:kotlin-sdk:3.0.1'
implementation 'com.telemetrydeck:kotlin-sdk:3.0.3'
}
```

Expand Down
8 changes: 1 addition & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ lifecycleRuntimeKtx = "2.8.6"
activityCompose = "1.9.3"
composeBom = "2024.10.00"
ktor = "3.0.0"
logback = "1.5.6"
kotlinx = "1.7.3"
coroutines = "1.9.0"
vanniktech-publish = "0.30.0"
Expand All @@ -25,22 +24,17 @@ androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-lifecycle-process = { group = "androidx.lifecycle", name = "lifecycle-process", version.ref = "lifecycleRuntimeKtx" }
androidx-lifecycle-extensions = { group = "androidx.lifecycle", name = "lifecycle-extensions", version.ref = "lifecycleRuntimeKtx" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
androidx-arch-core = {group = "androidx.arch.core", name = "core-testing", version = "2.2.0" }
ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktor" }
ktor-client-okhttp = { group = "io.ktor", name = "ktor-client-okhttp", version.ref = "ktor" }
ktor-client-logging = { group = "io.ktor", name = "ktor-client-logging", version.ref = "ktor" }
ktor-content-negotiation = { group = "io.ktor", name = "ktor-client-content-negotiation", version.ref = "ktor" }
ktor-serialization-kotlinx-json = { group = "io.ktor", name = "ktor-serialization-kotlinx-json", version.ref = "ktor" }
logback = { group = "ch.qos.logback", name = "logback-classic", version.ref = "logback" }
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinx" }
kotlinx-serialization-properties = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-properties", version.ref = "kotlinx" }
kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines" }
Expand Down
3 changes: 2 additions & 1 deletion lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ dependencies {
implementation(libs.ktor.client.okhttp)
implementation(libs.kotlinx.serialization.json)
implementation(libs.kotlinx.serialization.properties)
implementation(libs.ktor.client.logging)


testImplementation(libs.junit)
Expand All @@ -100,7 +101,7 @@ dependencies {
}

mavenPublishing {
coordinates("com.telemetrydeck", "kotlin-sdk", "3.0.2")
coordinates("com.telemetrydeck", "kotlin-sdk", "3.0.3")

pom {
name = "TelemetryDeck SDK"
Expand Down
15 changes: 14 additions & 1 deletion lib/src/main/java/com/telemetrydeck/sdk/TelemetryClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import io.ktor.client.HttpClient
import io.ktor.client.engine.okhttp.OkHttp
import io.ktor.client.plugins.DefaultRequest
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.plugins.logging.LogLevel
import io.ktor.client.plugins.logging.Logger
import io.ktor.client.plugins.logging.Logging
import io.ktor.client.request.header
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.serialization.kotlinx.json.json
import java.net.URL
import java.util.UUID

/**
* The HTTP client to communicate with TelemetryDeck's API
Expand All @@ -25,6 +27,17 @@ internal class TelemetryClient(
install(ContentNegotiation) {
json()
}
if (showDebugLogs && debugLogger != null) {
install(Logging) {
logger = object : Logger {
override fun log(message: String) {
debugLogger.debug(message)
}
}
level = LogLevel.ALL // Log request, response, headers, and body
}
}

install(DefaultRequest) {
header(HttpHeaders.ContentType, ContentType.Application.Json)
header(HttpHeaders.Accept, ContentType.Application.Json)
Expand Down

0 comments on commit 346c48c

Please sign in to comment.