Skip to content

Mark TelemetryProvider API experimental #885

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

Merged
merged 1 commit into from
Jul 7, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package aws.smithy.kotlin.runtime.telemetry

import aws.smithy.kotlin.runtime.ExperimentalApi
import aws.smithy.kotlin.runtime.telemetry.context.Context
import aws.smithy.kotlin.runtime.telemetry.context.ContextManager
import aws.smithy.kotlin.runtime.telemetry.logging.LoggerProvider
Expand All @@ -25,24 +26,29 @@ public interface TelemetryProvider {
/**
* Get the [TracerProvider] used to create new [aws.smithy.kotlin.runtime.telemetry.trace.Tracer] instances
*/
@ExperimentalApi
public val tracerProvider: TracerProvider

/**
* Get the [MeterProvider] used to create new [aws.smithy.kotlin.runtime.telemetry.metrics.Meter] instances
*/
@ExperimentalApi
public val meterProvider: MeterProvider

/**
* Get the [LoggerProvider] used to create new [aws.smithy.kotlin.runtime.telemetry.logging.Logger] instances
*/
@ExperimentalApi
public val loggerProvider: LoggerProvider

/**
* Get the [ContextManager] used to get the current [Context]
*/
@ExperimentalApi
public val contextManager: ContextManager
}

@OptIn(ExperimentalApi::class)
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Shouldn't we opt into this annotation globally the way we do with @InternalApi?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decided not to because I wanted to see how far reaching the API becomes. Turns out there weren't that many places that need it.

