Skip to content

Commit e2d70b0

Browse files
committed
wip: tearing apart Telemetry APIs
1 parent c15a988 commit e2d70b0

File tree

14 files changed

+143
-75
lines changed

14 files changed

+143
-75
lines changed

runtime/observability/telemetry-api/api/telemetry-api.api

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public abstract class aws/smithy/kotlin/runtime/telemetry/context/AbstractContex
5353

5454
public abstract class aws/smithy/kotlin/runtime/telemetry/context/AbstractContextManager : aws/smithy/kotlin/runtime/telemetry/context/ContextManager {
5555
public fun <init> ()V
56-
public fun current ()Laws/smithy/kotlin/runtime/telemetry/context/Context;
56+
public fun current (Lkotlin/coroutines/CoroutineContext;)Laws/smithy/kotlin/runtime/telemetry/context/Context;
5757
}
5858

5959
public abstract class aws/smithy/kotlin/runtime/telemetry/context/AbstractScope : aws/smithy/kotlin/runtime/telemetry/context/Scope {
@@ -72,7 +72,7 @@ public final class aws/smithy/kotlin/runtime/telemetry/context/Context$Companion
7272

7373
public abstract interface class aws/smithy/kotlin/runtime/telemetry/context/ContextManager {
7474
public static final field Companion Laws/smithy/kotlin/runtime/telemetry/context/ContextManager$Companion;
75-
public abstract fun current ()Laws/smithy/kotlin/runtime/telemetry/context/Context;
75+
public abstract fun current (Lkotlin/coroutines/CoroutineContext;)Laws/smithy/kotlin/runtime/telemetry/context/Context;
7676
}
7777

7878
public final class aws/smithy/kotlin/runtime/telemetry/context/ContextManager$Companion {

runtime/observability/telemetry-api/common/src/aws/smithy/kotlin/runtime/telemetry/context/AbstractContextManager.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
*/
55
package aws.smithy.kotlin.runtime.telemetry.context
66

7+
import kotlin.coroutines.CoroutineContext
8+
79
/**
810
* An abstract implementation of a context manager. By default, this class uses no-op implementations for all members
911
* unless overridden in a subclass.
1012
*/
1113
public abstract class AbstractContextManager : ContextManager {
12-
override fun current(): Context = Context.None
14+
override fun current(ctx: CoroutineContext): Context = Context.None
1315
}

runtime/observability/telemetry-api/common/src/aws/smithy/kotlin/runtime/telemetry/context/ContextManager.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package aws.smithy.kotlin.runtime.telemetry.context
77

8+
import kotlin.coroutines.CoroutineContext
9+
810
/**
911
* Responsible for managing the current context with callers current execution unit. For example, some implementations
1012
* use Thread Local storage for managing the current context.
@@ -20,5 +22,5 @@ public interface ContextManager {
2022
/**
2123
* Return the current [Context]
2224
*/
23-
public fun current(): Context
25+
public fun current(ctx: CoroutineContext): Context
2426
}

runtime/observability/telemetry-api/common/src/aws/smithy/kotlin/runtime/telemetry/trace/CoroutineContextTraceExt.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import aws.smithy.kotlin.runtime.ExperimentalApi
99
import aws.smithy.kotlin.runtime.InternalApi
1010
import aws.smithy.kotlin.runtime.collections.Attributes
1111
import aws.smithy.kotlin.runtime.collections.emptyAttributes
12+
import aws.smithy.kotlin.runtime.operation.ExecutionContext
1213
import aws.smithy.kotlin.runtime.telemetry.TelemetryProviderContext
1314
import aws.smithy.kotlin.runtime.telemetry.context.TelemetryContextElement
1415
import aws.smithy.kotlin.runtime.telemetry.context.telemetryContext
@@ -69,7 +70,7 @@ public suspend inline fun <R> withSpan(
6970
): R = try {
7071
// after a span is created the current telemetry context may be updated, ensure the new coroutine gets the latest
7172
// or else traces may be disconnected from their parent
72-
val updatedCtx = coroutineContext[TelemetryProviderContext]?.provider?.contextManager?.current()
73+
val updatedCtx = coroutineContext[TelemetryProviderContext]?.provider?.contextManager?.current(coroutineContext)
7374
val telemetryCtxElement = (updatedCtx?.let { TelemetryContextElement(it) } ?: coroutineContext[TelemetryContextElement]) ?: EmptyCoroutineContext
7475
withContext(context + TraceSpanContext(span) + telemetryCtxElement) {
7576
block(span)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
public final class aws/smithy/kotlin/runtime/telemetry/ism/IsmContextManager : aws/smithy/kotlin/runtime/telemetry/context/ContextManager {
2+
public static final field Companion Laws/smithy/kotlin/runtime/telemetry/ism/IsmContextManager$Companion;
3+
public fun current (Lkotlin/coroutines/CoroutineContext;)Laws/smithy/kotlin/runtime/telemetry/context/Context;
4+
}
5+
6+
public final class aws/smithy/kotlin/runtime/telemetry/ism/IsmContextManager$Companion {
7+
public final fun createWithScopeListener ()Lkotlin/Pair;
8+
}
9+
10+
public final class aws/smithy/kotlin/runtime/telemetry/ism/IsmMetricsProvider : aws/smithy/kotlin/runtime/telemetry/metrics/MeterProvider {
11+
public fun <init> (Laws/smithy/kotlin/runtime/telemetry/ism/OperationMetricsCollector;)V
12+
public fun getOrCreateMeter (Ljava/lang/String;)Laws/smithy/kotlin/runtime/telemetry/metrics/Meter;
13+
}
14+
15+
public final class aws/smithy/kotlin/runtime/telemetry/ism/IsmMetricsProviderKt {
16+
public static final fun MetricRecord (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;Laws/smithy/kotlin/runtime/collections/Attributes;Laws/smithy/kotlin/runtime/telemetry/context/Context;Laws/smithy/kotlin/runtime/time/Instant;)Laws/smithy/kotlin/runtime/telemetry/ism/MetricRecord;
17+
public static final fun OperationMetrics (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;)Laws/smithy/kotlin/runtime/telemetry/ism/OperationMetrics;
18+
public static final fun ScopeMetrics (Ljava/util/Map;Ljava/util/Map;)Laws/smithy/kotlin/runtime/telemetry/ism/ScopeMetrics;
19+
}
20+
21+
public abstract interface class aws/smithy/kotlin/runtime/telemetry/ism/MetricRecord {
22+
public abstract fun getAttributes ()Laws/smithy/kotlin/runtime/collections/Attributes;
23+
public abstract fun getContext ()Laws/smithy/kotlin/runtime/telemetry/context/Context;
24+
public abstract fun getDescription ()Ljava/lang/String;
25+
public abstract fun getName ()Ljava/lang/String;
26+
public abstract fun getTimestamp ()Laws/smithy/kotlin/runtime/time/Instant;
27+
public abstract fun getUnits ()Ljava/lang/String;
28+
public abstract fun getValue ()Ljava/lang/Object;
29+
}
30+
31+
public abstract interface class aws/smithy/kotlin/runtime/telemetry/ism/OperationMetrics : aws/smithy/kotlin/runtime/telemetry/ism/ScopeMetrics {
32+
public abstract fun getOperation ()Ljava/lang/String;
33+
public abstract fun getSdkInvocationId ()Ljava/lang/String;
34+
public abstract fun getService ()Ljava/lang/String;
35+
}
36+
37+
public abstract interface class aws/smithy/kotlin/runtime/telemetry/ism/OperationMetricsCollector {
38+
public abstract fun onOperationMetrics (Laws/smithy/kotlin/runtime/telemetry/ism/OperationMetrics;)V
39+
}
40+
41+
public abstract interface class aws/smithy/kotlin/runtime/telemetry/ism/ScopeMetrics {
42+
public abstract fun getChildScopes ()Ljava/util/Map;
43+
public abstract fun getRecords ()Ljava/util/Map;
44+
}
45+
46+
public abstract interface class aws/smithy/kotlin/runtime/telemetry/ism/SpanListener {
47+
public abstract fun onCloseSpan (Laws/smithy/kotlin/runtime/telemetry/context/Context;)V
48+
public abstract fun onNewSpan (Laws/smithy/kotlin/runtime/telemetry/context/Context;Ljava/lang/String;Laws/smithy/kotlin/runtime/collections/Attributes;)Laws/smithy/kotlin/runtime/telemetry/context/Context;
49+
}
50+
Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,21 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
package aws.smithy.kotlin.runtime.telemetry.ism.context
5+
package aws.smithy.kotlin.runtime.telemetry.ism
66

77
import aws.smithy.kotlin.runtime.collections.Attributes
88
import aws.smithy.kotlin.runtime.http.operation.OperationAttributes
99
import aws.smithy.kotlin.runtime.telemetry.context.Context
1010
import aws.smithy.kotlin.runtime.telemetry.context.ContextManager
1111
import aws.smithy.kotlin.runtime.telemetry.context.Scope
12-
import aws.smithy.kotlin.runtime.telemetry.ism.metrics.MetricRecord
13-
import aws.smithy.kotlin.runtime.telemetry.ism.metrics.ScopeMetrics
12+
import aws.smithy.kotlin.runtime.telemetry.context.telemetryContext
13+
import kotlin.coroutines.CoroutineContext
1414

1515
public interface SpanListener {
1616
public fun onNewSpan(parentContext: Context?, name: String, attributes: Attributes): Context
1717
public fun onCloseSpan(context: Context)
1818
}
1919

20-
internal interface ContextStorage {
21-
fun get(): Context
22-
fun getAndSet(value: Context): Context
23-
fun requireAndSet(expect: Context, update: Context)
24-
}
25-
26-
internal expect fun ContextStorage(initialContext: Context): ContextStorage
27-
2820
public class IsmContextManager private constructor() : ContextManager {
2921
public companion object {
3022
public fun createWithScopeListener(): Pair<IsmContextManager, SpanListener> {
@@ -40,9 +32,8 @@ public class IsmContextManager private constructor() : ContextManager {
4032
}
4133

4234
private val rootContext = object : HierarchicalContext(null) { }
43-
private val storage = ContextStorage(rootContext)
4435

45-
override fun current(): Context = storage.get()
36+
override fun current(ctx: CoroutineContext): Context = ctx.telemetryContext ?: rootContext
4637

4738
private fun onNewSpan(parentContext: Context?, name: String, attributes: Attributes): Context =
4839
when (parentContext) {
@@ -62,13 +53,10 @@ public class IsmContextManager private constructor() : ContextManager {
6253
else -> OtherContext(parentContext)
6354
}
6455

65-
private fun onCloseSpan(context: Context) {
66-
TODO()
67-
}
56+
private fun onCloseSpan(context: Context) = Unit
6857

6958
private abstract inner class HierarchicalContext(val parent: Context?) : Context {
7059
override fun makeCurrent(): Scope {
71-
storage.requireAndSet(parent ?: Context.None, this)
7260
return IsmScope(this)
7361
}
7462
}
@@ -90,8 +78,6 @@ public class IsmContextManager private constructor() : ContextManager {
9078
private inner class OtherContext(parent: Context?) : HierarchicalContext(parent)
9179

9280
private inner class IsmScope(val context: Context) : Scope {
93-
override fun close() {
94-
storage.requireAndSet(context, Context.None)
95-
}
81+
override fun close() = Unit
9682
}
9783
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
package aws.smithy.kotlin.runtime.telemetry.ism.metrics
5+
package aws.smithy.kotlin.runtime.telemetry.ism
66

77
import aws.smithy.kotlin.runtime.ExperimentalApi
88
import aws.smithy.kotlin.runtime.collections.Attributes
@@ -57,8 +57,7 @@ private data class ScopeMetricsImpl(
5757
public fun ScopeMetrics(
5858
records: Map<String, List<MetricRecord<*>>>,
5959
childScopes: Map<String, ScopeMetrics>,
60-
): ScopeMetrics =
61-
ScopeMetricsImpl(records, childScopes)
60+
): ScopeMetrics = ScopeMetricsImpl(records, childScopes)
6261

6362
public interface OperationMetrics : ScopeMetrics {
6463
public val service: String
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package aws.smithy.kotlin.runtime.telemetry.ism
6+
7+
import aws.smithy.kotlin.runtime.collections.AttributeKey
8+
import aws.smithy.kotlin.runtime.collections.Attributes
9+
import aws.smithy.kotlin.runtime.telemetry.context.Context
10+
import aws.smithy.kotlin.runtime.telemetry.trace.*
11+
12+
public class IsmTracerProvider : TracerProvider {
13+
override fun getOrCreateTracer(scope: String): Tracer {
14+
TODO("Not yet implemented")
15+
}
16+
}
17+
18+
public class IsmTracer : Tracer {
19+
override fun createSpan(
20+
name: String,
21+
initialAttributes: Attributes,
22+
spanKind: SpanKind,
23+
parentContext: Context?
24+
): TraceSpan {
25+
TODO("Not yet implemented")
26+
}
27+
}
28+
29+
public class IsmTraceSpan : TraceSpan {
30+
override val spanContext: SpanContext
31+
get() = TODO("Not yet implemented")
32+
33+
override fun <T : Any> set(key: AttributeKey<T>, value: T) {
34+
TODO("Not yet implemented")
35+
}
36+
37+
override fun mergeAttributes(attributes: Attributes) {
38+
TODO("Not yet implemented")
39+
}
40+
41+
override fun emitEvent(name: String, attributes: Attributes) {
42+
TODO("Not yet implemented")
43+
}
44+
45+
override fun setStatus(status: SpanStatus) {
46+
TODO("Not yet implemented")
47+
}
48+
49+
override fun close() {
50+
TODO("Not yet implemented")
51+
}
52+
}

runtime/observability/telemetry-provider-ism/common/src/aws/smithy/kotlin/runtime/telemetry/ism/trace/IsmTracerProvider.kt

Lines changed: 0 additions & 6 deletions
This file was deleted.

runtime/observability/telemetry-provider-ism/jvm/src/aws/smithy/kotlin/runtime/telemetry/ism/context/ContextStorageJvm.kt

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)