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
2 changes: 1 addition & 1 deletion runtime/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ subprojects {
}
}

named("jvmTest") {
findByName("jvmTest")?.run {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this change was necessary because the new logging-crt module does not have a JVM source set, causing errors like "jvmTest does not exist"

dependencies {
implementation(libraries.kotlinx.coroutines.debug)
implementation(libraries.kotest.assertions.core.jvm)
Expand Down
18 changes: 18 additions & 0 deletions runtime/observability/logging-crt/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
description = "Logging provider based on CRT"
extra["displayName"] = "Smithy :: Kotlin :: Observability :: CRT"
extra["moduleName"] = "aws.smithy.kotlin.runtime.telemetry.logging.crt"

kotlin {
sourceSets {
nativeMain {
dependencies {
api(project(":runtime:observability:telemetry-api"))
api(libs.crt.kotlin)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package aws.smithy.kotlin.runtime.telemetry.logging.crt

import aws.smithy.kotlin.runtime.telemetry.logging.LogLevel
import aws.smithy.kotlin.runtime.telemetry.logging.LogRecordBuilder
import aws.smithy.kotlin.runtime.telemetry.logging.MessageSupplier

public class CrtLogRecordBuilder(
private val delegate: CrtLogger,
private val level: LogLevel,
) : LogRecordBuilder {
private var cause: Throwable? = null
private var msg: (() -> String)? = null

override fun setCause(ex: Throwable) {
cause = ex
}

override fun setMessage(message: String) {
msg = { message }
}

override fun setMessage(message: MessageSupplier) {
msg = message
}

// CRT logger does not support setting key-value pairs
override fun setKeyValuePair(key: String, value: Any) { }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Is this not supported yet or are there no plans to support it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No plans to support it


override fun emit() {
val message = requireNotNull(msg) { "no message provided to LogRecordBuilder" }

val logMethod = when (level) {
LogLevel.Trace -> delegate::trace
LogLevel.Debug -> delegate::debug
LogLevel.Info -> delegate::info
LogLevel.Warning -> delegate::warn
LogLevel.Error -> delegate::error
}

logMethod(cause, message)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package aws.smithy.kotlin.runtime.telemetry.logging.crt

import aws.sdk.kotlin.crt.WithCrt
import aws.sdk.kotlin.crt.log
import aws.smithy.kotlin.runtime.telemetry.logging.LogLevel
import aws.smithy.kotlin.runtime.telemetry.logging.LogRecordBuilder
import aws.smithy.kotlin.runtime.telemetry.logging.Logger
import aws.smithy.kotlin.runtime.telemetry.logging.MessageSupplier
import aws.sdk.kotlin.crt.Config as CrtConfig
import aws.sdk.kotlin.crt.LogLevel as CrtLogLevel

public class CrtLogger(public val name: String, public val config: CrtConfig) :
WithCrt(),
Logger {
override fun trace(t: Throwable?, msg: MessageSupplier): Unit = log(CrtLogLevel.Trace, msg())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Can we pass in the t to the crt log function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we can't. This is invoking a CRT function AWS_LOGF which has no concept of exceptions / throwables

override fun debug(t: Throwable?, msg: MessageSupplier): Unit = log(CrtLogLevel.Debug, msg())
override fun info(t: Throwable?, msg: MessageSupplier): Unit = log(CrtLogLevel.Info, msg())
override fun warn(t: Throwable?, msg: MessageSupplier): Unit = log(CrtLogLevel.Warn, msg())
override fun error(t: Throwable?, msg: MessageSupplier): Unit = log(CrtLogLevel.Error, msg())
override fun isEnabledFor(level: LogLevel): Boolean = config.logLevel.ordinal >= level.ordinal
override fun atLevel(level: LogLevel): LogRecordBuilder = CrtLogRecordBuilder(this, level)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package aws.smithy.kotlin.runtime.telemetry.logging.crt

import aws.smithy.kotlin.runtime.telemetry.logging.*
import aws.sdk.kotlin.crt.Config as CrtConfig

public class CrtLoggerProvider : LoggerProvider {
override fun getOrCreateLogger(name: String): Logger = CrtLogger(name, CrtConfig())
public fun getOrCreateLogger(name: String, config: CrtConfig): Logger = CrtLogger(name, config)
}
2 changes: 1 addition & 1 deletion runtime/observability/logging-slf4j2/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
description = "Logging provider based on SLF4J"
extra["displayName"] = "Smithy :: Kotlin :: Observability :: SLF4J binding"
extra["moduleName"] = "aws.smithy.kotlin.runtime.telemetry"
extra["moduleName"] = "aws.smithy.kotlin.runtime.telemetry.slf4j"

kotlin {
sourceSets {
Expand Down
6 changes: 6 additions & 0 deletions runtime/observability/telemetry-defaults/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ kotlin {
}
}

nativeMain {
dependencies {
implementation(project(":runtime:observability:logging-crt"))
}
}

all {
languageSettings.optIn("aws.smithy.kotlin.runtime.InternalApi")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

package aws.smithy.kotlin.runtime.telemetry.logging

internal actual val DefaultLoggerProvider: LoggerProvider = TODO("Not yet implemented")
import aws.smithy.kotlin.runtime.telemetry.logging.crt.CrtLoggerProvider

internal actual val DefaultLoggerProvider: LoggerProvider = CrtLoggerProvider()
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,28 @@ kotlin {
implementation(project(":runtime:runtime-core"))
}
}

jvmMain {
dependencies {
// okhttp works on both JVM and Android
implementation(project(":runtime:protocol:http-client-engines:http-client-engine-okhttp"))
}
}

jvmTest {
dependencies {
implementation(project(":runtime:protocol:http-client-engines:http-client-engine-crt"))
}
}

all {
languageSettings.optIn("aws.smithy.kotlin.runtime.InternalApi")
}

nativeMain {
dependencies {
implementation(project(":runtime:protocol:http-client-engines:http-client-engine-crt"))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@

package aws.smithy.kotlin.runtime.http.engine

internal actual fun newDefaultHttpEngine(block: (HttpClientEngineConfig.Builder.() -> Unit)?): CloseableHttpClientEngine =
TODO("Not yet implemented")
import aws.smithy.kotlin.runtime.http.engine.crt.CrtHttpEngine

internal actual fun newDefaultHttpEngine(block: (HttpClientEngineConfig.Builder.() -> Unit)?): CloseableHttpClientEngine = CrtHttpEngine()
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ include(":runtime:auth:http-auth-api")
include(":runtime:auth:http-auth-aws")
include(":runtime:auth:identity-api")
include(":runtime:crt-util")
include(":runtime:observability:logging-crt")
include(":runtime:observability:logging-slf4j2")
include(":runtime:observability:telemetry-api")
include(":runtime:observability:telemetry-defaults")
Expand Down
Loading