private object NoOpTelemetryProvider : TelemetryProvider {
override val meterProvider: MeterProvider = MeterProvider.None
override val tracerProvider: TracerProvider = TracerProvider.None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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

import aws.smithy.kotlin.runtime.ExperimentalApi
import aws.smithy.kotlin.runtime.InternalApi
import aws.smithy.kotlin.runtime.telemetry.context.Context
import aws.smithy.kotlin.runtime.telemetry.context.telemetryContext
Expand Down Expand Up @@ -61,6 +62,7 @@ public suspend inline fun<R> withLogCtx(
* @param content A lambda which provides the content of the message. This content does not need to include any data
* from the exception (if any), which may be concatenated later based on probe behavior.
*/
@OptIn(ExperimentalApi::class)
@InternalApi
public fun CoroutineContext.log(
level: LogLevel,
Expand Down Expand Up @@ -213,6 +215,7 @@ public inline fun <reified T> CoroutineContext.trace(ex: Throwable? = null, noin
* Get a [Logger] instance using the current [LoggerProvider] configured in this [CoroutineContext]
* @param sourceComponent The name of the component to create a logger for
*/
@OptIn(ExperimentalApi::class)
@InternalApi
public fun CoroutineContext.logger(sourceComponent: String): Logger {
val logger = this.telemetryProvider.loggerProvider.getOrCreateLogger(sourceComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package aws.smithy.kotlin.runtime.telemetry.trace

import aws.smithy.kotlin.runtime.ExperimentalApi
import aws.smithy.kotlin.runtime.InternalApi
import aws.smithy.kotlin.runtime.telemetry.TelemetryProviderContext
import aws.smithy.kotlin.runtime.telemetry.context.TelemetryContextElement
Expand Down Expand Up @@ -59,6 +60,7 @@ public suspend inline fun <R> Tracer.withSpan(
* Executes [block] within the scope of [TraceSpan]. The [block] of code is executed
* with a new coroutine context that contains the [span] set in the context.
*/
@OptIn(ExperimentalApi::class)
@InternalApi
public suspend inline fun <R> withSpan(
span: TraceSpan,
Expand Down Expand Up @@ -107,6 +109,7 @@ public suspend inline fun <reified T, R> withSpan(
* within the scope of the new span. The [block] of code is executed with a new coroutine
* context that contains the newly created span set.
*/
@OptIn(ExperimentalApi::class)
@InternalApi
public suspend inline fun <R> withSpan(
sourceComponent: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package aws.smithy.kotlin.runtime.telemetry

import aws.smithy.kotlin.runtime.ExperimentalApi
import aws.smithy.kotlin.runtime.telemetry.context.ContextManager
import aws.smithy.kotlin.runtime.telemetry.logging.DefaultLoggerProvider
import aws.smithy.kotlin.runtime.telemetry.logging.LoggerProvider
Expand All @@ -15,6 +16,7 @@ import aws.smithy.kotlin.runtime.telemetry.trace.TracerProvider
* A telemetry provider that uses the default logger for a platform if one exists (e.g. SLF4J on JVM) and
* is a no-op for other telemetry signals.
*/
@OptIn(ExperimentalApi::class)
public object DefaultTelemetryProvider : TelemetryProvider {
override val loggerProvider: LoggerProvider = DefaultLoggerProvider
override val tracerProvider: TracerProvider = TracerProvider.None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package aws.smithy.kotlin.runtime.http.engine.okhttp

import aws.smithy.kotlin.runtime.ExperimentalApi
import aws.smithy.kotlin.runtime.http.engine.internal.HttpClientMetrics
import aws.smithy.kotlin.runtime.net.HostResolver
import aws.smithy.kotlin.runtime.net.toHostAddress
Expand All @@ -29,7 +30,7 @@ import kotlin.time.TimeSource
internal const val TELEMETRY_SCOPE = "aws.smithy.kotlin.runtime.http.engine.okhttp"

// see https://square.github.io/okhttp/features/events/#eventlistener for example callback flow
@OptIn(ExperimentalTime::class)
@OptIn(ExperimentalTime::class, ExperimentalApi::class)
internal class HttpEngineEventListener(
private val pool: ConnectionPool,
private val hr: HostResolver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package aws.smithy.kotlin.runtime.http.engine.internal

import aws.smithy.kotlin.runtime.ExperimentalApi
import aws.smithy.kotlin.runtime.InternalApi
import aws.smithy.kotlin.runtime.io.Closeable
import aws.smithy.kotlin.runtime.telemetry.TelemetryProvider
Expand Down Expand Up @@ -33,6 +34,7 @@ public object HttpClientMetricAttributes {
* @param scope the instrumentation scope
* @param provider the telemetry provider to instrument with
*/
@OptIn(ExperimentalApi::class)
@InternalApi
public class HttpClientMetrics(
scope: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package aws.smithy.kotlin.runtime.http.interceptors

import aws.smithy.kotlin.runtime.ExperimentalApi
import aws.smithy.kotlin.runtime.client.ProtocolRequestInterceptorContext
import aws.smithy.kotlin.runtime.client.ProtocolResponseInterceptorContext
import aws.smithy.kotlin.runtime.client.RequestInterceptorContext
Expand All @@ -27,7 +28,7 @@ import kotlin.time.TimeSource
* @param operation the name of the operation
* @param timeSource the time source to use for measuring elapsed time
*/
@OptIn(ExperimentalTime::class)
@OptIn(ExperimentalTime::class, ExperimentalApi::class)
internal class OperationTelemetryInterceptor(
private val metrics: OperationMetrics,
private val service: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package aws.smithy.kotlin.runtime.http.operation

import aws.smithy.kotlin.runtime.ExperimentalApi
import aws.smithy.kotlin.runtime.InternalApi
import aws.smithy.kotlin.runtime.telemetry.TelemetryProvider
import aws.smithy.kotlin.runtime.telemetry.metrics.DoubleHistogram
Expand All @@ -16,6 +17,7 @@ import aws.smithy.kotlin.runtime.telemetry.metrics.MonotonicCounter
* @param scope the instrumentation scope
* @param provider the telemetry provider to instrument with
*/
@OptIn(ExperimentalApi::class)
@InternalApi
public class OperationMetrics(
scope: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package aws.smithy.kotlin.runtime.http.operation

import aws.smithy.kotlin.runtime.ExperimentalApi
import aws.smithy.kotlin.runtime.InternalApi
import aws.smithy.kotlin.runtime.client.*
import aws.smithy.kotlin.runtime.http.interceptors.OperationTelemetryInterceptor
Expand Down Expand Up @@ -51,7 +52,7 @@ public inline fun<I, O> SdkHttpOperationBuilder<I, O>.telemetry(block: SdkOperat
* @return the span for the operation and the additional coroutine context to execute the operation with containing
* telemetry elements.
*/
@OptIn(ExperimentalTime::class)
@OptIn(ExperimentalTime::class, ExperimentalApi::class)
internal fun<I, O> SdkHttpOperation<I, O>.instrument(): Pair<TraceSpan, CoroutineContext> {
val serviceName = checkNotNull(context.serviceName)
val opName = checkNotNull(context.operationName)
Expand Down