-
Notifications
You must be signed in to change notification settings - Fork 31
kn: observability #1234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kn: observability #1234
Changes from all commits
2ab88ac
cec0017
ea260c1
2cf1bfb
99c3e73
3840aff
612cbd7
fe0d0d3
027584f
776fe9a
7dbdbdb
bbb78fb
ae75af8
92c509a
8712d52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) { } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: Can we pass in the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we can't. This is invoking a CRT function |
||
| 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) | ||
| } |
There was a problem hiding this comment.
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-crtmodule does not have a JVM source set, causing errors like "jvmTest does not exist"