From 04d72e2449d9d7023d1673a7f94a828d986eb37f Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sun, 8 Dec 2024 13:17:05 -0800 Subject: [PATCH 01/24] Rename ktor tracing to ktor telemetry --- .../ktor/v1_0/KtorServerTelemetry.kt | 169 +++++++++++++++ .../ktor/v1_0/KtorServerTracing.kt | 1 + .../v1_0/KtorServerSpanKindExtractorTest.kt | 2 +- .../instrumentation/ktor/v1_0/KtorTestUtil.kt | 2 +- .../client/AbstractKtorClientTelemetry.kt | 42 ++++ .../AbstractKtorClientTelemetryBuilder.kt | 121 +++++++++++ .../ktor/client/AbstractKtorClientTracing.kt | 1 + .../AbstractKtorClientTracingBuilder.kt | 8 +- .../ktor/client/internal/Experimental.kt | 53 +++++ .../ktor/internal/KtorBuilderUtil.kt | 8 +- .../ktor/internal/KtorBuilderUtilOld.kt | 27 +++ .../ktor/internal/KtorClientTelemetryUtil.kt | 88 ++++++++ .../ktor/internal/KtorClientTracingUtil.kt | 1 + .../ktor/internal/KtorServerTelemetryUtil.kt | 83 ++++++++ .../ktor/internal/KtorServerTracingUtil.kt | 1 + .../AbstractKtorServerTelemetryBuilder.kt | 195 ++++++++++++++++++ .../AbstractKtorServerTracingBuilder.kt | 2 +- .../ktor/v2_0/HttpClientInstrumentation.java | 10 +- .../ktor/v2_0/ServerInstrumentation.java | 10 +- .../ktor/v2_0/client/KtorClientTelemetry.kt | 33 +++ .../v2_0/client/KtorClientTelemetryBuilder.kt | 17 ++ .../ktor/v2_0/client/KtorClientTracing.kt | 1 + .../v2_0/client/KtorClientTracingBuilder.kt | 1 + .../v2_0/server/KtorServerTelemetryBuilder.kt | 29 +++ .../v2_0/server/KtorServerTracingBuilder.kt | 1 + .../ktor/v3_0/HttpClientInstrumentation.java | 10 +- .../ktor/v3_0/ServerInstrumentation.java | 10 +- .../ktor/v3_0/client/KtorClientTelemetry.kt | 33 +++ .../v3_0/client/KtorClientTelemetryBuilder.kt | 17 ++ .../ktor/v3_0/client/KtorClientTracing.kt | 1 + .../v3_0/client/KtorClientTracingBuilder.kt | 1 + .../v3_0/server/KtorServerTelemetryBuilder.kt | 29 +++ .../v3_0/server/KtorServerTracingBuilder.kt | 1 + 33 files changed, 978 insertions(+), 30 deletions(-) create mode 100644 instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTelemetry.kt create mode 100644 instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTelemetry.kt create mode 100644 instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTelemetryBuilder.kt create mode 100644 instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/internal/Experimental.kt create mode 100644 instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorBuilderUtilOld.kt create mode 100644 instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorClientTelemetryUtil.kt create mode 100644 instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorServerTelemetryUtil.kt create mode 100644 instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/AbstractKtorServerTelemetryBuilder.kt create mode 100644 instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt create mode 100644 instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt create mode 100644 instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt create mode 100644 instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetry.kt create mode 100644 instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetryBuilder.kt create mode 100644 instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTelemetryBuilder.kt diff --git a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTelemetry.kt b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTelemetry.kt new file mode 100644 index 000000000000..1ecdf34b18d9 --- /dev/null +++ b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTelemetry.kt @@ -0,0 +1,169 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.v1_0 + +import io.ktor.application.* +import io.ktor.request.* +import io.ktor.response.* +import io.ktor.routing.* +import io.ktor.util.* +import io.ktor.util.pipeline.* +import io.opentelemetry.api.OpenTelemetry +import io.opentelemetry.context.Context +import io.opentelemetry.extension.kotlin.asContextElement +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor +import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter +import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor +import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusBuilder +import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor +import io.opentelemetry.instrumentation.api.internal.InstrumenterUtil +import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute +import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource +import kotlinx.coroutines.withContext + +class KtorServerTelemetry private constructor( + private val instrumenter: Instrumenter, +) { + + class Configuration { + internal lateinit var builder: DefaultHttpServerInstrumenterBuilder + + internal var spanKindExtractor: + (SpanKindExtractor) -> SpanKindExtractor = { a -> a } + + fun setOpenTelemetry(openTelemetry: OpenTelemetry) { + this.builder = + DefaultHttpServerInstrumenterBuilder.create( + INSTRUMENTATION_NAME, + openTelemetry, + KtorHttpServerAttributesGetter.INSTANCE + ) + } + + fun setStatusExtractor( + extractor: (SpanStatusExtractor) -> SpanStatusExtractor + ) { + builder.setStatusExtractor { prevExtractor -> + SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder, + request: ApplicationRequest, + response: ApplicationResponse?, + throwable: Throwable? -> + extractor(prevExtractor).extract(spanStatusBuilder, request, response, throwable) + } + } + } + + fun setSpanKindExtractor(extractor: (SpanKindExtractor) -> SpanKindExtractor) { + this.spanKindExtractor = extractor + } + + fun addAttributeExtractor(extractor: AttributesExtractor) { + builder.addAttributesExtractor(extractor) + } + + fun setCapturedRequestHeaders(requestHeaders: List) { + builder.setCapturedRequestHeaders(requestHeaders) + } + + fun setCapturedResponseHeaders(responseHeaders: List) { + builder.setCapturedResponseHeaders(responseHeaders) + } + + fun setKnownMethods(knownMethods: Set) { + builder.setKnownMethods(knownMethods) + } + + internal fun isOpenTelemetryInitialized(): Boolean = this::builder.isInitialized + } + + private fun start(call: ApplicationCall): Context? { + val parentContext = Context.current() + if (!instrumenter.shouldStart(parentContext, call.request)) { + return null + } + + return instrumenter.start(parentContext, call.request) + } + + private fun end(context: Context, call: ApplicationCall, error: Throwable?) { + instrumenter.end(context, call.request, call.response, error) + } + + companion object Feature : ApplicationFeature { + private const val INSTRUMENTATION_NAME = "io.opentelemetry.ktor-1.0" + + private val contextKey = AttributeKey("OpenTelemetry") + private val errorKey = AttributeKey("OpenTelemetryException") + + override val key: AttributeKey = AttributeKey("OpenTelemetry") + + override fun install(pipeline: Application, configure: Configuration.() -> Unit): KtorServerTelemetry { + val configuration = Configuration().apply(configure) + + if (!configuration.isOpenTelemetryInitialized()) { + throw IllegalArgumentException("OpenTelemetry must be set") + } + + val instrumenter = InstrumenterUtil.buildUpstreamInstrumenter( + configuration.builder.instrumenterBuilder(), + ApplicationRequestGetter, + configuration.spanKindExtractor(SpanKindExtractor.alwaysServer()) + ) + + val feature = KtorServerTelemetry(instrumenter) + + val startPhase = PipelinePhase("OpenTelemetry") + pipeline.insertPhaseBefore(ApplicationCallPipeline.Monitoring, startPhase) + pipeline.intercept(startPhase) { + val context = feature.start(call) + + if (context != null) { + call.attributes.put(contextKey, context) + withContext(context.asContextElement()) { + try { + proceed() + } catch (err: Throwable) { + // Stash error for reporting later since need ktor to finish setting up the response + call.attributes.put(errorKey, err) + throw err + } + } + } else { + proceed() + } + } + + val postSendPhase = PipelinePhase("OpenTelemetryPostSend") + pipeline.sendPipeline.insertPhaseAfter(ApplicationSendPipeline.After, postSendPhase) + pipeline.sendPipeline.intercept(postSendPhase) { + val context = call.attributes.getOrNull(contextKey) + if (context != null) { + var error: Throwable? = call.attributes.getOrNull(errorKey) + try { + proceed() + } catch (t: Throwable) { + error = t + throw t + } finally { + feature.end(context, call, error) + } + } else { + proceed() + } + } + + pipeline.environment.monitor.subscribe(Routing.RoutingCallStarted) { call -> + val context = call.attributes.getOrNull(contextKey) + if (context != null) { + HttpServerRoute.update(context, HttpServerRouteSource.SERVER, { _, arg -> arg.route.parent.toString() }, call) + } + } + + return feature + } + } +} diff --git a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt index 844cbe2895fd..1073053d0639 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt @@ -25,6 +25,7 @@ import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource import kotlinx.coroutines.withContext +@Deprecated("Use KtorServerTelemetry instead", ReplaceWith("KtorServerTelemetry")) class KtorServerTracing private constructor( private val instrumenter: Instrumenter, ) { diff --git a/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerSpanKindExtractorTest.kt b/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerSpanKindExtractorTest.kt index 364c67a9e1a5..a494ed33aced 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerSpanKindExtractorTest.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerSpanKindExtractorTest.kt @@ -58,7 +58,7 @@ class KtorServerSpanKindExtractorTest : AbstractHttpServerUsingTest diff --git a/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorTestUtil.kt b/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorTestUtil.kt index 6daf7382ec40..85fd9d6b78fa 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorTestUtil.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorTestUtil.kt @@ -12,7 +12,7 @@ import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTes class KtorTestUtil { companion object { fun installOpenTelemetry(application: Application, openTelemetry: OpenTelemetry) { - application.install(KtorServerTracing) { + application.install(KtorServerTelemetry) { setOpenTelemetry(openTelemetry) setCapturedRequestHeaders(listOf(AbstractHttpServerTest.TEST_REQUEST_HEADER)) setCapturedResponseHeaders(listOf(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTelemetry.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTelemetry.kt new file mode 100644 index 000000000000..cfff0ef78119 --- /dev/null +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTelemetry.kt @@ -0,0 +1,42 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.client + +import io.ktor.client.call.* +import io.ktor.client.request.* +import io.ktor.client.statement.* +import io.opentelemetry.context.Context +import io.opentelemetry.context.propagation.ContextPropagators +import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter + +abstract class AbstractKtorClientTelemetry( + private val instrumenter: Instrumenter, + private val propagators: ContextPropagators, +) { + + internal fun createSpan(requestBuilder: HttpRequestBuilder): Context? { + val parentContext = Context.current() + val requestData = requestBuilder.build() + + return if (instrumenter.shouldStart(parentContext, requestData)) { + instrumenter.start(parentContext, requestData) + } else { + null + } + } + + internal fun populateRequestHeaders(requestBuilder: HttpRequestBuilder, context: Context) { + propagators.textMapPropagator.inject(context, requestBuilder, KtorHttpHeadersSetter) + } + + internal fun endSpan(context: Context, call: HttpClientCall, error: Throwable?) { + endSpan(context, HttpRequestBuilder().takeFrom(call.request), call.response, error) + } + + internal fun endSpan(context: Context, requestBuilder: HttpRequestBuilder, response: HttpResponse?, error: Throwable?) { + instrumenter.end(context, requestBuilder.build(), response, error) + } +} diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTelemetryBuilder.kt new file mode 100644 index 000000000000..eddeec494faa --- /dev/null +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTelemetryBuilder.kt @@ -0,0 +1,121 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.client + +import io.ktor.client.request.* +import io.ktor.client.statement.* +import io.ktor.http.* +import io.opentelemetry.api.OpenTelemetry +import io.opentelemetry.api.common.AttributesBuilder +import io.opentelemetry.context.Context +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor +import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtil + +abstract class AbstractKtorClientTelemetryBuilder( + private val instrumentationName: String +) { + companion object { + init { + KtorBuilderUtil.clientBuilderExtractor = { it.clientBuilder } + } + } + + internal lateinit var openTelemetry: OpenTelemetry + protected lateinit var clientBuilder: DefaultHttpClientInstrumenterBuilder + + fun setOpenTelemetry(openTelemetry: OpenTelemetry) { + this.openTelemetry = openTelemetry + this.clientBuilder = DefaultHttpClientInstrumenterBuilder.create( + instrumentationName, + openTelemetry, + KtorHttpClientAttributesGetter + ) + } + + protected fun getOpenTelemetry(): OpenTelemetry { + return openTelemetry + } + + fun capturedRequestHeaders(vararg headers: String) = capturedRequestHeaders(headers.asIterable()) + + fun capturedRequestHeaders(headers: Iterable) { + clientBuilder.setCapturedRequestHeaders(headers.toList()) + } + + fun capturedResponseHeaders(vararg headers: String) = capturedResponseHeaders(headers.asIterable()) + + fun capturedResponseHeaders(headers: Iterable) { + clientBuilder.setCapturedResponseHeaders(headers.toList()) + } + + fun knownMethods(vararg methods: String) = knownMethods(methods.asIterable()) + + fun knownMethods(vararg methods: HttpMethod) = knownMethods(methods.asIterable()) + + @JvmName("knownMethodsJvm") + fun knownMethods(methods: Iterable) = knownMethods(methods.map { it.value }) + + fun knownMethods(methods: Iterable) { + clientBuilder.setKnownMethods(methods.toSet()) + } + + fun attributeExtractor(extractorBuilder: ExtractorBuilder.() -> Unit = {}) { + val builder = ExtractorBuilder().apply(extractorBuilder).build() + this.clientBuilder.addAttributeExtractor( + object : AttributesExtractor { + override fun onStart(attributes: AttributesBuilder, parentContext: Context, request: HttpRequestData) { + builder.onStart(OnStartData(attributes, parentContext, request)) + } + + override fun onEnd(attributes: AttributesBuilder, context: Context, request: HttpRequestData, response: HttpResponse?, error: Throwable?) { + builder.onEnd(OnEndData(attributes, context, request, response, error)) + } + } + ) + } + + class ExtractorBuilder { + private var onStart: OnStartData.() -> Unit = {} + private var onEnd: OnEndData.() -> Unit = {} + + fun onStart(block: OnStartData.() -> Unit) { + onStart = block + } + + fun onEnd(block: OnEndData.() -> Unit) { + onEnd = block + } + + internal fun build(): Extractor { + return Extractor(onStart, onEnd) + } + } + + internal class Extractor(val onStart: OnStartData.() -> Unit, val onEnd: OnEndData.() -> Unit) + + data class OnStartData( + val attributes: AttributesBuilder, + val parentContext: Context, + val request: HttpRequestData + ) + + data class OnEndData( + val attributes: AttributesBuilder, + val parentContext: Context, + val request: HttpRequestData, + val response: HttpResponse?, + val error: Throwable? + ) + + /** + * Can be used via the unstable method {@link + * Experimental#setEmitExperimentalHttpClientMetrics(AbstractKtorClientTelemetryBuilder, boolean)}. + */ + internal fun emitExperimentalHttpClientMetrics() { + clientBuilder.setEmitExperimentalHttpClientMetrics(true) + } +} diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTracing.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTracing.kt index 925cb6cf3156..0e1c099e4e7e 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTracing.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTracing.kt @@ -12,6 +12,7 @@ import io.opentelemetry.context.Context import io.opentelemetry.context.propagation.ContextPropagators import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter +@Deprecated("Use AbstractKtorClientTelemetry instead", ReplaceWith("AbstractKtorClientTelemetry")) abstract class AbstractKtorClientTracing( private val instrumenter: Instrumenter, private val propagators: ContextPropagators, diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTracingBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTracingBuilder.kt index 3b99bba1f6af..410bacbd4340 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTracingBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTracingBuilder.kt @@ -13,14 +13,15 @@ import io.opentelemetry.api.common.AttributesBuilder import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor -import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtil +import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtilOld +@Deprecated("Use AbstractKtorClientTelemetryBuilder instead", ReplaceWith("AbstractKtorClientTelemetryBuilder")) abstract class AbstractKtorClientTracingBuilder( private val instrumentationName: String ) { companion object { init { - KtorBuilderUtil.clientBuilderExtractor = { it.clientBuilder } + KtorBuilderUtilOld.clientBuilderExtractor = { it.clientBuilder } } } @@ -159,13 +160,14 @@ abstract class AbstractKtorClientTracingBuilder( * * @param emitExperimentalHttpClientMetrics `true` if the experimental HTTP client metrics are to be emitted. */ - @Deprecated("Please use method `emitExperimentalHttpClientMetrics`") + @Deprecated("Please use method `Experimental.emitExperimentalHttpClientMetrics`") fun setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics: Boolean) { if (emitExperimentalHttpClientMetrics) { emitExperimentalHttpClientMetrics() } } + @Deprecated("Please use method `Experimental.emitExperimentalHttpClientMetrics`") fun emitExperimentalHttpClientMetrics() { clientBuilder.setEmitExperimentalHttpClientMetrics(true) } diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/internal/Experimental.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/internal/Experimental.kt new file mode 100644 index 000000000000..7610945d38c1 --- /dev/null +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/internal/Experimental.kt @@ -0,0 +1,53 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.client.internal + +import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTelemetryBuilder +import java.lang.reflect.InvocationTargetException +import java.lang.reflect.Method +import java.util.logging.Level +import java.util.logging.Logger + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +// TODO (trask) update the above javadoc similar to +// https://github.com/open-telemetry/opentelemetry-java/pull/6886 +class Experimental { + + companion object { + private val logger: Logger = Logger.getLogger(Experimental::class.java.name) + + private val emitExperimentalTelemetryMethod = getEmitExperimentalTelemetry() + + fun setEmitExperimentalTelemetry(builder: AbstractKtorClientTelemetryBuilder?, emitExperimentalTelemetry: Boolean) { + if (emitExperimentalTelemetryMethod != null) { + try { + emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry) + } catch (e: IllegalAccessException) { + logger.log(Level.FINE, e.message, e) + } catch (e: InvocationTargetException) { + logger.log(Level.FINE, e.message, e) + } + } + } + + private fun getEmitExperimentalTelemetry(): Method? { + try { + val method = AbstractKtorClientTelemetryBuilder::class.java.getDeclaredMethod( + "setEmitExperimentalHttpClientMetrics", + Boolean::class.javaPrimitiveType + ) + method.setAccessible(true) + return method + } catch (e: NoSuchMethodException) { + logger.log(Level.FINE, e.message, e) + return null + } + } + } +} diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorBuilderUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorBuilderUtil.kt index ec074cca66bd..ac3ee94db3fa 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorBuilderUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorBuilderUtil.kt @@ -11,16 +11,16 @@ import io.ktor.server.request.* import io.ktor.server.response.* import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder -import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTracingBuilder -import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTracingBuilder +import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTelemetryBuilder /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ object KtorBuilderUtil { - lateinit var clientBuilderExtractor: (AbstractKtorClientTracingBuilder) -> DefaultHttpClientInstrumenterBuilder + lateinit var clientBuilderExtractor: (AbstractKtorClientTelemetryBuilder) -> DefaultHttpClientInstrumenterBuilder lateinit var serverBuilderExtractor: ( - AbstractKtorServerTracingBuilder + AbstractKtorServerTelemetryBuilder ) -> DefaultHttpServerInstrumenterBuilder } diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorBuilderUtilOld.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorBuilderUtilOld.kt new file mode 100644 index 000000000000..6e00c3d4a98d --- /dev/null +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorBuilderUtilOld.kt @@ -0,0 +1,27 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.internal + +import io.ktor.client.request.* +import io.ktor.client.statement.* +import io.ktor.server.request.* +import io.ktor.server.response.* +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder +import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTracingBuilder +import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTracingBuilder + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +@Deprecated("Use KtorBuilderUtil instead", ReplaceWith("KtorBuilderUtil")) +object KtorBuilderUtilOld { + lateinit var clientBuilderExtractor: (AbstractKtorClientTracingBuilder) -> DefaultHttpClientInstrumenterBuilder + lateinit var serverBuilderExtractor: ( + AbstractKtorServerTracingBuilder + ) -> DefaultHttpServerInstrumenterBuilder +} diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorClientTelemetryUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorClientTelemetryUtil.kt new file mode 100644 index 000000000000..630f4bb14e2c --- /dev/null +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorClientTelemetryUtil.kt @@ -0,0 +1,88 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.internal + +import io.ktor.client.* +import io.ktor.client.request.* +import io.ktor.client.statement.* +import io.ktor.util.* +import io.ktor.util.pipeline.* +import io.opentelemetry.context.Context +import io.opentelemetry.extension.kotlin.asContextElement +import io.opentelemetry.instrumentation.api.semconv.http.HttpClientRequestResendCount +import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTelemetry +import kotlinx.coroutines.InternalCoroutinesApi +import kotlinx.coroutines.job +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +object KtorClientTelemetryUtil { + private val openTelemetryContextKey = AttributeKey("OpenTelemetry") + + fun install(plugin: AbstractKtorClientTelemetry, scope: HttpClient) { + installSpanCreation(plugin, scope) + installSpanEnd(plugin, scope) + } + + private fun installSpanCreation(plugin: AbstractKtorClientTelemetry, scope: HttpClient) { + val initializeRequestPhase = PipelinePhase("OpenTelemetryInitializeRequest") + scope.requestPipeline.insertPhaseAfter(HttpRequestPipeline.State, initializeRequestPhase) + + scope.requestPipeline.intercept(initializeRequestPhase) { + val openTelemetryContext = HttpClientRequestResendCount.initialize(Context.current()) + withContext(openTelemetryContext.asContextElement()) { proceed() } + } + + val createSpanPhase = PipelinePhase("OpenTelemetryCreateSpan") + scope.sendPipeline.insertPhaseAfter(HttpSendPipeline.State, createSpanPhase) + + scope.sendPipeline.intercept(createSpanPhase) { + val requestBuilder = context + val openTelemetryContext = plugin.createSpan(requestBuilder) + + if (openTelemetryContext != null) { + try { + requestBuilder.attributes.put(openTelemetryContextKey, openTelemetryContext) + plugin.populateRequestHeaders(requestBuilder, openTelemetryContext) + + withContext(openTelemetryContext.asContextElement()) { proceed() } + } catch (e: Throwable) { + plugin.endSpan(openTelemetryContext, requestBuilder, null, e) + throw e + } + } else { + proceed() + } + } + } + + @OptIn(InternalCoroutinesApi::class) + private fun installSpanEnd(plugin: AbstractKtorClientTelemetry, scope: HttpClient) { + val endSpanPhase = PipelinePhase("OpenTelemetryEndSpan") + scope.receivePipeline.insertPhaseBefore(HttpReceivePipeline.State, endSpanPhase) + + scope.receivePipeline.intercept(endSpanPhase) { + val openTelemetryContext = it.call.attributes.getOrNull(openTelemetryContextKey) + openTelemetryContext ?: return@intercept + + scope.launch { + val job = it.call.coroutineContext.job + job.join() + val cause = if (!job.isCancelled) { + null + } else { + kotlin.runCatching { job.getCancellationException() }.getOrNull() + } + + plugin.endSpan(openTelemetryContext, it.call, cause) + } + } + } +} diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorClientTracingUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorClientTracingUtil.kt index b1735217a99a..4ed1d6d3fea1 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorClientTracingUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorClientTracingUtil.kt @@ -23,6 +23,7 @@ import kotlinx.coroutines.withContext * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ +@Deprecated("Use KtorClientTelemetryUtil instead", ReplaceWith("KtorClientTelemetryUtil")) object KtorClientTracingUtil { private val openTelemetryContextKey = AttributeKey("OpenTelemetry") diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorServerTelemetryUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorServerTelemetryUtil.kt new file mode 100644 index 000000000000..7ec23c7923c5 --- /dev/null +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorServerTelemetryUtil.kt @@ -0,0 +1,83 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.internal + +import io.ktor.server.application.* +import io.ktor.server.request.* +import io.ktor.server.response.* +import io.ktor.util.* +import io.ktor.util.pipeline.* +import io.opentelemetry.context.Context +import io.opentelemetry.extension.kotlin.asContextElement +import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter +import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor +import io.opentelemetry.instrumentation.api.internal.InstrumenterUtil +import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.server.ApplicationRequestGetter +import kotlinx.coroutines.withContext + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +object KtorServerTelemetryUtil { + + fun configureTelemetry(builder: AbstractKtorServerTelemetryBuilder, application: Application) { + val contextKey = AttributeKey("OpenTelemetry") + val errorKey = AttributeKey("OpenTelemetryException") + + val instrumenter = instrumenter(builder) + val tracer = KtorServerTracer(instrumenter) + val startPhase = PipelinePhase("OpenTelemetry") + + application.insertPhaseBefore(ApplicationCallPipeline.Monitoring, startPhase) + application.intercept(startPhase) { + val context = tracer.start(call) + + if (context != null) { + call.attributes.put(contextKey, context) + withContext(context.asContextElement()) { + try { + proceed() + } catch (err: Throwable) { + // Stash error for reporting later since need ktor to finish setting up the response + call.attributes.put(errorKey, err) + throw err + } + } + } else { + proceed() + } + } + + val postSendPhase = PipelinePhase("OpenTelemetryPostSend") + application.sendPipeline.insertPhaseAfter(ApplicationSendPipeline.After, postSendPhase) + application.sendPipeline.intercept(postSendPhase) { + val context = call.attributes.getOrNull(contextKey) + if (context != null) { + var error: Throwable? = call.attributes.getOrNull(errorKey) + try { + proceed() + } catch (t: Throwable) { + error = t + throw t + } finally { + tracer.end(context, call, error) + } + } else { + proceed() + } + } + } + + private fun instrumenter(builder: AbstractKtorServerTelemetryBuilder): Instrumenter { + return InstrumenterUtil.buildUpstreamInstrumenter( + builder.serverBuilder.instrumenterBuilder(), + ApplicationRequestGetter, + builder.spanKindExtractor(SpanKindExtractor.alwaysServer()) + ) + } +} diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorServerTracingUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorServerTracingUtil.kt index e5e3ea4fc908..975803e11ee2 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorServerTracingUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorServerTracingUtil.kt @@ -23,6 +23,7 @@ import kotlinx.coroutines.withContext * This class is internal and is hence not for public use. Its APIs are unstable and can change at * any time. */ +@Deprecated("Use KtorServerTelemetryUtil instead", ReplaceWith("KtorServerTelemetryUtil")) object KtorServerTracingUtil { fun configureTracing(builder: AbstractKtorServerTracingBuilder, application: Application) { diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/AbstractKtorServerTelemetryBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/AbstractKtorServerTelemetryBuilder.kt new file mode 100644 index 000000000000..2195e52584d0 --- /dev/null +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/AbstractKtorServerTelemetryBuilder.kt @@ -0,0 +1,195 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.server + +import io.ktor.http.* +import io.ktor.server.request.* +import io.ktor.server.response.* +import io.opentelemetry.api.OpenTelemetry +import io.opentelemetry.api.common.AttributesBuilder +import io.opentelemetry.api.trace.SpanKind +import io.opentelemetry.context.Context +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor +import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor +import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusBuilder +import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor +import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtil + +abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationName: String) { + companion object { + init { + KtorBuilderUtil.serverBuilderExtractor = { it.serverBuilder } + } + } + + internal lateinit var serverBuilder: DefaultHttpServerInstrumenterBuilder + + internal var spanKindExtractor: + (SpanKindExtractor) -> SpanKindExtractor = { a -> a } + + fun setOpenTelemetry(openTelemetry: OpenTelemetry) { + this.serverBuilder = + DefaultHttpServerInstrumenterBuilder.create( + instrumentationName, + openTelemetry, + KtorHttpServerAttributesGetter.INSTANCE + ) + } + + @Deprecated("Please use method `spanStatusExtractor`") + fun setStatusExtractor( + extractor: (SpanStatusExtractor) -> SpanStatusExtractor + ) { + spanStatusExtractor { prevStatusExtractor -> + extractor(prevStatusExtractor).extract(spanStatusBuilder, request, response, error) + } + } + + fun spanStatusExtractor(extract: SpanStatusData.(SpanStatusExtractor) -> Unit) { + serverBuilder.setStatusExtractor { prevExtractor -> + SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder, + request: ApplicationRequest, + response: ApplicationResponse?, + throwable: Throwable? -> + extract( + SpanStatusData(spanStatusBuilder, request, response, throwable), + prevExtractor + ) + } + } + } + + data class SpanStatusData( + val spanStatusBuilder: SpanStatusBuilder, + val request: ApplicationRequest, + val response: ApplicationResponse?, + val error: Throwable? + ) + + @Deprecated("Please use method `spanKindExtractor`") + fun setSpanKindExtractor(extractor: (SpanKindExtractor) -> SpanKindExtractor) { + spanKindExtractor { prevSpanKindExtractor -> + extractor(prevSpanKindExtractor).extract(this) + } + } + + fun spanKindExtractor(extract: ApplicationRequest.(SpanKindExtractor) -> SpanKind) { + spanKindExtractor = { prevExtractor -> + SpanKindExtractor { request: ApplicationRequest -> + extract(request, prevExtractor) + } + } + } + + @Deprecated("Please use method `attributeExtractor`") + fun addAttributeExtractor(extractor: AttributesExtractor) { + attributeExtractor { + onStart { + extractor.onStart(attributes, parentContext, request) + } + onEnd { + extractor.onEnd(attributes, parentContext, request, response, error) + } + } + } + + fun attributeExtractor(extractorBuilder: ExtractorBuilder.() -> Unit = {}) { + val builder = ExtractorBuilder().apply(extractorBuilder).build() + serverBuilder.addAttributesExtractor( + object : AttributesExtractor { + override fun onStart(attributes: AttributesBuilder, parentContext: Context, request: ApplicationRequest) { + builder.onStart(OnStartData(attributes, parentContext, request)) + } + + override fun onEnd(attributes: AttributesBuilder, context: Context, request: ApplicationRequest, response: ApplicationResponse?, error: Throwable?) { + builder.onEnd(OnEndData(attributes, context, request, response, error)) + } + } + ) + } + + class ExtractorBuilder { + private var onStart: OnStartData.() -> Unit = {} + private var onEnd: OnEndData.() -> Unit = {} + + fun onStart(block: OnStartData.() -> Unit) { + onStart = block + } + + fun onEnd(block: OnEndData.() -> Unit) { + onEnd = block + } + + internal fun build(): Extractor { + return Extractor(onStart, onEnd) + } + } + + internal class Extractor(val onStart: OnStartData.() -> Unit, val onEnd: OnEndData.() -> Unit) + + data class OnStartData( + val attributes: AttributesBuilder, + val parentContext: Context, + val request: ApplicationRequest + ) + + data class OnEndData( + val attributes: AttributesBuilder, + val parentContext: Context, + val request: ApplicationRequest, + val response: ApplicationResponse?, + val error: Throwable? + ) + + @Deprecated( + "Please use method `capturedRequestHeaders`", + ReplaceWith("capturedRequestHeaders(headers)") + ) + fun setCapturedRequestHeaders(headers: List) = capturedRequestHeaders(headers) + + fun capturedRequestHeaders(vararg headers: String) = capturedRequestHeaders(headers.asIterable()) + + fun capturedRequestHeaders(headers: Iterable) { + serverBuilder.setCapturedRequestHeaders(headers.toList()) + } + + @Deprecated( + "Please use method `capturedResponseHeaders`", + ReplaceWith("capturedResponseHeaders(headers)") + ) + fun setCapturedResponseHeaders(headers: List) = capturedResponseHeaders(headers) + + fun capturedResponseHeaders(vararg headers: String) = capturedResponseHeaders(headers.asIterable()) + + fun capturedResponseHeaders(headers: Iterable) { + serverBuilder.setCapturedResponseHeaders(headers.toList()) + } + + @Deprecated( + "Please use method `knownMethods`", + ReplaceWith("knownMethods(knownMethods)") + ) + fun setKnownMethods(knownMethods: Set) = knownMethods(knownMethods) + + fun knownMethods(vararg methods: String) = knownMethods(methods.asIterable()) + + fun knownMethods(vararg methods: HttpMethod) = knownMethods(methods.asIterable()) + + @JvmName("knownMethodsJvm") + fun knownMethods(methods: Iterable) = knownMethods(methods.map { it.value }) + + fun knownMethods(methods: Iterable) { + methods.toSet().apply { + serverBuilder.setKnownMethods(this) + } + } + + /** + * {@link #setOpenTelemetry(OpenTelemetry)} sets the serverBuilder to a non-null value. + */ + fun isOpenTelemetryInitialized(): Boolean = this::serverBuilder.isInitialized +} diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/AbstractKtorServerTracingBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/AbstractKtorServerTracingBuilder.kt index 65abba99460c..b3d3217d9a9f 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/AbstractKtorServerTracingBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/AbstractKtorServerTracingBuilder.kt @@ -6,7 +6,6 @@ package io.opentelemetry.instrumentation.ktor.server import io.ktor.http.* -import io.ktor.server.application.* import io.ktor.server.request.* import io.ktor.server.response.* import io.opentelemetry.api.OpenTelemetry @@ -20,6 +19,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusBuilder import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtil +@Deprecated("Use AbstractKtorServerTelemetryBuilder instead", ReplaceWith("AbstractKtorServerTelemetryBuilder")) abstract class AbstractKtorServerTracingBuilder(private val instrumentationName: String) { companion object { init { diff --git a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java index 79fb525fdb7a..f1c116177394 100644 --- a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java +++ b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java @@ -14,8 +14,8 @@ import io.ktor.client.engine.HttpClientEngineConfig; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtil; -import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTracing; -import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTracingBuilder; +import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTelemetry; +import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTelemetryBuilder; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; @@ -46,14 +46,14 @@ public static class ConstructorAdvice { @Advice.OnMethodEnter public static void onEnter( @Advice.Argument(1) HttpClientConfig httpClientConfig) { - httpClientConfig.install(KtorClientTracing.Companion, new SetupFunction()); + httpClientConfig.install(KtorClientTelemetry.Companion, new SetupFunction()); } } - public static class SetupFunction implements Function1 { + public static class SetupFunction implements Function1 { @Override - public Unit invoke(KtorClientTracingBuilder builder) { + public Unit invoke(KtorClientTelemetryBuilder builder) { builder.setOpenTelemetry(GlobalOpenTelemetry.get()); KtorBuilderUtil.clientBuilderExtractor.invoke(builder).configure(AgentCommonConfig.get()); return kotlin.Unit.INSTANCE; diff --git a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/ServerInstrumentation.java b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/ServerInstrumentation.java index 214d94d80df0..94463567087a 100644 --- a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/ServerInstrumentation.java +++ b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/ServerInstrumentation.java @@ -12,8 +12,8 @@ import io.ktor.server.application.ApplicationPluginKt; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtil; -import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTracingBuilder; -import io.opentelemetry.instrumentation.ktor.v2_0.server.KtorServerTracingBuilderKt; +import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTelemetryBuilder; +import io.opentelemetry.instrumentation.ktor.v2_0.server.KtorServerTelemetryBuilderKt; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; @@ -41,15 +41,15 @@ public static class ConstructorAdvice { @Advice.OnMethodExit public static void onExit(@Advice.FieldValue("_applicationInstance") Application application) { ApplicationPluginKt.install( - application, KtorServerTracingBuilderKt.getKtorServerTracing(), new SetupFunction()); + application, KtorServerTelemetryBuilderKt.getKtorServerTelemetry(), new SetupFunction()); } } public static class SetupFunction - implements Function1 { + implements Function1 { @Override - public Unit invoke(AbstractKtorServerTracingBuilder builder) { + public Unit invoke(AbstractKtorServerTelemetryBuilder builder) { builder.setOpenTelemetry(GlobalOpenTelemetry.get()); KtorBuilderUtil.serverBuilderExtractor.invoke(builder).configure(AgentCommonConfig.get()); return kotlin.Unit.INSTANCE; diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt new file mode 100644 index 000000000000..69e25b2349b9 --- /dev/null +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt @@ -0,0 +1,33 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.v2_0.client + +import io.ktor.client.* +import io.ktor.client.plugins.* +import io.ktor.client.request.* +import io.ktor.client.statement.* +import io.ktor.util.* +import io.opentelemetry.context.propagation.ContextPropagators +import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter +import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTelemetry +import io.opentelemetry.instrumentation.ktor.internal.KtorClientTelemetryUtil + +class KtorClientTelemetry internal constructor( + instrumenter: Instrumenter, + propagators: ContextPropagators +) : AbstractKtorClientTelemetry(instrumenter, propagators) { + + companion object : HttpClientPlugin { + + override val key = AttributeKey("OpenTelemetry") + + override fun prepare(block: KtorClientTelemetryBuilder.() -> Unit) = KtorClientTelemetryBuilder().apply(block).build() + + override fun install(plugin: KtorClientTelemetry, scope: HttpClient) { + KtorClientTelemetryUtil.install(plugin, scope) + } + } +} diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt new file mode 100644 index 000000000000..38abca4a477a --- /dev/null +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt @@ -0,0 +1,17 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.v2_0.client + +import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.InstrumentationProperties.INSTRUMENTATION_NAME + +class KtorClientTelemetryBuilder : AbstractKtorClientTelemetryBuilder(INSTRUMENTATION_NAME) { + + internal fun build(): KtorClientTelemetry = KtorClientTelemetry( + instrumenter = clientBuilder.build(), + propagators = getOpenTelemetry().propagators, + ) +} diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracing.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracing.kt index 429e2ccdfe0c..b7e4b17e927e 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracing.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracing.kt @@ -15,6 +15,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTracing import io.opentelemetry.instrumentation.ktor.internal.KtorClientTracingUtil +@Deprecated("Use KtorClientTelemetry instead", ReplaceWith("KtorClientTelemetry")) class KtorClientTracing internal constructor( instrumenter: Instrumenter, propagators: ContextPropagators diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracingBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracingBuilder.kt index b93fb82f02da..fc0b04d705cb 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracingBuilder.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracingBuilder.kt @@ -8,6 +8,7 @@ package io.opentelemetry.instrumentation.ktor.v2_0.client import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTracingBuilder import io.opentelemetry.instrumentation.ktor.v2_0.InstrumentationProperties.INSTRUMENTATION_NAME +@Deprecated("Use KtorClientTelemetryBuilder instead", ReplaceWith("KtorClientTelemetryBuilder")) class KtorClientTracingBuilder : AbstractKtorClientTracingBuilder(INSTRUMENTATION_NAME) { internal fun build(): KtorClientTracing = KtorClientTracing( diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt new file mode 100644 index 000000000000..aba80c987944 --- /dev/null +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt @@ -0,0 +1,29 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.v2_0.server + +import io.ktor.server.application.* +import io.ktor.server.routing.* +import io.opentelemetry.context.Context +import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute +import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource +import io.opentelemetry.instrumentation.ktor.internal.KtorServerTelemetryUtil +import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.InstrumentationProperties.INSTRUMENTATION_NAME + +class KtorServerTelemetryBuilder internal constructor( + instrumentationName: String +) : AbstractKtorServerTelemetryBuilder(instrumentationName) + +val KtorServerTelemetry = createRouteScopedPlugin("OpenTelemetry", { KtorServerTelemetryBuilder(INSTRUMENTATION_NAME) }) { + require(pluginConfig.isOpenTelemetryInitialized()) { "OpenTelemetry must be set" } + + KtorServerTelemetryUtil.configureTelemetry(pluginConfig, application) + + application.environment.monitor.subscribe(Routing.RoutingCallStarted) { call -> + HttpServerRoute.update(Context.current(), HttpServerRouteSource.SERVER, { _, arg -> arg.route.parent.toString() }, call) + } +} diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracingBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracingBuilder.kt index b2c4be9b86db..811a4d862f91 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracingBuilder.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracingBuilder.kt @@ -14,6 +14,7 @@ import io.opentelemetry.instrumentation.ktor.internal.KtorServerTracingUtil import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTracingBuilder import io.opentelemetry.instrumentation.ktor.v2_0.InstrumentationProperties.INSTRUMENTATION_NAME +@Deprecated("Use KtorServerTelemetryBuilder instead", ReplaceWith("KtorServerTelemetryBuilder")) class KtorServerTracingBuilder internal constructor( instrumentationName: String ) : AbstractKtorServerTracingBuilder(instrumentationName) diff --git a/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/HttpClientInstrumentation.java b/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/HttpClientInstrumentation.java index 09dfcca67e20..8920f0d249ab 100644 --- a/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/HttpClientInstrumentation.java +++ b/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/HttpClientInstrumentation.java @@ -14,8 +14,8 @@ import io.ktor.client.engine.HttpClientEngineConfig; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtil; -import io.opentelemetry.instrumentation.ktor.v3_0.client.KtorClientTracing; -import io.opentelemetry.instrumentation.ktor.v3_0.client.KtorClientTracingBuilder; +import io.opentelemetry.instrumentation.ktor.v3_0.client.KtorClientTelemetry; +import io.opentelemetry.instrumentation.ktor.v3_0.client.KtorClientTelemetryBuilder; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; @@ -46,14 +46,14 @@ public static class ConstructorAdvice { @Advice.OnMethodEnter public static void onEnter( @Advice.Argument(1) HttpClientConfig httpClientConfig) { - httpClientConfig.install(KtorClientTracing.Companion, new SetupFunction()); + httpClientConfig.install(KtorClientTelemetry.Companion, new SetupFunction()); } } - public static class SetupFunction implements Function1 { + public static class SetupFunction implements Function1 { @Override - public Unit invoke(KtorClientTracingBuilder builder) { + public Unit invoke(KtorClientTelemetryBuilder builder) { builder.setOpenTelemetry(GlobalOpenTelemetry.get()); KtorBuilderUtil.clientBuilderExtractor.invoke(builder).configure(AgentCommonConfig.get()); return Unit.INSTANCE; diff --git a/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/ServerInstrumentation.java b/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/ServerInstrumentation.java index df4335fa686d..eb0639c54dbb 100644 --- a/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/ServerInstrumentation.java +++ b/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/ServerInstrumentation.java @@ -12,8 +12,8 @@ import io.ktor.server.application.ApplicationPluginKt; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtil; -import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTracingBuilder; -import io.opentelemetry.instrumentation.ktor.v3_0.server.KtorServerTracingBuilderKt; +import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTelemetryBuilder; +import io.opentelemetry.instrumentation.ktor.v3_0.server.KtorServerTelemetryBuilderKt; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; @@ -41,14 +41,14 @@ public static class ConstructorAdvice { @Advice.OnMethodExit public static void onExit(@Advice.FieldValue("_applicationInstance") Application application) { ApplicationPluginKt.install( - application, KtorServerTracingBuilderKt.getKtorServerTracing(), new SetupFunction()); + application, KtorServerTelemetryBuilderKt.getKtorServerTelemetry(), new SetupFunction()); } } - public static class SetupFunction implements Function1 { + public static class SetupFunction implements Function1 { @Override - public Unit invoke(AbstractKtorServerTracingBuilder builder) { + public Unit invoke(AbstractKtorServerTelemetryBuilder builder) { builder.setOpenTelemetry(GlobalOpenTelemetry.get()); KtorBuilderUtil.serverBuilderExtractor.invoke(builder).configure(AgentCommonConfig.get()); return Unit.INSTANCE; diff --git a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetry.kt b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetry.kt new file mode 100644 index 000000000000..d15f78fc3c80 --- /dev/null +++ b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetry.kt @@ -0,0 +1,33 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.v3_0.client + +import io.ktor.client.* +import io.ktor.client.plugins.* +import io.ktor.client.request.* +import io.ktor.client.statement.* +import io.ktor.util.* +import io.opentelemetry.context.propagation.ContextPropagators +import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter +import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTelemetry +import io.opentelemetry.instrumentation.ktor.internal.KtorClientTelemetryUtil + +class KtorClientTelemetry internal constructor( + instrumenter: Instrumenter, + propagators: ContextPropagators +) : AbstractKtorClientTelemetry(instrumenter, propagators) { + + companion object : HttpClientPlugin { + + override val key = AttributeKey("OpenTelemetry") + + override fun prepare(block: KtorClientTelemetryBuilder.() -> Unit) = KtorClientTelemetryBuilder().apply(block).build() + + override fun install(plugin: KtorClientTelemetry, scope: HttpClient) { + KtorClientTelemetryUtil.install(plugin, scope) + } + } +} diff --git a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetryBuilder.kt new file mode 100644 index 000000000000..793a3e81becf --- /dev/null +++ b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetryBuilder.kt @@ -0,0 +1,17 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.v3_0.client + +import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.v3_0.InstrumentationProperties.INSTRUMENTATION_NAME + +class KtorClientTelemetryBuilder : AbstractKtorClientTelemetryBuilder(INSTRUMENTATION_NAME) { + + internal fun build(): KtorClientTelemetry = KtorClientTelemetry( + instrumenter = clientBuilder.build(), + propagators = getOpenTelemetry().propagators, + ) +} diff --git a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTracing.kt b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTracing.kt index d5bf578cc56c..623e31c5693c 100644 --- a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTracing.kt +++ b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTracing.kt @@ -15,6 +15,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTracing import io.opentelemetry.instrumentation.ktor.internal.KtorClientTracingUtil +@Deprecated("Use KtorClientTelemetry instead", ReplaceWith("KtorClientTelemetry")) class KtorClientTracing internal constructor( instrumenter: Instrumenter, propagators: ContextPropagators diff --git a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTracingBuilder.kt b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTracingBuilder.kt index 6f68939d9f06..64134a656a27 100644 --- a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTracingBuilder.kt +++ b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTracingBuilder.kt @@ -8,6 +8,7 @@ package io.opentelemetry.instrumentation.ktor.v3_0.client import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTracingBuilder import io.opentelemetry.instrumentation.ktor.v3_0.InstrumentationProperties.INSTRUMENTATION_NAME +@Deprecated("Use KtorClientTelemetryBuilder instead", ReplaceWith("KtorClientTelemetryBuilder")) class KtorClientTracingBuilder : AbstractKtorClientTracingBuilder(INSTRUMENTATION_NAME) { internal fun build(): KtorClientTracing = KtorClientTracing( diff --git a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTelemetryBuilder.kt b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTelemetryBuilder.kt new file mode 100644 index 000000000000..a344e98a7593 --- /dev/null +++ b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTelemetryBuilder.kt @@ -0,0 +1,29 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.v3_0.server + +import io.ktor.server.application.* +import io.ktor.server.routing.* +import io.opentelemetry.context.Context +import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute +import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource +import io.opentelemetry.instrumentation.ktor.internal.KtorServerTelemetryUtil +import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.v3_0.InstrumentationProperties.INSTRUMENTATION_NAME + +class KtorServerTelemetryBuilder internal constructor( + instrumentationName: String +) : AbstractKtorServerTelemetryBuilder(instrumentationName) + +val KtorServerTelemetry = createRouteScopedPlugin("OpenTelemetry", { KtorServerTelemetryBuilder(INSTRUMENTATION_NAME) }) { + require(pluginConfig.isOpenTelemetryInitialized()) { "OpenTelemetry must be set" } + + KtorServerTelemetryUtil.configureTelemetry(pluginConfig, application) + + application.monitor.subscribe(RoutingRoot.RoutingCallStarted) { call -> + HttpServerRoute.update(Context.current(), HttpServerRouteSource.SERVER, { _, arg -> arg.route.parent.toString() }, call) + } +} diff --git a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTracingBuilder.kt b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTracingBuilder.kt index a086f7473fd8..be04c921979e 100644 --- a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTracingBuilder.kt +++ b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTracingBuilder.kt @@ -14,6 +14,7 @@ import io.opentelemetry.instrumentation.ktor.internal.KtorServerTracingUtil import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTracingBuilder import io.opentelemetry.instrumentation.ktor.v3_0.InstrumentationProperties.INSTRUMENTATION_NAME +@Deprecated("Use KtorServerTelemetryBuilder instead", ReplaceWith("KtorServerTelemetryBuilder")) class KtorServerTracingBuilder internal constructor( instrumentationName: String ) : AbstractKtorServerTracingBuilder(instrumentationName) From 77012edd2c370c814dd95344875b6016413e64be Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Mon, 9 Dec 2024 14:18:15 -0800 Subject: [PATCH 02/24] Fix javadoc todo --- .../instrumentation/ktor/client/internal/Experimental.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/internal/Experimental.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/internal/Experimental.kt index 7610945d38c1..501ea84468d6 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/internal/Experimental.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/internal/Experimental.kt @@ -12,11 +12,10 @@ import java.util.logging.Level import java.util.logging.Logger /** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. + * This class is internal and experimental. Its APIs are unstable and can change at any time. Its + * APIs (or a version of them) may be promoted to the public stable API in the future, but no + * guarantees are made. */ -// TODO (trask) update the above javadoc similar to -// https://github.com/open-telemetry/opentelemetry-java/pull/6886 class Experimental { companion object { From 2c082228f13ed84e11c7a77574337d62dccdd1ec Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Mon, 9 Dec 2024 14:47:27 -0800 Subject: [PATCH 03/24] Move under v2_0.common --- .../{ => v2_0/common}/client/AbstractKtorClientTelemetry.kt | 2 +- .../common}/client/AbstractKtorClientTelemetryBuilder.kt | 4 ++-- .../{ => v2_0/common}/client/AbstractKtorClientTracing.kt | 2 +- .../common}/client/AbstractKtorClientTracingBuilder.kt | 4 ++-- .../common}/client/KtorHttpClientAttributesGetter.kt | 2 +- .../ktor/{ => v2_0/common}/client/KtorHttpHeadersSetter.kt | 2 +- .../ktor/{ => v2_0/common}/client/internal/Experimental.kt | 4 ++-- .../ktor/{ => v2_0/common}/internal/KtorBuilderUtil.kt | 2 +- .../ktor/{ => v2_0/common}/internal/KtorBuilderUtilOld.kt | 6 +++--- .../{ => v2_0/common}/internal/KtorClientTelemetryUtil.kt | 2 +- .../{ => v2_0/common}/internal/KtorClientTracingUtil.kt | 2 +- .../{ => v2_0/common}/internal/KtorServerTelemetryUtil.kt | 2 +- .../ktor/{ => v2_0/common}/internal/KtorServerTracer.kt | 2 +- .../{ => v2_0/common}/internal/KtorServerTracingUtil.kt | 2 +- .../common}/server/AbstractKtorServerTelemetryBuilder.kt | 2 +- .../common}/server/AbstractKtorServerTracingBuilder.kt | 2 +- .../{ => v2_0/common}/server/ApplicationRequestGetter.kt | 2 +- .../common}/server/KtorHttpServerAttributesGetter.kt | 2 +- .../instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt | 2 +- .../ktor/v2_0/client/KtorClientTelemetryBuilder.kt | 2 +- .../instrumentation/ktor/v2_0/client/KtorClientTracing.kt | 2 +- .../ktor/v2_0/client/KtorClientTracingBuilder.kt | 2 +- .../ktor/v2_0/server/KtorServerTelemetryBuilder.kt | 2 +- .../ktor/v2_0/server/KtorServerTracingBuilder.kt | 2 +- .../ktor/v2_0/client/AbstractKtorHttpClientTest.kt | 5 ++++- .../ktor/v2_0/client/KtorHttpClientSingleConnection.kt | 1 - .../ktor/v3_0/client/KtorClientTracingBuilder.kt | 2 +- 27 files changed, 34 insertions(+), 32 deletions(-) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/{ => v2_0/common}/client/AbstractKtorClientTelemetry.kt (95%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/{ => v2_0/common}/client/AbstractKtorClientTelemetryBuilder.kt (96%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/{ => v2_0/common}/client/AbstractKtorClientTracing.kt (95%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/{ => v2_0/common}/client/AbstractKtorClientTracingBuilder.kt (97%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/{ => v2_0/common}/client/KtorHttpClientAttributesGetter.kt (95%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/{ => v2_0/common}/client/KtorHttpHeadersSetter.kt (85%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/{ => v2_0/common}/client/internal/Experimental.kt (90%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/{ => v2_0/common}/internal/KtorBuilderUtil.kt (94%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/{ => v2_0/common}/internal/KtorBuilderUtilOld.kt (78%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/{ => v2_0/common}/internal/KtorClientTelemetryUtil.kt (97%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/{ => v2_0/common}/internal/KtorClientTracingUtil.kt (97%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/{ => v2_0/common}/internal/KtorServerTelemetryUtil.kt (97%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/{ => v2_0/common}/internal/KtorServerTracer.kt (92%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/{ => v2_0/common}/internal/KtorServerTracingUtil.kt (97%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/{ => v2_0/common}/server/AbstractKtorServerTelemetryBuilder.kt (99%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/{ => v2_0/common}/server/AbstractKtorServerTracingBuilder.kt (99%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/{ => v2_0/common}/server/ApplicationRequestGetter.kt (88%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/{ => v2_0/common}/server/KtorHttpServerAttributesGetter.kt (96%) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTelemetry.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetry.kt similarity index 95% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTelemetry.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetry.kt index cfff0ef78119..fe7dffce7c1e 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTelemetry.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetry.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.client +package io.opentelemetry.instrumentation.ktor.v2_0.common.client import io.ktor.client.call.* import io.ktor.client.request.* diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt similarity index 96% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTelemetryBuilder.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt index eddeec494faa..0b5fddce6e09 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.client +package io.opentelemetry.instrumentation.ktor.v2_0.common.client import io.ktor.client.request.* import io.ktor.client.statement.* @@ -13,7 +13,7 @@ import io.opentelemetry.api.common.AttributesBuilder import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor -import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtil +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil abstract class AbstractKtorClientTelemetryBuilder( private val instrumentationName: String diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTracing.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTracing.kt similarity index 95% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTracing.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTracing.kt index 0e1c099e4e7e..99d4f861622d 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTracing.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTracing.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.client +package io.opentelemetry.instrumentation.ktor.v2_0.common.client import io.ktor.client.call.* import io.ktor.client.request.* diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTracingBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTracingBuilder.kt similarity index 97% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTracingBuilder.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTracingBuilder.kt index 410bacbd4340..7940ac5f583a 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/AbstractKtorClientTracingBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTracingBuilder.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.client +package io.opentelemetry.instrumentation.ktor.v2_0.common.client import io.ktor.client.request.* import io.ktor.client.statement.* @@ -13,7 +13,7 @@ import io.opentelemetry.api.common.AttributesBuilder import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor -import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtilOld +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtilOld @Deprecated("Use AbstractKtorClientTelemetryBuilder instead", ReplaceWith("AbstractKtorClientTelemetryBuilder")) abstract class AbstractKtorClientTracingBuilder( diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/KtorHttpClientAttributesGetter.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/KtorHttpClientAttributesGetter.kt similarity index 95% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/KtorHttpClientAttributesGetter.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/KtorHttpClientAttributesGetter.kt index db1a9d1a0f0b..9d4a739dbae4 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/KtorHttpClientAttributesGetter.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/KtorHttpClientAttributesGetter.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.client +package io.opentelemetry.instrumentation.ktor.v2_0.common.client import io.ktor.client.request.* import io.ktor.client.statement.* diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/KtorHttpHeadersSetter.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/KtorHttpHeadersSetter.kt similarity index 85% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/KtorHttpHeadersSetter.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/KtorHttpHeadersSetter.kt index d6be22087a26..c04de9e9352e 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/KtorHttpHeadersSetter.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/KtorHttpHeadersSetter.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.client +package io.opentelemetry.instrumentation.ktor.v2_0.common.client import io.ktor.client.request.HttpRequestBuilder import io.opentelemetry.context.propagation.TextMapSetter diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/internal/Experimental.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt similarity index 90% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/internal/Experimental.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt index 501ea84468d6..c1e6c8da7de2 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/client/internal/Experimental.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt @@ -3,9 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.client.internal +package io.opentelemetry.instrumentation.ktor.v2_0.common.client.internal -import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetryBuilder import java.lang.reflect.InvocationTargetException import java.lang.reflect.Method import java.util.logging.Level diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorBuilderUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorBuilderUtil.kt similarity index 94% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorBuilderUtil.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorBuilderUtil.kt index ac3ee94db3fa..53eb90d63733 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorBuilderUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorBuilderUtil.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.internal +package io.opentelemetry.instrumentation.ktor.v2_0.common.internal import io.ktor.client.request.* import io.ktor.client.statement.* diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorBuilderUtilOld.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorBuilderUtilOld.kt similarity index 78% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorBuilderUtilOld.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorBuilderUtilOld.kt index 6e00c3d4a98d..9154c7f7cd60 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorBuilderUtilOld.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorBuilderUtilOld.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.internal +package io.opentelemetry.instrumentation.ktor.v2_0.common.internal import io.ktor.client.request.* import io.ktor.client.statement.* @@ -11,8 +11,8 @@ import io.ktor.server.request.* import io.ktor.server.response.* import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder -import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTracingBuilder -import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTracingBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTracingBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTracingBuilder /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorClientTelemetryUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTelemetryUtil.kt similarity index 97% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorClientTelemetryUtil.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTelemetryUtil.kt index 630f4bb14e2c..6d39551bb04d 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorClientTelemetryUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTelemetryUtil.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.internal +package io.opentelemetry.instrumentation.ktor.v2_0.common.internal import io.ktor.client.* import io.ktor.client.request.* diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorClientTracingUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTracingUtil.kt similarity index 97% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorClientTracingUtil.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTracingUtil.kt index 4ed1d6d3fea1..bc0a3d71cf6c 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorClientTracingUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTracingUtil.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.internal +package io.opentelemetry.instrumentation.ktor.v2_0.common.internal import io.ktor.client.* import io.ktor.client.request.* diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorServerTelemetryUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt similarity index 97% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorServerTelemetryUtil.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt index 7ec23c7923c5..2748a08519cb 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorServerTelemetryUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.internal +package io.opentelemetry.instrumentation.ktor.v2_0.common.internal import io.ktor.server.application.* import io.ktor.server.request.* diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorServerTracer.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracer.kt similarity index 92% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorServerTracer.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracer.kt index 2226f4169a94..7e6f5af975a8 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorServerTracer.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracer.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.internal +package io.opentelemetry.instrumentation.ktor.v2_0.common.internal import io.ktor.server.application.* import io.ktor.server.request.* diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorServerTracingUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracingUtil.kt similarity index 97% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorServerTracingUtil.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracingUtil.kt index 975803e11ee2..d88d70194eb3 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/internal/KtorServerTracingUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracingUtil.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.internal +package io.opentelemetry.instrumentation.ktor.v2_0.common.internal import io.ktor.server.application.* import io.ktor.server.request.* diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/AbstractKtorServerTelemetryBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt similarity index 99% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/AbstractKtorServerTelemetryBuilder.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt index 2195e52584d0..0858b326a1ed 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/AbstractKtorServerTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.server +package io.opentelemetry.instrumentation.ktor.v2_0.common.server import io.ktor.http.* import io.ktor.server.request.* diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/AbstractKtorServerTracingBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTracingBuilder.kt similarity index 99% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/AbstractKtorServerTracingBuilder.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTracingBuilder.kt index b3d3217d9a9f..817f745f060e 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/AbstractKtorServerTracingBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTracingBuilder.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.server +package io.opentelemetry.instrumentation.ktor.v2_0.common.server import io.ktor.http.* import io.ktor.server.request.* diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/ApplicationRequestGetter.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/ApplicationRequestGetter.kt similarity index 88% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/ApplicationRequestGetter.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/ApplicationRequestGetter.kt index 053436977ef2..cfe7e0b35a11 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/ApplicationRequestGetter.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/ApplicationRequestGetter.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.server +package io.opentelemetry.instrumentation.ktor.v2_0.common.server import io.ktor.server.request.* import io.opentelemetry.context.propagation.TextMapGetter diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/KtorHttpServerAttributesGetter.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/KtorHttpServerAttributesGetter.kt similarity index 96% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/KtorHttpServerAttributesGetter.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/KtorHttpServerAttributesGetter.kt index 9471aa44f64b..d49daead2c9d 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/server/KtorHttpServerAttributesGetter.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/KtorHttpServerAttributesGetter.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.server +package io.opentelemetry.instrumentation.ktor.v2_0.common.server import io.ktor.server.plugins.* import io.ktor.server.request.* diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt index 69e25b2349b9..d750fe9ed436 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt @@ -12,8 +12,8 @@ import io.ktor.client.statement.* import io.ktor.util.* import io.opentelemetry.context.propagation.ContextPropagators import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter -import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTelemetry import io.opentelemetry.instrumentation.ktor.internal.KtorClientTelemetryUtil +import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetry class KtorClientTelemetry internal constructor( instrumenter: Instrumenter, diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt index 38abca4a477a..13c2839e6724 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt @@ -5,8 +5,8 @@ package io.opentelemetry.instrumentation.ktor.v2_0.client -import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTelemetryBuilder import io.opentelemetry.instrumentation.ktor.v2_0.InstrumentationProperties.INSTRUMENTATION_NAME +import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetryBuilder class KtorClientTelemetryBuilder : AbstractKtorClientTelemetryBuilder(INSTRUMENTATION_NAME) { diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracing.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracing.kt index b7e4b17e927e..db34a2582165 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracing.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracing.kt @@ -12,8 +12,8 @@ import io.ktor.client.statement.* import io.ktor.util.* import io.opentelemetry.context.propagation.ContextPropagators import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter -import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTracing import io.opentelemetry.instrumentation.ktor.internal.KtorClientTracingUtil +import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTracing @Deprecated("Use KtorClientTelemetry instead", ReplaceWith("KtorClientTelemetry")) class KtorClientTracing internal constructor( diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracingBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracingBuilder.kt index fc0b04d705cb..706852a3178a 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracingBuilder.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracingBuilder.kt @@ -5,8 +5,8 @@ package io.opentelemetry.instrumentation.ktor.v2_0.client -import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTracingBuilder import io.opentelemetry.instrumentation.ktor.v2_0.InstrumentationProperties.INSTRUMENTATION_NAME +import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTracingBuilder @Deprecated("Use KtorClientTelemetryBuilder instead", ReplaceWith("KtorClientTelemetryBuilder")) class KtorClientTracingBuilder : AbstractKtorClientTracingBuilder(INSTRUMENTATION_NAME) { diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt index aba80c987944..c0357857db47 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt @@ -11,8 +11,8 @@ import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource import io.opentelemetry.instrumentation.ktor.internal.KtorServerTelemetryUtil -import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTelemetryBuilder import io.opentelemetry.instrumentation.ktor.v2_0.InstrumentationProperties.INSTRUMENTATION_NAME +import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTelemetryBuilder class KtorServerTelemetryBuilder internal constructor( instrumentationName: String diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracingBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracingBuilder.kt index 811a4d862f91..23f6c1f1006b 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracingBuilder.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracingBuilder.kt @@ -11,8 +11,8 @@ import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource import io.opentelemetry.instrumentation.ktor.internal.KtorServerTracingUtil -import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTracingBuilder import io.opentelemetry.instrumentation.ktor.v2_0.InstrumentationProperties.INSTRUMENTATION_NAME +import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTracingBuilder @Deprecated("Use KtorServerTelemetryBuilder instead", ReplaceWith("KtorServerTelemetryBuilder")) class KtorServerTracingBuilder internal constructor( diff --git a/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/AbstractKtorHttpClientTest.kt b/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/AbstractKtorHttpClientTest.kt index 991e32f347f6..25984db55484 100644 --- a/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/AbstractKtorHttpClientTest.kt +++ b/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/AbstractKtorHttpClientTest.kt @@ -17,7 +17,10 @@ import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES import io.opentelemetry.semconv.NetworkAttributes -import kotlinx.coroutines.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.AfterAll import java.net.URI diff --git a/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorHttpClientSingleConnection.kt b/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorHttpClientSingleConnection.kt index 2396d62bb6b1..4e61403a4bdf 100644 --- a/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorHttpClientSingleConnection.kt +++ b/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorHttpClientSingleConnection.kt @@ -6,7 +6,6 @@ package io.opentelemetry.instrumentation.ktor.v2_0.client import io.ktor.client.* -import io.ktor.client.engine.cio.* import io.ktor.client.request.* import io.opentelemetry.instrumentation.testing.junit.http.SingleConnection import kotlinx.coroutines.runBlocking diff --git a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTracingBuilder.kt b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTracingBuilder.kt index 64134a656a27..b4787662b8e2 100644 --- a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTracingBuilder.kt +++ b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTracingBuilder.kt @@ -5,7 +5,7 @@ package io.opentelemetry.instrumentation.ktor.v3_0.client -import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTracingBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTracingBuilder import io.opentelemetry.instrumentation.ktor.v3_0.InstrumentationProperties.INSTRUMENTATION_NAME @Deprecated("Use KtorClientTelemetryBuilder instead", ReplaceWith("KtorClientTelemetryBuilder")) From ab1bf85747cd122ace77ff66df88877b50d7f9fe Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Mon, 9 Dec 2024 19:00:43 -0800 Subject: [PATCH 04/24] fix --- .../v2_0/common/server/AbstractKtorServerTracingBuilder.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTracingBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTracingBuilder.kt index 817f745f060e..64c67b4d70ff 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTracingBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTracingBuilder.kt @@ -17,13 +17,13 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusBuilder import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor -import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtil +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtilOld @Deprecated("Use AbstractKtorServerTelemetryBuilder instead", ReplaceWith("AbstractKtorServerTelemetryBuilder")) abstract class AbstractKtorServerTracingBuilder(private val instrumentationName: String) { companion object { init { - KtorBuilderUtil.serverBuilderExtractor = { it.serverBuilder } + KtorBuilderUtilOld.serverBuilderExtractor = { it.serverBuilder } } } From 959499eb775e2146e97984777ebe48fac089be12 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Mon, 9 Dec 2024 19:13:36 -0800 Subject: [PATCH 05/24] -fix --- .../ktor/v2_0/common/internal/KtorBuilderUtil.kt | 4 ++-- .../ktor/v2_0/common/internal/KtorClientTelemetryUtil.kt | 2 +- .../ktor/v2_0/common/internal/KtorClientTracingUtil.kt | 2 +- .../ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt | 4 ++-- .../ktor/v2_0/common/internal/KtorServerTracingUtil.kt | 4 ++-- .../v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt | 2 +- .../instrumentation/ktor/v2_0/HttpClientInstrumentation.java | 2 +- .../instrumentation/ktor/v2_0/ServerInstrumentation.java | 4 ++-- .../instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt | 2 +- .../instrumentation/ktor/v2_0/client/KtorClientTracing.kt | 2 +- .../ktor/v2_0/server/KtorServerTelemetryBuilder.kt | 2 +- .../ktor/v2_0/server/KtorServerTracingBuilder.kt | 2 +- .../instrumentation/ktor/v3_0/HttpClientInstrumentation.java | 2 +- .../instrumentation/ktor/v3_0/ServerInstrumentation.java | 4 ++-- .../instrumentation/ktor/v3_0/client/KtorClientTelemetry.kt | 4 ++-- .../ktor/v3_0/client/KtorClientTelemetryBuilder.kt | 2 +- .../instrumentation/ktor/v3_0/client/KtorClientTracing.kt | 4 ++-- .../ktor/v3_0/server/KtorServerTelemetryBuilder.kt | 4 ++-- .../ktor/v3_0/server/KtorServerTracingBuilder.kt | 4 ++-- 19 files changed, 28 insertions(+), 28 deletions(-) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorBuilderUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorBuilderUtil.kt index 53eb90d63733..d916a48c4487 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorBuilderUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorBuilderUtil.kt @@ -11,8 +11,8 @@ import io.ktor.server.request.* import io.ktor.server.response.* import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder -import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTelemetryBuilder -import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTelemetryBuilder /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTelemetryUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTelemetryUtil.kt index 6d39551bb04d..52408fa0f9a6 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTelemetryUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTelemetryUtil.kt @@ -13,7 +13,7 @@ import io.ktor.util.pipeline.* import io.opentelemetry.context.Context import io.opentelemetry.extension.kotlin.asContextElement import io.opentelemetry.instrumentation.api.semconv.http.HttpClientRequestResendCount -import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTelemetry +import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetry import kotlinx.coroutines.InternalCoroutinesApi import kotlinx.coroutines.job import kotlinx.coroutines.launch diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTracingUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTracingUtil.kt index bc0a3d71cf6c..45e0f1d22559 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTracingUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTracingUtil.kt @@ -13,7 +13,7 @@ import io.ktor.util.pipeline.* import io.opentelemetry.context.Context import io.opentelemetry.extension.kotlin.asContextElement import io.opentelemetry.instrumentation.api.semconv.http.HttpClientRequestResendCount -import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTracing +import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTracing import kotlinx.coroutines.InternalCoroutinesApi import kotlinx.coroutines.job import kotlinx.coroutines.launch diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt index 2748a08519cb..a99346b33d1a 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt @@ -15,8 +15,8 @@ import io.opentelemetry.extension.kotlin.asContextElement import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor import io.opentelemetry.instrumentation.api.internal.InstrumenterUtil -import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTelemetryBuilder -import io.opentelemetry.instrumentation.ktor.server.ApplicationRequestGetter +import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.common.server.ApplicationRequestGetter import kotlinx.coroutines.withContext /** diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracingUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracingUtil.kt index d88d70194eb3..1834e7c487e6 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracingUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracingUtil.kt @@ -15,8 +15,8 @@ import io.opentelemetry.extension.kotlin.asContextElement import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor import io.opentelemetry.instrumentation.api.internal.InstrumenterUtil -import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTracingBuilder -import io.opentelemetry.instrumentation.ktor.server.ApplicationRequestGetter +import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTracingBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.common.server.ApplicationRequestGetter import kotlinx.coroutines.withContext /** diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt index 0858b326a1ed..19d6ae9111a7 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt @@ -17,7 +17,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusBuilder import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor -import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtil +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationName: String) { companion object { diff --git a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java index f1c116177394..51e3e3ebcfc7 100644 --- a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java +++ b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java @@ -13,7 +13,7 @@ import io.ktor.client.HttpClientConfig; import io.ktor.client.engine.HttpClientEngineConfig; import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtil; +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil; import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTelemetry; import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTelemetryBuilder; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; diff --git a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/ServerInstrumentation.java b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/ServerInstrumentation.java index 94463567087a..6f9611499bec 100644 --- a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/ServerInstrumentation.java +++ b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/ServerInstrumentation.java @@ -11,8 +11,8 @@ import io.ktor.server.application.Application; import io.ktor.server.application.ApplicationPluginKt; import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtil; -import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTelemetryBuilder; +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil; +import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTelemetryBuilder; import io.opentelemetry.instrumentation.ktor.v2_0.server.KtorServerTelemetryBuilderKt; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt index d750fe9ed436..ba65bddc8132 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt @@ -12,7 +12,7 @@ import io.ktor.client.statement.* import io.ktor.util.* import io.opentelemetry.context.propagation.ContextPropagators import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter -import io.opentelemetry.instrumentation.ktor.internal.KtorClientTelemetryUtil +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorClientTelemetryUtil import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetry class KtorClientTelemetry internal constructor( diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracing.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracing.kt index db34a2582165..960a1aff21cd 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracing.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracing.kt @@ -12,7 +12,7 @@ import io.ktor.client.statement.* import io.ktor.util.* import io.opentelemetry.context.propagation.ContextPropagators import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter -import io.opentelemetry.instrumentation.ktor.internal.KtorClientTracingUtil +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorClientTracingUtil import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTracing @Deprecated("Use KtorClientTelemetry instead", ReplaceWith("KtorClientTelemetry")) diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt index c0357857db47..8d68991a61a0 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt @@ -10,7 +10,7 @@ import io.ktor.server.routing.* import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource -import io.opentelemetry.instrumentation.ktor.internal.KtorServerTelemetryUtil +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorServerTelemetryUtil import io.opentelemetry.instrumentation.ktor.v2_0.InstrumentationProperties.INSTRUMENTATION_NAME import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTelemetryBuilder diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracingBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracingBuilder.kt index 23f6c1f1006b..11c7178fa8c3 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracingBuilder.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracingBuilder.kt @@ -10,7 +10,7 @@ import io.ktor.server.routing.* import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource -import io.opentelemetry.instrumentation.ktor.internal.KtorServerTracingUtil +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorServerTracingUtil import io.opentelemetry.instrumentation.ktor.v2_0.InstrumentationProperties.INSTRUMENTATION_NAME import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTracingBuilder diff --git a/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/HttpClientInstrumentation.java b/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/HttpClientInstrumentation.java index 8920f0d249ab..0ab6f7609276 100644 --- a/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/HttpClientInstrumentation.java +++ b/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/HttpClientInstrumentation.java @@ -13,7 +13,7 @@ import io.ktor.client.HttpClientConfig; import io.ktor.client.engine.HttpClientEngineConfig; import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtil; +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil; import io.opentelemetry.instrumentation.ktor.v3_0.client.KtorClientTelemetry; import io.opentelemetry.instrumentation.ktor.v3_0.client.KtorClientTelemetryBuilder; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; diff --git a/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/ServerInstrumentation.java b/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/ServerInstrumentation.java index eb0639c54dbb..b4b5a0832256 100644 --- a/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/ServerInstrumentation.java +++ b/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/ServerInstrumentation.java @@ -11,8 +11,8 @@ import io.ktor.server.application.Application; import io.ktor.server.application.ApplicationPluginKt; import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.ktor.internal.KtorBuilderUtil; -import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTelemetryBuilder; +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil; +import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTelemetryBuilder; import io.opentelemetry.instrumentation.ktor.v3_0.server.KtorServerTelemetryBuilderKt; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; diff --git a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetry.kt b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetry.kt index d15f78fc3c80..aa0f2d4ecf88 100644 --- a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetry.kt +++ b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetry.kt @@ -12,8 +12,8 @@ import io.ktor.client.statement.* import io.ktor.util.* import io.opentelemetry.context.propagation.ContextPropagators import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter -import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTelemetry -import io.opentelemetry.instrumentation.ktor.internal.KtorClientTelemetryUtil +import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetry +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorClientTelemetryUtil class KtorClientTelemetry internal constructor( instrumenter: Instrumenter, diff --git a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetryBuilder.kt index 793a3e81becf..f154aaca31ef 100644 --- a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetryBuilder.kt @@ -5,7 +5,7 @@ package io.opentelemetry.instrumentation.ktor.v3_0.client -import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetryBuilder import io.opentelemetry.instrumentation.ktor.v3_0.InstrumentationProperties.INSTRUMENTATION_NAME class KtorClientTelemetryBuilder : AbstractKtorClientTelemetryBuilder(INSTRUMENTATION_NAME) { diff --git a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTracing.kt b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTracing.kt index 623e31c5693c..b63c4f6974ad 100644 --- a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTracing.kt +++ b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTracing.kt @@ -12,8 +12,8 @@ import io.ktor.client.statement.* import io.ktor.util.* import io.opentelemetry.context.propagation.ContextPropagators import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter -import io.opentelemetry.instrumentation.ktor.client.AbstractKtorClientTracing -import io.opentelemetry.instrumentation.ktor.internal.KtorClientTracingUtil +import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTracing +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorClientTracingUtil @Deprecated("Use KtorClientTelemetry instead", ReplaceWith("KtorClientTelemetry")) class KtorClientTracing internal constructor( diff --git a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTelemetryBuilder.kt b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTelemetryBuilder.kt index a344e98a7593..43c4ec92952a 100644 --- a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTelemetryBuilder.kt @@ -10,8 +10,8 @@ import io.ktor.server.routing.* import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource -import io.opentelemetry.instrumentation.ktor.internal.KtorServerTelemetryUtil -import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorServerTelemetryUtil +import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTelemetryBuilder import io.opentelemetry.instrumentation.ktor.v3_0.InstrumentationProperties.INSTRUMENTATION_NAME class KtorServerTelemetryBuilder internal constructor( diff --git a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTracingBuilder.kt b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTracingBuilder.kt index be04c921979e..e77e5487c866 100644 --- a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTracingBuilder.kt +++ b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTracingBuilder.kt @@ -10,8 +10,8 @@ import io.ktor.server.routing.* import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource -import io.opentelemetry.instrumentation.ktor.internal.KtorServerTracingUtil -import io.opentelemetry.instrumentation.ktor.server.AbstractKtorServerTracingBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorServerTracingUtil +import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTracingBuilder import io.opentelemetry.instrumentation.ktor.v3_0.InstrumentationProperties.INSTRUMENTATION_NAME @Deprecated("Use KtorServerTelemetryBuilder instead", ReplaceWith("KtorServerTelemetryBuilder")) From 3dc49f81d93165f227a3902a8516f4e5673f315a Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Mon, 9 Dec 2024 19:27:51 -0800 Subject: [PATCH 06/24] spotless --- .../instrumentation/ktor/v2_0/HttpClientInstrumentation.java | 2 +- .../instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt | 2 +- .../instrumentation/ktor/v2_0/client/KtorClientTracing.kt | 2 +- .../ktor/v2_0/server/KtorServerTelemetryBuilder.kt | 2 +- .../ktor/v2_0/server/KtorServerTracingBuilder.kt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java index 51e3e3ebcfc7..65e8ded4e967 100644 --- a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java +++ b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java @@ -13,9 +13,9 @@ import io.ktor.client.HttpClientConfig; import io.ktor.client.engine.HttpClientEngineConfig; import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil; import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTelemetry; import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTelemetryBuilder; +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt index ba65bddc8132..3963999e9b63 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt @@ -12,8 +12,8 @@ import io.ktor.client.statement.* import io.ktor.util.* import io.opentelemetry.context.propagation.ContextPropagators import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter -import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorClientTelemetryUtil import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetry +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorClientTelemetryUtil class KtorClientTelemetry internal constructor( instrumenter: Instrumenter, diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracing.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracing.kt index 960a1aff21cd..d9dcf9796f67 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracing.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracing.kt @@ -12,8 +12,8 @@ import io.ktor.client.statement.* import io.ktor.util.* import io.opentelemetry.context.propagation.ContextPropagators import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter -import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorClientTracingUtil import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTracing +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorClientTracingUtil @Deprecated("Use KtorClientTelemetry instead", ReplaceWith("KtorClientTelemetry")) class KtorClientTracing internal constructor( diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt index 8d68991a61a0..af6a84d9ee5e 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt @@ -10,8 +10,8 @@ import io.ktor.server.routing.* import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource -import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorServerTelemetryUtil import io.opentelemetry.instrumentation.ktor.v2_0.InstrumentationProperties.INSTRUMENTATION_NAME +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorServerTelemetryUtil import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTelemetryBuilder class KtorServerTelemetryBuilder internal constructor( diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracingBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracingBuilder.kt index 11c7178fa8c3..c82c99fccb5e 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracingBuilder.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracingBuilder.kt @@ -10,8 +10,8 @@ import io.ktor.server.routing.* import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource -import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorServerTracingUtil import io.opentelemetry.instrumentation.ktor.v2_0.InstrumentationProperties.INSTRUMENTATION_NAME +import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorServerTracingUtil import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTracingBuilder @Deprecated("Use KtorServerTelemetryBuilder instead", ReplaceWith("KtorServerTelemetryBuilder")) From 4e8bdb3c33f2a61aaf9ceb6d23afd781b49a2ade Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Mon, 9 Dec 2024 19:43:43 -0800 Subject: [PATCH 07/24] rename-var --- .../AbstractKtorClientTelemetryBuilder.kt | 16 ++++++++-------- .../common/internal/KtorServerTelemetryUtil.kt | 2 +- .../AbstractKtorServerTelemetryBuilder.kt | 18 +++++++++--------- .../v2_0/client/KtorClientTelemetryBuilder.kt | 2 +- .../v3_0/client/KtorClientTelemetryBuilder.kt | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt index 0b5fddce6e09..fd5a594cfb75 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt @@ -20,16 +20,16 @@ abstract class AbstractKtorClientTelemetryBuilder( ) { companion object { init { - KtorBuilderUtil.clientBuilderExtractor = { it.clientBuilder } + KtorBuilderUtil.clientBuilderExtractor = { it.builder } } } internal lateinit var openTelemetry: OpenTelemetry - protected lateinit var clientBuilder: DefaultHttpClientInstrumenterBuilder + protected lateinit var builder: DefaultHttpClientInstrumenterBuilder fun setOpenTelemetry(openTelemetry: OpenTelemetry) { this.openTelemetry = openTelemetry - this.clientBuilder = DefaultHttpClientInstrumenterBuilder.create( + this.builder = DefaultHttpClientInstrumenterBuilder.create( instrumentationName, openTelemetry, KtorHttpClientAttributesGetter @@ -43,13 +43,13 @@ abstract class AbstractKtorClientTelemetryBuilder( fun capturedRequestHeaders(vararg headers: String) = capturedRequestHeaders(headers.asIterable()) fun capturedRequestHeaders(headers: Iterable) { - clientBuilder.setCapturedRequestHeaders(headers.toList()) + builder.setCapturedRequestHeaders(headers.toList()) } fun capturedResponseHeaders(vararg headers: String) = capturedResponseHeaders(headers.asIterable()) fun capturedResponseHeaders(headers: Iterable) { - clientBuilder.setCapturedResponseHeaders(headers.toList()) + builder.setCapturedResponseHeaders(headers.toList()) } fun knownMethods(vararg methods: String) = knownMethods(methods.asIterable()) @@ -60,12 +60,12 @@ abstract class AbstractKtorClientTelemetryBuilder( fun knownMethods(methods: Iterable) = knownMethods(methods.map { it.value }) fun knownMethods(methods: Iterable) { - clientBuilder.setKnownMethods(methods.toSet()) + builder.setKnownMethods(methods.toSet()) } fun attributeExtractor(extractorBuilder: ExtractorBuilder.() -> Unit = {}) { val builder = ExtractorBuilder().apply(extractorBuilder).build() - this.clientBuilder.addAttributeExtractor( + this.builder.addAttributeExtractor( object : AttributesExtractor { override fun onStart(attributes: AttributesBuilder, parentContext: Context, request: HttpRequestData) { builder.onStart(OnStartData(attributes, parentContext, request)) @@ -116,6 +116,6 @@ abstract class AbstractKtorClientTelemetryBuilder( * Experimental#setEmitExperimentalHttpClientMetrics(AbstractKtorClientTelemetryBuilder, boolean)}. */ internal fun emitExperimentalHttpClientMetrics() { - clientBuilder.setEmitExperimentalHttpClientMetrics(true) + builder.setEmitExperimentalHttpClientMetrics(true) } } diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt index a99346b33d1a..02900444202d 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt @@ -75,7 +75,7 @@ object KtorServerTelemetryUtil { private fun instrumenter(builder: AbstractKtorServerTelemetryBuilder): Instrumenter { return InstrumenterUtil.buildUpstreamInstrumenter( - builder.serverBuilder.instrumenterBuilder(), + builder.builder.instrumenterBuilder(), ApplicationRequestGetter, builder.spanKindExtractor(SpanKindExtractor.alwaysServer()) ) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt index 19d6ae9111a7..62b1a9633b1f 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt @@ -22,17 +22,17 @@ import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUti abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationName: String) { companion object { init { - KtorBuilderUtil.serverBuilderExtractor = { it.serverBuilder } + KtorBuilderUtil.serverBuilderExtractor = { it.builder } } } - internal lateinit var serverBuilder: DefaultHttpServerInstrumenterBuilder + internal lateinit var builder: DefaultHttpServerInstrumenterBuilder internal var spanKindExtractor: (SpanKindExtractor) -> SpanKindExtractor = { a -> a } fun setOpenTelemetry(openTelemetry: OpenTelemetry) { - this.serverBuilder = + this.builder = DefaultHttpServerInstrumenterBuilder.create( instrumentationName, openTelemetry, @@ -50,7 +50,7 @@ abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationNam } fun spanStatusExtractor(extract: SpanStatusData.(SpanStatusExtractor) -> Unit) { - serverBuilder.setStatusExtractor { prevExtractor -> + builder.setStatusExtractor { prevExtractor -> SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder, request: ApplicationRequest, response: ApplicationResponse?, @@ -99,7 +99,7 @@ abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationNam fun attributeExtractor(extractorBuilder: ExtractorBuilder.() -> Unit = {}) { val builder = ExtractorBuilder().apply(extractorBuilder).build() - serverBuilder.addAttributesExtractor( + this.builder.addAttributesExtractor( object : AttributesExtractor { override fun onStart(attributes: AttributesBuilder, parentContext: Context, request: ApplicationRequest) { builder.onStart(OnStartData(attributes, parentContext, request)) @@ -154,7 +154,7 @@ abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationNam fun capturedRequestHeaders(vararg headers: String) = capturedRequestHeaders(headers.asIterable()) fun capturedRequestHeaders(headers: Iterable) { - serverBuilder.setCapturedRequestHeaders(headers.toList()) + builder.setCapturedRequestHeaders(headers.toList()) } @Deprecated( @@ -166,7 +166,7 @@ abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationNam fun capturedResponseHeaders(vararg headers: String) = capturedResponseHeaders(headers.asIterable()) fun capturedResponseHeaders(headers: Iterable) { - serverBuilder.setCapturedResponseHeaders(headers.toList()) + builder.setCapturedResponseHeaders(headers.toList()) } @Deprecated( @@ -184,12 +184,12 @@ abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationNam fun knownMethods(methods: Iterable) { methods.toSet().apply { - serverBuilder.setKnownMethods(this) + builder.setKnownMethods(this) } } /** * {@link #setOpenTelemetry(OpenTelemetry)} sets the serverBuilder to a non-null value. */ - fun isOpenTelemetryInitialized(): Boolean = this::serverBuilder.isInitialized + fun isOpenTelemetryInitialized(): Boolean = this::builder.isInitialized } diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt index 13c2839e6724..6e5449f1d2ef 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt @@ -11,7 +11,7 @@ import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClie class KtorClientTelemetryBuilder : AbstractKtorClientTelemetryBuilder(INSTRUMENTATION_NAME) { internal fun build(): KtorClientTelemetry = KtorClientTelemetry( - instrumenter = clientBuilder.build(), + instrumenter = builder.build(), propagators = getOpenTelemetry().propagators, ) } diff --git a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetryBuilder.kt index f154aaca31ef..bbf21d7a8b48 100644 --- a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetryBuilder.kt @@ -11,7 +11,7 @@ import io.opentelemetry.instrumentation.ktor.v3_0.InstrumentationProperties.INST class KtorClientTelemetryBuilder : AbstractKtorClientTelemetryBuilder(INSTRUMENTATION_NAME) { internal fun build(): KtorClientTelemetry = KtorClientTelemetry( - instrumenter = clientBuilder.build(), + instrumenter = builder.build(), propagators = getOpenTelemetry().propagators, ) } From 93975470b7bbd0338ffd39f9a14d3ae0c188febd Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Mon, 9 Dec 2024 20:12:16 -0800 Subject: [PATCH 08/24] Remove deprecated from the new classes --- .../ktor/v1_0/KtorServerTelemetry.kt | 2 +- .../AbstractKtorClientTelemetryBuilder.kt | 2 +- .../AbstractKtorServerTelemetryBuilder.kt | 48 +------------------ 3 files changed, 3 insertions(+), 49 deletions(-) diff --git a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTelemetry.kt b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTelemetry.kt index 1ecdf34b18d9..d4635e557962 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTelemetry.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTelemetry.kt @@ -61,7 +61,7 @@ class KtorServerTelemetry private constructor( this.spanKindExtractor = extractor } - fun addAttributeExtractor(extractor: AttributesExtractor) { + fun addAttributesExtractor(extractor: AttributesExtractor) { builder.addAttributesExtractor(extractor) } diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt index fd5a594cfb75..7eb2f7d21cb0 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt @@ -63,7 +63,7 @@ abstract class AbstractKtorClientTelemetryBuilder( builder.setKnownMethods(methods.toSet()) } - fun attributeExtractor(extractorBuilder: ExtractorBuilder.() -> Unit = {}) { + fun attributesExtractor(extractorBuilder: ExtractorBuilder.() -> Unit = {}) { val builder = ExtractorBuilder().apply(extractorBuilder).build() this.builder.addAttributeExtractor( object : AttributesExtractor { diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt index 62b1a9633b1f..e8a3754337ab 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt @@ -40,15 +40,6 @@ abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationNam ) } - @Deprecated("Please use method `spanStatusExtractor`") - fun setStatusExtractor( - extractor: (SpanStatusExtractor) -> SpanStatusExtractor - ) { - spanStatusExtractor { prevStatusExtractor -> - extractor(prevStatusExtractor).extract(spanStatusBuilder, request, response, error) - } - } - fun spanStatusExtractor(extract: SpanStatusData.(SpanStatusExtractor) -> Unit) { builder.setStatusExtractor { prevExtractor -> SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder, @@ -70,13 +61,6 @@ abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationNam val error: Throwable? ) - @Deprecated("Please use method `spanKindExtractor`") - fun setSpanKindExtractor(extractor: (SpanKindExtractor) -> SpanKindExtractor) { - spanKindExtractor { prevSpanKindExtractor -> - extractor(prevSpanKindExtractor).extract(this) - } - } - fun spanKindExtractor(extract: ApplicationRequest.(SpanKindExtractor) -> SpanKind) { spanKindExtractor = { prevExtractor -> SpanKindExtractor { request: ApplicationRequest -> @@ -85,19 +69,7 @@ abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationNam } } - @Deprecated("Please use method `attributeExtractor`") - fun addAttributeExtractor(extractor: AttributesExtractor) { - attributeExtractor { - onStart { - extractor.onStart(attributes, parentContext, request) - } - onEnd { - extractor.onEnd(attributes, parentContext, request, response, error) - } - } - } - - fun attributeExtractor(extractorBuilder: ExtractorBuilder.() -> Unit = {}) { + fun attributesExtractor(extractorBuilder: ExtractorBuilder.() -> Unit = {}) { val builder = ExtractorBuilder().apply(extractorBuilder).build() this.builder.addAttributesExtractor( object : AttributesExtractor { @@ -145,36 +117,18 @@ abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationNam val error: Throwable? ) - @Deprecated( - "Please use method `capturedRequestHeaders`", - ReplaceWith("capturedRequestHeaders(headers)") - ) - fun setCapturedRequestHeaders(headers: List) = capturedRequestHeaders(headers) - fun capturedRequestHeaders(vararg headers: String) = capturedRequestHeaders(headers.asIterable()) fun capturedRequestHeaders(headers: Iterable) { builder.setCapturedRequestHeaders(headers.toList()) } - @Deprecated( - "Please use method `capturedResponseHeaders`", - ReplaceWith("capturedResponseHeaders(headers)") - ) - fun setCapturedResponseHeaders(headers: List) = capturedResponseHeaders(headers) - fun capturedResponseHeaders(vararg headers: String) = capturedResponseHeaders(headers.asIterable()) fun capturedResponseHeaders(headers: Iterable) { builder.setCapturedResponseHeaders(headers.toList()) } - @Deprecated( - "Please use method `knownMethods`", - ReplaceWith("knownMethods(knownMethods)") - ) - fun setKnownMethods(knownMethods: Set) = knownMethods(knownMethods) - fun knownMethods(vararg methods: String) = knownMethods(methods.asIterable()) fun knownMethods(vararg methods: HttpMethod) = knownMethods(methods.asIterable()) From 12a37b70240c2fa90bc1cc0ff92f51f8efb2304e Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 10 Dec 2024 19:35:05 -0800 Subject: [PATCH 09/24] remove reflection --- .../AbstractKtorClientTelemetryBuilder.kt | 2 + .../AbstractKtorClientTracingBuilder.kt | 4 +- .../common/client/internal/Experimental.kt | 57 +++++-------------- 3 files changed, 19 insertions(+), 44 deletions(-) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt index 7eb2f7d21cb0..bf941f6e8787 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt @@ -13,6 +13,7 @@ import io.opentelemetry.api.common.AttributesBuilder import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor +import io.opentelemetry.instrumentation.ktor.v2_0.common.client.internal.Experimental import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil abstract class AbstractKtorClientTelemetryBuilder( @@ -21,6 +22,7 @@ abstract class AbstractKtorClientTelemetryBuilder( companion object { init { KtorBuilderUtil.clientBuilderExtractor = { it.builder } + Experimental.setSetEmitExperimentalTelemetry { builder, emit -> builder.builder.setEmitExperimentalHttpClientMetrics(emit) } } } diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTracingBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTracingBuilder.kt index 7940ac5f583a..6ad219471dc2 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTracingBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTracingBuilder.kt @@ -160,14 +160,14 @@ abstract class AbstractKtorClientTracingBuilder( * * @param emitExperimentalHttpClientMetrics `true` if the experimental HTTP client metrics are to be emitted. */ - @Deprecated("Please use method `Experimental.emitExperimentalHttpClientMetrics`") + @Deprecated("Please use method `Experimental.emitExperimentalTelemetry`") fun setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics: Boolean) { if (emitExperimentalHttpClientMetrics) { emitExperimentalHttpClientMetrics() } } - @Deprecated("Please use method `Experimental.emitExperimentalHttpClientMetrics`") + @Deprecated("Please use method `Experimental.emitExperimentalTelemetry`") fun emitExperimentalHttpClientMetrics() { clientBuilder.setEmitExperimentalHttpClientMetrics(true) } diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt index c1e6c8da7de2..ccdfb198f24a 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt @@ -1,52 +1,25 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - package io.opentelemetry.instrumentation.ktor.v2_0.common.client.internal import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetryBuilder -import java.lang.reflect.InvocationTargetException -import java.lang.reflect.Method -import java.util.logging.Level -import java.util.logging.Logger - -/** - * This class is internal and experimental. Its APIs are unstable and can change at any time. Its - * APIs (or a version of them) may be promoted to the public stable API in the future, but no - * guarantees are made. - */ -class Experimental { +import java.util.function.BiConsumer - companion object { - private val logger: Logger = Logger.getLogger(Experimental::class.java.name) +class Experimental private constructor() { - private val emitExperimentalTelemetryMethod = getEmitExperimentalTelemetry() + companion object { + private var setEmitExperimentalTelemetry: BiConsumer? = null - fun setEmitExperimentalTelemetry(builder: AbstractKtorClientTelemetryBuilder?, emitExperimentalTelemetry: Boolean) { - if (emitExperimentalTelemetryMethod != null) { - try { - emitExperimentalTelemetryMethod.invoke(builder, emitExperimentalTelemetry) - } catch (e: IllegalAccessException) { - logger.log(Level.FINE, e.message, e) - } catch (e: InvocationTargetException) { - logger.log(Level.FINE, e.message, e) + fun emitExperimentalTelemetry( + builder: AbstractKtorClientTelemetryBuilder + ) { + if (setEmitExperimentalTelemetry != null) { + setEmitExperimentalTelemetry!!.accept(builder, true) + } } - } - } - private fun getEmitExperimentalTelemetry(): Method? { - try { - val method = AbstractKtorClientTelemetryBuilder::class.java.getDeclaredMethod( - "setEmitExperimentalHttpClientMetrics", - Boolean::class.javaPrimitiveType - ) - method.setAccessible(true) - return method - } catch (e: NoSuchMethodException) { - logger.log(Level.FINE, e.message, e) - return null - } + fun setSetEmitExperimentalTelemetry( + setEmitExperimentalTelemetry: BiConsumer? + ) { + Companion.setEmitExperimentalTelemetry = setEmitExperimentalTelemetry + } } - } } From 2b11a5a745b45004acd3a436b053a78dda42fb3a Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 10 Dec 2024 19:51:39 -0800 Subject: [PATCH 10/24] volatile --- .../common/client/internal/Experimental.kt | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt index ccdfb198f24a..bfeb16462916 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt @@ -5,21 +5,22 @@ import java.util.function.BiConsumer class Experimental private constructor() { - companion object { - private var setEmitExperimentalTelemetry: BiConsumer? = null + companion object { + @Volatile + private var setEmitExperimentalTelemetry: BiConsumer? = null - fun emitExperimentalTelemetry( - builder: AbstractKtorClientTelemetryBuilder - ) { - if (setEmitExperimentalTelemetry != null) { - setEmitExperimentalTelemetry!!.accept(builder, true) - } - } + fun emitExperimentalTelemetry( + builder: AbstractKtorClientTelemetryBuilder + ) { + if (setEmitExperimentalTelemetry != null) { + setEmitExperimentalTelemetry!!.accept(builder, true) + } + } - fun setSetEmitExperimentalTelemetry( - setEmitExperimentalTelemetry: BiConsumer? - ) { - Companion.setEmitExperimentalTelemetry = setEmitExperimentalTelemetry - } + fun setSetEmitExperimentalTelemetry( + setEmitExperimentalTelemetry: BiConsumer? + ) { + Companion.setEmitExperimentalTelemetry = setEmitExperimentalTelemetry } + } } From 3f54de5f104bedfe0db41499c04a1e6c828faa59 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 10 Dec 2024 19:53:26 -0800 Subject: [PATCH 11/24] spotless --- .../v2_0/common/client/internal/Experimental.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt index bfeb16462916..49c6b75235e1 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.instrumentation.ktor.v2_0.common.client.internal import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetryBuilder @@ -9,17 +14,13 @@ class Experimental private constructor() { @Volatile private var setEmitExperimentalTelemetry: BiConsumer? = null - fun emitExperimentalTelemetry( - builder: AbstractKtorClientTelemetryBuilder - ) { + fun emitExperimentalTelemetry(builder: AbstractKtorClientTelemetryBuilder) { if (setEmitExperimentalTelemetry != null) { setEmitExperimentalTelemetry!!.accept(builder, true) } } - fun setSetEmitExperimentalTelemetry( - setEmitExperimentalTelemetry: BiConsumer? - ) { + fun setSetEmitExperimentalTelemetry(setEmitExperimentalTelemetry: BiConsumer?) { Companion.setEmitExperimentalTelemetry = setEmitExperimentalTelemetry } } From 26ddaed6545361d71fb1f4c2db5ff95b26f01498 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 10 Dec 2024 19:59:29 -0800 Subject: [PATCH 12/24] use kotlin internal --- .../client/AbstractKtorClientTelemetryBuilder.kt | 6 ++---- .../ktor/v2_0/common/client/internal/Experimental.kt | 12 +----------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt index bf941f6e8787..e12d29d9a7d8 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt @@ -13,7 +13,6 @@ import io.opentelemetry.api.common.AttributesBuilder import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor -import io.opentelemetry.instrumentation.ktor.v2_0.common.client.internal.Experimental import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil abstract class AbstractKtorClientTelemetryBuilder( @@ -22,12 +21,11 @@ abstract class AbstractKtorClientTelemetryBuilder( companion object { init { KtorBuilderUtil.clientBuilderExtractor = { it.builder } - Experimental.setSetEmitExperimentalTelemetry { builder, emit -> builder.builder.setEmitExperimentalHttpClientMetrics(emit) } } } internal lateinit var openTelemetry: OpenTelemetry - protected lateinit var builder: DefaultHttpClientInstrumenterBuilder + internal lateinit var builder: DefaultHttpClientInstrumenterBuilder fun setOpenTelemetry(openTelemetry: OpenTelemetry) { this.openTelemetry = openTelemetry @@ -67,7 +65,7 @@ abstract class AbstractKtorClientTelemetryBuilder( fun attributesExtractor(extractorBuilder: ExtractorBuilder.() -> Unit = {}) { val builder = ExtractorBuilder().apply(extractorBuilder).build() - this.builder.addAttributeExtractor( + this.builder.addAttributesExtractor( object : AttributesExtractor { override fun onStart(attributes: AttributesBuilder, parentContext: Context, request: HttpRequestData) { builder.onStart(OnStartData(attributes, parentContext, request)) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt index 49c6b75235e1..6b36233c59b0 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt @@ -6,22 +6,12 @@ package io.opentelemetry.instrumentation.ktor.v2_0.common.client.internal import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetryBuilder -import java.util.function.BiConsumer class Experimental private constructor() { companion object { - @Volatile - private var setEmitExperimentalTelemetry: BiConsumer? = null - fun emitExperimentalTelemetry(builder: AbstractKtorClientTelemetryBuilder) { - if (setEmitExperimentalTelemetry != null) { - setEmitExperimentalTelemetry!!.accept(builder, true) - } - } - - fun setSetEmitExperimentalTelemetry(setEmitExperimentalTelemetry: BiConsumer?) { - Companion.setEmitExperimentalTelemetry = setEmitExperimentalTelemetry + builder.builder.setEmitExperimentalHttpClientMetrics(true) } } } From cb5971db279ab19eadd6d1e1a08a6af8ff100290 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 10 Dec 2024 20:27:10 -0800 Subject: [PATCH 13/24] fix --- .../AbstractKtorClientTelemetryBuilder.kt | 24 +++++++++---------- .../common/client/internal/Experimental.kt | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt index e12d29d9a7d8..fef048f950d4 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt @@ -25,15 +25,17 @@ abstract class AbstractKtorClientTelemetryBuilder( } internal lateinit var openTelemetry: OpenTelemetry - internal lateinit var builder: DefaultHttpClientInstrumenterBuilder + internal lateinit var internalBuilder: DefaultHttpClientInstrumenterBuilder + protected lateinit var builder: DefaultHttpClientInstrumenterBuilder fun setOpenTelemetry(openTelemetry: OpenTelemetry) { this.openTelemetry = openTelemetry - this.builder = DefaultHttpClientInstrumenterBuilder.create( + this.internalBuilder = DefaultHttpClientInstrumenterBuilder.create( instrumentationName, openTelemetry, KtorHttpClientAttributesGetter ) + this.builder = internalBuilder } protected fun getOpenTelemetry(): OpenTelemetry { @@ -65,17 +67,15 @@ abstract class AbstractKtorClientTelemetryBuilder( fun attributesExtractor(extractorBuilder: ExtractorBuilder.() -> Unit = {}) { val builder = ExtractorBuilder().apply(extractorBuilder).build() - this.builder.addAttributesExtractor( - object : AttributesExtractor { - override fun onStart(attributes: AttributesBuilder, parentContext: Context, request: HttpRequestData) { - builder.onStart(OnStartData(attributes, parentContext, request)) - } - - override fun onEnd(attributes: AttributesBuilder, context: Context, request: HttpRequestData, response: HttpResponse?, error: Throwable?) { - builder.onEnd(OnEndData(attributes, context, request, response, error)) - } + this.builder.addAttributesExtractor(object : AttributesExtractor { + override fun onStart(attributes: AttributesBuilder, parentContext: Context, request: HttpRequestData) { + builder.onStart(OnStartData(attributes, parentContext, request)) } - ) + + override fun onEnd(attributes: AttributesBuilder, context: Context, request: HttpRequestData, response: HttpResponse?, error: Throwable?) { + builder.onEnd(OnEndData(attributes, context, request, response, error)) + } + }) } class ExtractorBuilder { diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt index 6b36233c59b0..74c69156fd4b 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt @@ -11,7 +11,7 @@ class Experimental private constructor() { companion object { fun emitExperimentalTelemetry(builder: AbstractKtorClientTelemetryBuilder) { - builder.builder.setEmitExperimentalHttpClientMetrics(true) + builder.internalBuilder.setEmitExperimentalHttpClientMetrics(true) } } } From b28385fd484141f53effb777cb8ca90a2e7011d0 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 11 Dec 2024 09:59:17 -0800 Subject: [PATCH 14/24] Combine client and server package --- .../common/{client => }/AbstractKtorClientTelemetry.kt | 3 ++- .../{client => }/AbstractKtorClientTelemetryBuilder.kt | 3 ++- .../{server => }/AbstractKtorServerTelemetryBuilder.kt | 3 ++- .../ktor/v2_0/common/client/internal/Experimental.kt | 2 +- .../ktor/v2_0/common/internal/KtorBuilderUtil.kt | 4 ++-- .../v2_0/common/internal/KtorClientTelemetryUtil.kt | 2 +- .../v2_0/common/internal/KtorServerTelemetryUtil.kt | 2 +- .../ktor/v2_0/ServerInstrumentation.java | 2 +- .../ktor/v2_0/client/KtorClientTelemetry.kt | 2 +- .../ktor/v2_0/client/KtorClientTelemetryBuilder.kt | 10 +++++----- .../ktor/v2_0/server/KtorServerTelemetryBuilder.kt | 2 +- .../ktor/v3_0/HttpClientInstrumentation.java | 4 ++-- .../ktor/v3_0/ServerInstrumentation.java | 4 ++-- .../ktor/v3_0/{client => }/KtorClientTelemetry.kt | 4 ++-- .../v3_0/{client => }/KtorClientTelemetryBuilder.kt | 4 ++-- .../v3_0/{server => }/KtorServerTelemetryBuilder.kt | 4 ++-- 16 files changed, 29 insertions(+), 26 deletions(-) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/{client => }/AbstractKtorClientTelemetry.kt (90%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/{client => }/AbstractKtorClientTelemetryBuilder.kt (96%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/{server => }/AbstractKtorServerTelemetryBuilder.kt (97%) rename instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/{client => }/KtorClientTelemetry.kt (87%) rename instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/{client => }/KtorClientTelemetryBuilder.kt (73%) rename instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/{server => }/KtorServerTelemetryBuilder.kt (88%) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetry.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetry.kt similarity index 90% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetry.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetry.kt index fe7dffce7c1e..521e73bd1a5e 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetry.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetry.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.common.client +package io.opentelemetry.instrumentation.ktor.v2_0.common import io.ktor.client.call.* import io.ktor.client.request.* @@ -11,6 +11,7 @@ import io.ktor.client.statement.* import io.opentelemetry.context.Context import io.opentelemetry.context.propagation.ContextPropagators import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter +import io.opentelemetry.instrumentation.ktor.v2_0.common.client.KtorHttpHeadersSetter abstract class AbstractKtorClientTelemetry( private val instrumenter: Instrumenter, diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetryBuilder.kt similarity index 96% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetryBuilder.kt index fef048f950d4..076f759df385 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetryBuilder.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.common.client +package io.opentelemetry.instrumentation.ktor.v2_0.common import io.ktor.client.request.* import io.ktor.client.statement.* @@ -13,6 +13,7 @@ import io.opentelemetry.api.common.AttributesBuilder import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor +import io.opentelemetry.instrumentation.ktor.v2_0.common.client.KtorHttpClientAttributesGetter import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil abstract class AbstractKtorClientTelemetryBuilder( diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorServerTelemetryBuilder.kt similarity index 97% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorServerTelemetryBuilder.kt index e8a3754337ab..e171a1492aff 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorServerTelemetryBuilder.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.common.server +package io.opentelemetry.instrumentation.ktor.v2_0.common import io.ktor.http.* import io.ktor.server.request.* @@ -18,6 +18,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusBuilder import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil +import io.opentelemetry.instrumentation.ktor.v2_0.common.server.KtorHttpServerAttributesGetter abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationName: String) { companion object { diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt index 74c69156fd4b..d32b3fe2963b 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt @@ -5,7 +5,7 @@ package io.opentelemetry.instrumentation.ktor.v2_0.common.client.internal -import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorClientTelemetryBuilder class Experimental private constructor() { diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorBuilderUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorBuilderUtil.kt index d916a48c4487..c83d8aa6bdba 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorBuilderUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorBuilderUtil.kt @@ -11,8 +11,8 @@ import io.ktor.server.request.* import io.ktor.server.response.* import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder -import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetryBuilder -import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorClientTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorServerTelemetryBuilder /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTelemetryUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTelemetryUtil.kt index 52408fa0f9a6..2bb2c8f0e016 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTelemetryUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorClientTelemetryUtil.kt @@ -13,7 +13,7 @@ import io.ktor.util.pipeline.* import io.opentelemetry.context.Context import io.opentelemetry.extension.kotlin.asContextElement import io.opentelemetry.instrumentation.api.semconv.http.HttpClientRequestResendCount -import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetry +import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorClientTelemetry import kotlinx.coroutines.InternalCoroutinesApi import kotlinx.coroutines.job import kotlinx.coroutines.launch diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt index 02900444202d..c0ffdcebc7ac 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt @@ -15,7 +15,7 @@ import io.opentelemetry.extension.kotlin.asContextElement import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor import io.opentelemetry.instrumentation.api.internal.InstrumenterUtil -import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorServerTelemetryBuilder import io.opentelemetry.instrumentation.ktor.v2_0.common.server.ApplicationRequestGetter import kotlinx.coroutines.withContext diff --git a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/ServerInstrumentation.java b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/ServerInstrumentation.java index 6f9611499bec..2e6985e9f073 100644 --- a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/ServerInstrumentation.java +++ b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/ServerInstrumentation.java @@ -11,8 +11,8 @@ import io.ktor.server.application.Application; import io.ktor.server.application.ApplicationPluginKt; import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorServerTelemetryBuilder; import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil; -import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTelemetryBuilder; import io.opentelemetry.instrumentation.ktor.v2_0.server.KtorServerTelemetryBuilderKt; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt index 3963999e9b63..4fb3ff07fb13 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt @@ -12,7 +12,7 @@ import io.ktor.client.statement.* import io.ktor.util.* import io.opentelemetry.context.propagation.ContextPropagators import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter -import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetry +import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorClientTelemetry import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorClientTelemetryUtil class KtorClientTelemetry internal constructor( diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt index 6e5449f1d2ef..6f1b6d759b08 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt @@ -6,12 +6,12 @@ package io.opentelemetry.instrumentation.ktor.v2_0.client import io.opentelemetry.instrumentation.ktor.v2_0.InstrumentationProperties.INSTRUMENTATION_NAME -import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorClientTelemetryBuilder class KtorClientTelemetryBuilder : AbstractKtorClientTelemetryBuilder(INSTRUMENTATION_NAME) { - internal fun build(): KtorClientTelemetry = KtorClientTelemetry( - instrumenter = builder.build(), - propagators = getOpenTelemetry().propagators, - ) + internal fun build(): KtorClientTelemetry = KtorClientTelemetry( + instrumenter = builder.build(), + propagators = getOpenTelemetry().propagators, + ) } diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt index af6a84d9ee5e..3592d6d0ddc7 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt @@ -11,8 +11,8 @@ import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource import io.opentelemetry.instrumentation.ktor.v2_0.InstrumentationProperties.INSTRUMENTATION_NAME +import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorServerTelemetryBuilder import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorServerTelemetryUtil -import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTelemetryBuilder class KtorServerTelemetryBuilder internal constructor( instrumentationName: String diff --git a/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/HttpClientInstrumentation.java b/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/HttpClientInstrumentation.java index 0ab6f7609276..f3b6c676d437 100644 --- a/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/HttpClientInstrumentation.java +++ b/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/HttpClientInstrumentation.java @@ -14,8 +14,8 @@ import io.ktor.client.engine.HttpClientEngineConfig; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil; -import io.opentelemetry.instrumentation.ktor.v3_0.client.KtorClientTelemetry; -import io.opentelemetry.instrumentation.ktor.v3_0.client.KtorClientTelemetryBuilder; +import io.opentelemetry.instrumentation.ktor.v3_0.KtorClientTelemetry; +import io.opentelemetry.instrumentation.ktor.v3_0.KtorClientTelemetryBuilder; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; diff --git a/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/ServerInstrumentation.java b/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/ServerInstrumentation.java index b4b5a0832256..f5dc7368e78a 100644 --- a/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/ServerInstrumentation.java +++ b/instrumentation/ktor/ktor-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v3_0/ServerInstrumentation.java @@ -11,9 +11,9 @@ import io.ktor.server.application.Application; import io.ktor.server.application.ApplicationPluginKt; import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorServerTelemetryBuilder; import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil; -import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTelemetryBuilder; -import io.opentelemetry.instrumentation.ktor.v3_0.server.KtorServerTelemetryBuilderKt; +import io.opentelemetry.instrumentation.ktor.v3_0.KtorServerTelemetryBuilderKt; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; diff --git a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetry.kt b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorClientTelemetry.kt similarity index 87% rename from instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetry.kt rename to instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorClientTelemetry.kt index aa0f2d4ecf88..09a82366c6cf 100644 --- a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetry.kt +++ b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorClientTelemetry.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v3_0.client +package io.opentelemetry.instrumentation.ktor.v3_0 import io.ktor.client.* import io.ktor.client.plugins.* @@ -12,7 +12,7 @@ import io.ktor.client.statement.* import io.ktor.util.* import io.opentelemetry.context.propagation.ContextPropagators import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter -import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetry +import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorClientTelemetry import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorClientTelemetryUtil class KtorClientTelemetry internal constructor( diff --git a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorClientTelemetryBuilder.kt similarity index 73% rename from instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetryBuilder.kt rename to instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorClientTelemetryBuilder.kt index bbf21d7a8b48..024f3d770b96 100644 --- a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorClientTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorClientTelemetryBuilder.kt @@ -3,9 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v3_0.client +package io.opentelemetry.instrumentation.ktor.v3_0 -import io.opentelemetry.instrumentation.ktor.v2_0.common.client.AbstractKtorClientTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorClientTelemetryBuilder import io.opentelemetry.instrumentation.ktor.v3_0.InstrumentationProperties.INSTRUMENTATION_NAME class KtorClientTelemetryBuilder : AbstractKtorClientTelemetryBuilder(INSTRUMENTATION_NAME) { diff --git a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTelemetryBuilder.kt b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorServerTelemetryBuilder.kt similarity index 88% rename from instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTelemetryBuilder.kt rename to instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorServerTelemetryBuilder.kt index 43c4ec92952a..3a582af028ba 100644 --- a/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorServerTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-3.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorServerTelemetryBuilder.kt @@ -3,15 +3,15 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v3_0.server +package io.opentelemetry.instrumentation.ktor.v3_0 import io.ktor.server.application.* import io.ktor.server.routing.* import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource +import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorServerTelemetryBuilder import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorServerTelemetryUtil -import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTelemetryBuilder import io.opentelemetry.instrumentation.ktor.v3_0.InstrumentationProperties.INSTRUMENTATION_NAME class KtorServerTelemetryBuilder internal constructor( From 24671ddf2859751c3fe9db40f90a82391e2987df Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 11 Dec 2024 10:07:16 -0800 Subject: [PATCH 15/24] Combine client and server package --- .../ktor/v2_0/common/{client => }/internal/Experimental.kt | 2 +- .../ktor/v2_0/HttpClientInstrumentation.java | 4 ++-- .../instrumentation/ktor/v2_0/ServerInstrumentation.java | 2 +- .../ktor/v2_0/{client => }/KtorHttpClientTest.kt | 2 +- .../instrumentation/ktor/v2_0}/KtorHttpServerTest.kt | 2 +- .../ktor/v2_0/{client => }/KtorClientTelemetry.kt | 2 +- .../ktor/v2_0/{client => }/KtorClientTelemetryBuilder.kt | 2 +- .../ktor/v2_0/{server => }/KtorServerTelemetryBuilder.kt | 2 +- .../ktor/v2_0/{client => }/KtorHttpClientTest.kt | 3 ++- .../ktor/v2_0/{server => }/KtorHttpServerTest.kt | 4 ++-- .../v2_0/{server => }/KtorServerSpanKindExtractorTest.kt | 3 ++- .../instrumentation/ktor/v2_0/{server => }/KtorTestUtil.kt | 3 ++- .../ktor/v2_0/{client => }/AbstractKtorHttpClientTest.kt | 2 +- .../ktor/v2_0/{server => }/AbstractKtorHttpServerTest.kt | 2 +- .../v2_0/{client => }/KtorHttpClientSingleConnection.kt | 2 +- .../ktor/v3_0/{client => }/KtorHttpClientTest.kt | 2 +- .../instrumentation/ktor/v3_0}/KtorHttpServerTest.kt | 2 +- .../ktor/v3_0/{client => }/KtorHttpClientTest.kt | 3 ++- .../ktor/v3_0/{server => }/KtorHttpServerTest.kt | 3 ++- .../ktor/v3_0/{client => }/AbstractKtorHttpClientTest.kt | 7 +++++-- .../ktor/v3_0/{server => }/AbstractKtorHttpServerTest.kt | 2 +- .../v3_0/{client => }/KtorHttpClientSingleConnection.kt | 3 +-- 22 files changed, 33 insertions(+), 26 deletions(-) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/{client => }/internal/Experimental.kt (84%) rename instrumentation/ktor/ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0/{client => }/KtorHttpClientTest.kt (89%) rename instrumentation/ktor/{ktor-3.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v3_0/server => ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0}/KtorHttpServerTest.kt (94%) rename instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/{client => }/KtorClientTelemetry.kt (95%) rename instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/{client => }/KtorClientTelemetryBuilder.kt (90%) rename instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/{server => }/KtorServerTelemetryBuilder.kt (95%) rename instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/{client => }/KtorHttpClientTest.kt (84%) rename instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/{server => }/KtorHttpServerTest.kt (84%) rename instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/{server => }/KtorServerSpanKindExtractorTest.kt (96%) rename instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/{server => }/KtorTestUtil.kt (83%) rename instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/{client => }/AbstractKtorHttpClientTest.kt (97%) rename instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/{server => }/AbstractKtorHttpServerTest.kt (98%) rename instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/{client => }/KtorHttpClientSingleConnection.kt (92%) rename instrumentation/ktor/ktor-3.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v3_0/{client => }/KtorHttpClientTest.kt (89%) rename instrumentation/ktor/{ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0/server => ktor-3.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v3_0}/KtorHttpServerTest.kt (94%) rename instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/{client => }/KtorHttpClientTest.kt (84%) rename instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/{server => }/KtorHttpServerTest.kt (88%) rename instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/{client => }/AbstractKtorHttpClientTest.kt (92%) rename instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/{server => }/AbstractKtorHttpServerTest.kt (98%) rename instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/{client => }/KtorHttpClientSingleConnection.kt (89%) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/Experimental.kt similarity index 84% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/Experimental.kt index d32b3fe2963b..f49c58d6c95b 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/internal/Experimental.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/Experimental.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.common.client.internal +package io.opentelemetry.instrumentation.ktor.v2_0.common.internal import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorClientTelemetryBuilder diff --git a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java index 65e8ded4e967..8a5276c6d695 100644 --- a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java +++ b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java @@ -13,8 +13,8 @@ import io.ktor.client.HttpClientConfig; import io.ktor.client.engine.HttpClientEngineConfig; import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTelemetry; -import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTelemetryBuilder; +import io.opentelemetry.instrumentation.ktor.v2_0.KtorClientTelemetry; +import io.opentelemetry.instrumentation.ktor.v2_0.KtorClientTelemetryBuilder; import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; diff --git a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/ServerInstrumentation.java b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/ServerInstrumentation.java index 2e6985e9f073..421c199a95b2 100644 --- a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/ServerInstrumentation.java +++ b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/ServerInstrumentation.java @@ -11,9 +11,9 @@ import io.ktor.server.application.Application; import io.ktor.server.application.ApplicationPluginKt; import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.instrumentation.ktor.v2_0.KtorServerTelemetryBuilderKt; import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorServerTelemetryBuilder; import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil; -import io.opentelemetry.instrumentation.ktor.v2_0.server.KtorServerTelemetryBuilderKt; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; diff --git a/instrumentation/ktor/ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorHttpClientTest.kt b/instrumentation/ktor/ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpClientTest.kt similarity index 89% rename from instrumentation/ktor/ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorHttpClientTest.kt rename to instrumentation/ktor/ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpClientTest.kt index 8b8b655f8475..ba9c459b76cb 100644 --- a/instrumentation/ktor/ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorHttpClientTest.kt +++ b/instrumentation/ktor/ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpClientTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.client +package io.opentelemetry.instrumentation.ktor.v2_0 import io.ktor.client.* import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension diff --git a/instrumentation/ktor/ktor-3.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorHttpServerTest.kt b/instrumentation/ktor/ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerTest.kt similarity index 94% rename from instrumentation/ktor/ktor-3.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorHttpServerTest.kt rename to instrumentation/ktor/ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerTest.kt index 138a6911144d..ec212c53996f 100644 --- a/instrumentation/ktor/ktor-3.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorHttpServerTest.kt +++ b/instrumentation/ktor/ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v3_0.server +package io.opentelemetry.instrumentation.ktor.v2_0 import io.ktor.server.application.* import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorClientTelemetry.kt similarity index 95% rename from instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt rename to instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorClientTelemetry.kt index 4fb3ff07fb13..ae06c51b9403 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetry.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorClientTelemetry.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.client +package io.opentelemetry.instrumentation.ktor.v2_0 import io.ktor.client.* import io.ktor.client.plugins.* diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorClientTelemetryBuilder.kt similarity index 90% rename from instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt rename to instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorClientTelemetryBuilder.kt index 6f1b6d759b08..64ac22199b28 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorClientTelemetryBuilder.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.client +package io.opentelemetry.instrumentation.ktor.v2_0 import io.opentelemetry.instrumentation.ktor.v2_0.InstrumentationProperties.INSTRUMENTATION_NAME import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorClientTelemetryBuilder diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorServerTelemetryBuilder.kt similarity index 95% rename from instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt rename to instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorServerTelemetryBuilder.kt index 3592d6d0ddc7..63d6931f3fe9 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorServerTelemetryBuilder.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.server +package io.opentelemetry.instrumentation.ktor.v2_0 import io.ktor.server.application.* import io.ktor.server.routing.* diff --git a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorHttpClientTest.kt b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpClientTest.kt similarity index 84% rename from instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorHttpClientTest.kt rename to instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpClientTest.kt index ada0183d30a1..62e1445bba91 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorHttpClientTest.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpClientTest.kt @@ -3,9 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.client +package io.opentelemetry.instrumentation.ktor.v2_0 import io.ktor.client.* +import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTracing import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension import org.junit.jupiter.api.extension.RegisterExtension diff --git a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorHttpServerTest.kt b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerTest.kt similarity index 84% rename from instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorHttpServerTest.kt rename to instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerTest.kt index 97f4022c3102..1d3909ee5bd8 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorHttpServerTest.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.server +package io.opentelemetry.instrumentation.ktor.v2_0 import io.ktor.server.application.* import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension @@ -23,6 +23,6 @@ class KtorHttpServerTest : AbstractKtorHttpServerTest() { } override fun installOpenTelemetry(application: Application) { - KtorTestUtil.installOpenTelemetry(application, TESTING.openTelemetry) + KtorTestUtil.installOpenTelemetry(application, TESTING.openTelemetry) } } diff --git a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerSpanKindExtractorTest.kt b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorServerSpanKindExtractorTest.kt similarity index 96% rename from instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerSpanKindExtractorTest.kt rename to instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorServerSpanKindExtractorTest.kt index e4ab5d89391a..9605454d3b1e 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerSpanKindExtractorTest.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorServerSpanKindExtractorTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.server +package io.opentelemetry.instrumentation.ktor.v2_0 import io.ktor.http.* import io.ktor.server.application.* @@ -13,6 +13,7 @@ import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* import io.opentelemetry.api.trace.SpanKind +import io.opentelemetry.instrumentation.ktor.v2_0.server.KtorServerTracing import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerUsingTest import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension diff --git a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorTestUtil.kt b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorTestUtil.kt similarity index 83% rename from instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorTestUtil.kt rename to instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorTestUtil.kt index 6a799635c1c5..73fdf2052dce 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorTestUtil.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorTestUtil.kt @@ -3,10 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.server +package io.opentelemetry.instrumentation.ktor.v2_0 import io.ktor.server.application.* import io.opentelemetry.api.OpenTelemetry +import io.opentelemetry.instrumentation.ktor.v2_0.server.KtorServerTracing import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest class KtorTestUtil { diff --git a/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/AbstractKtorHttpClientTest.kt b/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/AbstractKtorHttpClientTest.kt similarity index 97% rename from instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/AbstractKtorHttpClientTest.kt rename to instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/AbstractKtorHttpClientTest.kt index 25984db55484..38124f0dc338 100644 --- a/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/AbstractKtorHttpClientTest.kt +++ b/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/AbstractKtorHttpClientTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.client +package io.opentelemetry.instrumentation.ktor.v2_0 import io.ktor.client.* import io.ktor.client.engine.cio.* diff --git a/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/AbstractKtorHttpServerTest.kt b/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/AbstractKtorHttpServerTest.kt similarity index 98% rename from instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/AbstractKtorHttpServerTest.kt rename to instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/AbstractKtorHttpServerTest.kt index 13c424166036..863492509cb8 100644 --- a/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/AbstractKtorHttpServerTest.kt +++ b/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/AbstractKtorHttpServerTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.server +package io.opentelemetry.instrumentation.ktor.v2_0 import io.ktor.http.* import io.ktor.server.application.* diff --git a/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorHttpClientSingleConnection.kt b/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpClientSingleConnection.kt similarity index 92% rename from instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorHttpClientSingleConnection.kt rename to instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpClientSingleConnection.kt index 4e61403a4bdf..2d0de2d6e800 100644 --- a/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorHttpClientSingleConnection.kt +++ b/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpClientSingleConnection.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.client +package io.opentelemetry.instrumentation.ktor.v2_0 import io.ktor.client.* import io.ktor.client.request.* diff --git a/instrumentation/ktor/ktor-3.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorHttpClientTest.kt b/instrumentation/ktor/ktor-3.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpClientTest.kt similarity index 89% rename from instrumentation/ktor/ktor-3.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorHttpClientTest.kt rename to instrumentation/ktor/ktor-3.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpClientTest.kt index b9e3623e01a9..a58f4d856e13 100644 --- a/instrumentation/ktor/ktor-3.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorHttpClientTest.kt +++ b/instrumentation/ktor/ktor-3.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpClientTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v3_0.client +package io.opentelemetry.instrumentation.ktor.v3_0 import io.ktor.client.* import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension diff --git a/instrumentation/ktor/ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorHttpServerTest.kt b/instrumentation/ktor/ktor-3.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpServerTest.kt similarity index 94% rename from instrumentation/ktor/ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorHttpServerTest.kt rename to instrumentation/ktor/ktor-3.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpServerTest.kt index f9776431becf..e25dbb7ac3ea 100644 --- a/instrumentation/ktor/ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorHttpServerTest.kt +++ b/instrumentation/ktor/ktor-3.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpServerTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.server +package io.opentelemetry.instrumentation.ktor.v3_0 import io.ktor.server.application.* import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension diff --git a/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorHttpClientTest.kt b/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpClientTest.kt similarity index 84% rename from instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorHttpClientTest.kt rename to instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpClientTest.kt index 0249949e8ebb..e5d298eb65a3 100644 --- a/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorHttpClientTest.kt +++ b/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpClientTest.kt @@ -3,9 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v3_0.client +package io.opentelemetry.instrumentation.ktor.v3_0 import io.ktor.client.* +import io.opentelemetry.instrumentation.ktor.v3_0.client.KtorClientTracing import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension import org.junit.jupiter.api.extension.RegisterExtension diff --git a/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorHttpServerTest.kt b/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpServerTest.kt similarity index 88% rename from instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorHttpServerTest.kt rename to instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpServerTest.kt index 61caec27af83..6d3e9ffba167 100644 --- a/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/KtorHttpServerTest.kt +++ b/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpServerTest.kt @@ -3,9 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v3_0.server +package io.opentelemetry.instrumentation.ktor.v3_0 import io.ktor.server.application.* +import io.opentelemetry.instrumentation.ktor.v3_0.server.KtorServerTracing import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension import org.junit.jupiter.api.extension.RegisterExtension diff --git a/instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/AbstractKtorHttpClientTest.kt b/instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/AbstractKtorHttpClientTest.kt similarity index 92% rename from instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/AbstractKtorHttpClientTest.kt rename to instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/AbstractKtorHttpClientTest.kt index 2e698e34e461..086b15d66ae5 100644 --- a/instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/AbstractKtorHttpClientTest.kt +++ b/instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/AbstractKtorHttpClientTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v3_0.client +package io.opentelemetry.instrumentation.ktor.v3_0 import io.ktor.client.* import io.ktor.client.engine.cio.* @@ -17,7 +17,10 @@ import io.opentelemetry.instrumentation.testing.junit.http.HttpClientResult import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions.DEFAULT_HTTP_ATTRIBUTES import io.opentelemetry.semconv.NetworkAttributes -import kotlinx.coroutines.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.AfterAll import java.net.URI diff --git a/instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/AbstractKtorHttpServerTest.kt b/instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/AbstractKtorHttpServerTest.kt similarity index 98% rename from instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/AbstractKtorHttpServerTest.kt rename to instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/AbstractKtorHttpServerTest.kt index 24d4eba8c5e4..5b4fba1eecc8 100644 --- a/instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/server/AbstractKtorHttpServerTest.kt +++ b/instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/AbstractKtorHttpServerTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v3_0.server +package io.opentelemetry.instrumentation.ktor.v3_0 import io.ktor.http.* import io.ktor.server.application.* diff --git a/instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorHttpClientSingleConnection.kt b/instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpClientSingleConnection.kt similarity index 89% rename from instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorHttpClientSingleConnection.kt rename to instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpClientSingleConnection.kt index 30290d4f1e0f..82a2679c5a12 100644 --- a/instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/client/KtorHttpClientSingleConnection.kt +++ b/instrumentation/ktor/ktor-3.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpClientSingleConnection.kt @@ -3,10 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v3_0.client +package io.opentelemetry.instrumentation.ktor.v3_0 import io.ktor.client.* -import io.ktor.client.engine.cio.* import io.ktor.client.request.* import io.opentelemetry.instrumentation.testing.junit.http.SingleConnection import kotlinx.coroutines.runBlocking From a4ebcacfca6f9e0467f9e0bb35e52bf17aab7228 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 11 Dec 2024 10:08:47 -0800 Subject: [PATCH 16/24] update docs --- instrumentation/ktor/ktor-1.0/library/README.md | 9 ++++++--- instrumentation/ktor/ktor-2.0/library/README.md | 14 +++++++++----- instrumentation/ktor/ktor-3.0/library/README.md | 14 +++++++++----- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/instrumentation/ktor/ktor-1.0/library/README.md b/instrumentation/ktor/ktor-1.0/library/README.md index 2701fd8c5125..d93d052a20d6 100644 --- a/instrumentation/ktor/ktor-1.0/library/README.md +++ b/instrumentation/ktor/ktor-1.0/library/README.md @@ -1,6 +1,7 @@ # Library Instrumentation for Ktor version 1.x -This package contains libraries to help instrument Ktor. Currently, only server instrumentation is supported. +This package contains libraries to help instrument Ktor. Currently, only server instrumentation is +supported. ## Quickstart @@ -12,6 +13,7 @@ release](https://search.maven.org/search?q=g:io.opentelemetry.instrumentation%20 For Maven, add to your `pom.xml` dependencies: ```xml + io.opentelemetry.instrumentation @@ -29,14 +31,15 @@ implementation("io.opentelemetry.instrumentation:opentelemetry-ktor-1.0:OPENTELE ## Usage -Initialize instrumentation by installing the `KtorServerTracing` feature. You must set the `OpenTelemetry` to use with +Initialize instrumentation by installing the `KtorServerTelemetry` feature. You must set the +`OpenTelemetry` to use with the feature. ```kotlin OpenTelemetry openTelemetry = ... embeddedServer(Netty, 8080) { - install(KtorServerTracing) { + install(KtorServerTelemetry) { setOpenTelemetry(openTelemetry) } } diff --git a/instrumentation/ktor/ktor-2.0/library/README.md b/instrumentation/ktor/ktor-2.0/library/README.md index f9af95e58a5b..5a36056ff254 100644 --- a/instrumentation/ktor/ktor-2.0/library/README.md +++ b/instrumentation/ktor/ktor-2.0/library/README.md @@ -1,6 +1,7 @@ # Library Instrumentation for Ktor version 2.x -This package contains libraries to help instrument Ktor. Server and client instrumentations are supported. +This package contains libraries to help instrument Ktor. Server and client instrumentations are +supported. ## Quickstart @@ -12,6 +13,7 @@ release](https://search.maven.org/search?q=g:io.opentelemetry.instrumentation%20 For Maven, add to your `pom.xml` dependencies: ```xml + io.opentelemetry.instrumentation @@ -31,14 +33,15 @@ implementation("io.opentelemetry.instrumentation:opentelemetry-ktor-2.0:OPENTELE ## Initializing server instrumentation -Initialize instrumentation by installing the `KtorServerTracing` feature. You must set the `OpenTelemetry` to use with +Initialize instrumentation by installing the `KtorServerTelemetry` feature. You must set the +`OpenTelemetry` to use with the feature. ```kotlin val openTelemetry: OpenTelemetry = ... embeddedServer(Netty, 8080) { - install(KtorServerTracing) { + install(KtorServerTelemetry) { setOpenTelemetry(openTelemetry) } } @@ -46,14 +49,15 @@ embeddedServer(Netty, 8080) { ## Initializing client instrumentation -Initialize instrumentation by installing the `KtorClientTracing` feature. You must set the `OpenTelemetry` to use with +Initialize instrumentation by installing the `KtorClientTelemetry` feature. You must set the +`OpenTelemetry` to use with the feature. ```kotlin val openTelemetry: OpenTelemetry = ... val client = HttpClient { - install(KtorClientTracing) { + install(KtorClientTelemetry) { setOpenTelemetry(openTelemetry) } } diff --git a/instrumentation/ktor/ktor-3.0/library/README.md b/instrumentation/ktor/ktor-3.0/library/README.md index ce6fe411b3cd..87313b911a7d 100644 --- a/instrumentation/ktor/ktor-3.0/library/README.md +++ b/instrumentation/ktor/ktor-3.0/library/README.md @@ -1,6 +1,7 @@ # Library Instrumentation for Ktor version 3.0 and higher -This package contains libraries to help instrument Ktor. Server and client instrumentations are supported. +This package contains libraries to help instrument Ktor. Server and client instrumentations are +supported. ## Quickstart @@ -12,6 +13,7 @@ release](https://search.maven.org/search?q=g:io.opentelemetry.instrumentation%20 For Maven, add to your `pom.xml` dependencies: ```xml + io.opentelemetry.instrumentation @@ -31,14 +33,15 @@ implementation("io.opentelemetry.instrumentation:opentelemetry-ktor-3.0:OPENTELE ## Initializing server instrumentation -Initialize instrumentation by installing the `KtorServerTracing` feature. You must set the `OpenTelemetry` to use with +Initialize instrumentation by installing the `KtorServerTelemetry` feature. You must set the +`OpenTelemetry` to use with the feature. ```kotlin val openTelemetry: OpenTelemetry = ... embeddedServer(Netty, 8080) { - install(KtorServerTracing) { + install(KtorServerTelemetry) { setOpenTelemetry(openTelemetry) } } @@ -46,14 +49,15 @@ embeddedServer(Netty, 8080) { ## Initializing client instrumentation -Initialize instrumentation by installing the `KtorClientTracing` feature. You must set the `OpenTelemetry` to use with +Initialize instrumentation by installing the `KtorClientTelemetry` feature. You must set the +`OpenTelemetry` to use with the feature. ```kotlin val openTelemetry: OpenTelemetry = ... val client = HttpClient { - install(KtorClientTracing) { + install(KtorClientTelemetry) { setOpenTelemetry(openTelemetry) } } From c909356b201c13c01233711bfaf6503f618b8946 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 11 Dec 2024 10:17:44 -0800 Subject: [PATCH 17/24] spotless --- .../ktor/v2_0/KtorClientTelemetryBuilder.kt | 8 ++++---- .../instrumentation/ktor/v2_0/KtorHttpServerTest.kt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorClientTelemetryBuilder.kt index 64ac22199b28..6c71aa3815a8 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorClientTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorClientTelemetryBuilder.kt @@ -10,8 +10,8 @@ import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorClientTelem class KtorClientTelemetryBuilder : AbstractKtorClientTelemetryBuilder(INSTRUMENTATION_NAME) { - internal fun build(): KtorClientTelemetry = KtorClientTelemetry( - instrumenter = builder.build(), - propagators = getOpenTelemetry().propagators, - ) + internal fun build(): KtorClientTelemetry = KtorClientTelemetry( + instrumenter = builder.build(), + propagators = getOpenTelemetry().propagators, + ) } diff --git a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerTest.kt b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerTest.kt index 1d3909ee5bd8..ef76aac9cda9 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerTest.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerTest.kt @@ -23,6 +23,6 @@ class KtorHttpServerTest : AbstractKtorHttpServerTest() { } override fun installOpenTelemetry(application: Application) { - KtorTestUtil.installOpenTelemetry(application, TESTING.openTelemetry) + KtorTestUtil.installOpenTelemetry(application, TESTING.openTelemetry) } } From 36f3d1ef90322ccce63591025c17ebd16b22da3c Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 11 Dec 2024 12:12:13 -0800 Subject: [PATCH 18/24] cleanup --- instrumentation/ktor/ktor-1.0/library/README.md | 10 ++++------ instrumentation/ktor/ktor-2.0/library/README.md | 10 ++++------ instrumentation/ktor/ktor-3.0/library/README.md | 10 ++++------ 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/instrumentation/ktor/ktor-1.0/library/README.md b/instrumentation/ktor/ktor-1.0/library/README.md index d93d052a20d6..6ec0bedff8f0 100644 --- a/instrumentation/ktor/ktor-1.0/library/README.md +++ b/instrumentation/ktor/ktor-1.0/library/README.md @@ -1,7 +1,7 @@ # Library Instrumentation for Ktor version 1.x -This package contains libraries to help instrument Ktor. Currently, only server instrumentation is -supported. +This package contains libraries to help instrument Ktor. +Currently, only server instrumentation is supported. ## Quickstart @@ -13,7 +13,6 @@ release](https://search.maven.org/search?q=g:io.opentelemetry.instrumentation%20 For Maven, add to your `pom.xml` dependencies: ```xml - io.opentelemetry.instrumentation @@ -31,9 +30,8 @@ implementation("io.opentelemetry.instrumentation:opentelemetry-ktor-1.0:OPENTELE ## Usage -Initialize instrumentation by installing the `KtorServerTelemetry` feature. You must set the -`OpenTelemetry` to use with -the feature. +Initialize instrumentation by installing the `KtorServerTelemetry` feature. +You must set the `OpenTelemetry` to use with the feature. ```kotlin OpenTelemetry openTelemetry = ... diff --git a/instrumentation/ktor/ktor-2.0/library/README.md b/instrumentation/ktor/ktor-2.0/library/README.md index 5a36056ff254..6740d0c0fcea 100644 --- a/instrumentation/ktor/ktor-2.0/library/README.md +++ b/instrumentation/ktor/ktor-2.0/library/README.md @@ -1,7 +1,7 @@ # Library Instrumentation for Ktor version 2.x -This package contains libraries to help instrument Ktor. Server and client instrumentations are -supported. +This package contains libraries to help instrument Ktor. +Server and client instrumentations are supported. ## Quickstart @@ -13,7 +13,6 @@ release](https://search.maven.org/search?q=g:io.opentelemetry.instrumentation%20 For Maven, add to your `pom.xml` dependencies: ```xml - io.opentelemetry.instrumentation @@ -33,9 +32,8 @@ implementation("io.opentelemetry.instrumentation:opentelemetry-ktor-2.0:OPENTELE ## Initializing server instrumentation -Initialize instrumentation by installing the `KtorServerTelemetry` feature. You must set the -`OpenTelemetry` to use with -the feature. +Initialize instrumentation by installing the `KtorServerTelemetry` feature. +You must set the `OpenTelemetry` to use with the feature. ```kotlin val openTelemetry: OpenTelemetry = ... diff --git a/instrumentation/ktor/ktor-3.0/library/README.md b/instrumentation/ktor/ktor-3.0/library/README.md index 87313b911a7d..cf60d12cc0fa 100644 --- a/instrumentation/ktor/ktor-3.0/library/README.md +++ b/instrumentation/ktor/ktor-3.0/library/README.md @@ -1,7 +1,7 @@ # Library Instrumentation for Ktor version 3.0 and higher -This package contains libraries to help instrument Ktor. Server and client instrumentations are -supported. +This package contains libraries to help instrument Ktor. +Server and client instrumentations are supported. ## Quickstart @@ -13,7 +13,6 @@ release](https://search.maven.org/search?q=g:io.opentelemetry.instrumentation%20 For Maven, add to your `pom.xml` dependencies: ```xml - io.opentelemetry.instrumentation @@ -33,9 +32,8 @@ implementation("io.opentelemetry.instrumentation:opentelemetry-ktor-3.0:OPENTELE ## Initializing server instrumentation -Initialize instrumentation by installing the `KtorServerTelemetry` feature. You must set the -`OpenTelemetry` to use with -the feature. +Initialize instrumentation by installing the `KtorServerTelemetry` feature. +You must set the `OpenTelemetry` to use with the feature. ```kotlin val openTelemetry: OpenTelemetry = ... From 3863848641f86e914416c816393559e99aa5087e Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 11 Dec 2024 12:15:28 -0800 Subject: [PATCH 19/24] Test new code --- .../instrumentation/ktor/v2_0/KtorHttpClientTest.kt | 3 +-- .../instrumentation/ktor/v3_0/KtorHttpClientTest.kt | 3 +-- .../instrumentation/ktor/v3_0/KtorHttpServerTest.kt | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpClientTest.kt b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpClientTest.kt index 62e1445bba91..6eac7443e164 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpClientTest.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpClientTest.kt @@ -6,7 +6,6 @@ package io.opentelemetry.instrumentation.ktor.v2_0 import io.ktor.client.* -import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTracing import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension import org.junit.jupiter.api.extension.RegisterExtension @@ -19,7 +18,7 @@ class KtorHttpClientTest : AbstractKtorHttpClientTest() { } override fun HttpClientConfig<*>.installTracing() { - install(KtorClientTracing) { + install(KtorClientTelemetry) { setOpenTelemetry(TESTING.openTelemetry) capturedRequestHeaders(TEST_REQUEST_HEADER) capturedResponseHeaders(TEST_RESPONSE_HEADER) diff --git a/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpClientTest.kt b/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpClientTest.kt index e5d298eb65a3..a68d883d5bef 100644 --- a/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpClientTest.kt +++ b/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpClientTest.kt @@ -6,7 +6,6 @@ package io.opentelemetry.instrumentation.ktor.v3_0 import io.ktor.client.* -import io.opentelemetry.instrumentation.ktor.v3_0.client.KtorClientTracing import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension import org.junit.jupiter.api.extension.RegisterExtension @@ -19,7 +18,7 @@ class KtorHttpClientTest : AbstractKtorHttpClientTest() { } override fun HttpClientConfig<*>.installTracing() { - install(KtorClientTracing) { + install(KtorClientTelemetry) { setOpenTelemetry(TESTING.openTelemetry) capturedRequestHeaders(TEST_REQUEST_HEADER) capturedResponseHeaders(TEST_RESPONSE_HEADER) diff --git a/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpServerTest.kt b/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpServerTest.kt index 6d3e9ffba167..a2afe636c077 100644 --- a/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpServerTest.kt +++ b/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpServerTest.kt @@ -6,7 +6,6 @@ package io.opentelemetry.instrumentation.ktor.v3_0 import io.ktor.server.application.* -import io.opentelemetry.instrumentation.ktor.v3_0.server.KtorServerTracing import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension import org.junit.jupiter.api.extension.RegisterExtension @@ -25,7 +24,7 @@ class KtorHttpServerTest : AbstractKtorHttpServerTest() { override fun installOpenTelemetry(application: Application) { application.apply { - install(KtorServerTracing) { + install(KtorServerTelemetry) { setOpenTelemetry(TESTING.openTelemetry) capturedRequestHeaders(TEST_REQUEST_HEADER) capturedResponseHeaders(TEST_RESPONSE_HEADER) From 112eb3dc9af4eda43f0734ac09a37ef7e6ac28f7 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 11 Dec 2024 12:17:19 -0800 Subject: [PATCH 20/24] more moving --- .../ktor/v2_0/common/AbstractKtorClientTelemetry.kt | 1 - .../ktor/v2_0/common/AbstractKtorClientTelemetryBuilder.kt | 1 - .../ktor/v2_0/common/AbstractKtorServerTelemetryBuilder.kt | 1 - .../ktor/v2_0/common/{server => }/ApplicationRequestGetter.kt | 2 +- .../common/{client => }/KtorHttpClientAttributesGetter.kt | 2 +- .../ktor/v2_0/common/{client => }/KtorHttpHeadersSetter.kt | 4 ++-- .../common/{server => }/KtorHttpServerAttributesGetter.kt | 2 +- .../ktor/v2_0/common/client/AbstractKtorClientTracing.kt | 1 + .../v2_0/common/client/AbstractKtorClientTracingBuilder.kt | 1 + .../ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt | 2 +- .../ktor/v2_0/common/internal/KtorServerTracingUtil.kt | 2 +- .../v2_0/common/server/AbstractKtorServerTracingBuilder.kt | 1 + 12 files changed, 10 insertions(+), 10 deletions(-) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/{server => }/ApplicationRequestGetter.kt (88%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/{client => }/KtorHttpClientAttributesGetter.kt (95%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/{client => }/KtorHttpHeadersSetter.kt (75%) rename instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/{server => }/KtorHttpServerAttributesGetter.kt (96%) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetry.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetry.kt index 521e73bd1a5e..80729ec9c343 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetry.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetry.kt @@ -11,7 +11,6 @@ import io.ktor.client.statement.* import io.opentelemetry.context.Context import io.opentelemetry.context.propagation.ContextPropagators import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter -import io.opentelemetry.instrumentation.ktor.v2_0.common.client.KtorHttpHeadersSetter abstract class AbstractKtorClientTelemetry( private val instrumenter: Instrumenter, diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetryBuilder.kt index 076f759df385..2020c6e87a50 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetryBuilder.kt @@ -13,7 +13,6 @@ import io.opentelemetry.api.common.AttributesBuilder import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor -import io.opentelemetry.instrumentation.ktor.v2_0.common.client.KtorHttpClientAttributesGetter import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil abstract class AbstractKtorClientTelemetryBuilder( diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorServerTelemetryBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorServerTelemetryBuilder.kt index e171a1492aff..a73298ec76c7 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorServerTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorServerTelemetryBuilder.kt @@ -18,7 +18,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusBuilder import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtil -import io.opentelemetry.instrumentation.ktor.v2_0.common.server.KtorHttpServerAttributesGetter abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationName: String) { companion object { diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/ApplicationRequestGetter.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/ApplicationRequestGetter.kt similarity index 88% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/ApplicationRequestGetter.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/ApplicationRequestGetter.kt index cfe7e0b35a11..acd04567f1e3 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/ApplicationRequestGetter.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/ApplicationRequestGetter.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.common.server +package io.opentelemetry.instrumentation.ktor.v2_0.common import io.ktor.server.request.* import io.opentelemetry.context.propagation.TextMapGetter diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/KtorHttpClientAttributesGetter.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/KtorHttpClientAttributesGetter.kt similarity index 95% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/KtorHttpClientAttributesGetter.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/KtorHttpClientAttributesGetter.kt index 9d4a739dbae4..64df11c673e6 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/KtorHttpClientAttributesGetter.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/KtorHttpClientAttributesGetter.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.common.client +package io.opentelemetry.instrumentation.ktor.v2_0.common import io.ktor.client.request.* import io.ktor.client.statement.* diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/KtorHttpHeadersSetter.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/KtorHttpHeadersSetter.kt similarity index 75% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/KtorHttpHeadersSetter.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/KtorHttpHeadersSetter.kt index c04de9e9352e..dee42dc4fab4 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/KtorHttpHeadersSetter.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/KtorHttpHeadersSetter.kt @@ -3,9 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.common.client +package io.opentelemetry.instrumentation.ktor.v2_0.common -import io.ktor.client.request.HttpRequestBuilder +import io.ktor.client.request.* import io.opentelemetry.context.propagation.TextMapSetter internal object KtorHttpHeadersSetter : TextMapSetter { diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/KtorHttpServerAttributesGetter.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/KtorHttpServerAttributesGetter.kt similarity index 96% rename from instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/KtorHttpServerAttributesGetter.kt rename to instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/KtorHttpServerAttributesGetter.kt index d49daead2c9d..8c4ab938f53e 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/KtorHttpServerAttributesGetter.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/KtorHttpServerAttributesGetter.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.ktor.v2_0.common.server +package io.opentelemetry.instrumentation.ktor.v2_0.common import io.ktor.server.plugins.* import io.ktor.server.request.* diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTracing.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTracing.kt index 99d4f861622d..dc9cafba5b5f 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTracing.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTracing.kt @@ -11,6 +11,7 @@ import io.ktor.client.statement.* import io.opentelemetry.context.Context import io.opentelemetry.context.propagation.ContextPropagators import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter +import io.opentelemetry.instrumentation.ktor.v2_0.common.KtorHttpHeadersSetter @Deprecated("Use AbstractKtorClientTelemetry instead", ReplaceWith("AbstractKtorClientTelemetry")) abstract class AbstractKtorClientTracing( diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTracingBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTracingBuilder.kt index da5fb0764fd6..64609607497d 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTracingBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/client/AbstractKtorClientTracingBuilder.kt @@ -13,6 +13,7 @@ import io.opentelemetry.api.common.AttributesBuilder import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor +import io.opentelemetry.instrumentation.ktor.v2_0.common.KtorHttpClientAttributesGetter import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtilOld @Deprecated("Use AbstractKtorClientTelemetryBuilder instead", ReplaceWith("AbstractKtorClientTelemetryBuilder")) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt index c0ffdcebc7ac..37f04c8568da 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTelemetryUtil.kt @@ -16,7 +16,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor import io.opentelemetry.instrumentation.api.internal.InstrumenterUtil import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorServerTelemetryBuilder -import io.opentelemetry.instrumentation.ktor.v2_0.common.server.ApplicationRequestGetter +import io.opentelemetry.instrumentation.ktor.v2_0.common.ApplicationRequestGetter import kotlinx.coroutines.withContext /** diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracingUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracingUtil.kt index 1834e7c487e6..fb5758a097a6 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracingUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracingUtil.kt @@ -16,7 +16,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor import io.opentelemetry.instrumentation.api.internal.InstrumenterUtil import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTracingBuilder -import io.opentelemetry.instrumentation.ktor.v2_0.common.server.ApplicationRequestGetter +import io.opentelemetry.instrumentation.ktor.v2_0.common.ApplicationRequestGetter import kotlinx.coroutines.withContext /** diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTracingBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTracingBuilder.kt index 64c67b4d70ff..7abccf75b574 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTracingBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/server/AbstractKtorServerTracingBuilder.kt @@ -17,6 +17,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusBuilder import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor +import io.opentelemetry.instrumentation.ktor.v2_0.common.KtorHttpServerAttributesGetter import io.opentelemetry.instrumentation.ktor.v2_0.common.internal.KtorBuilderUtilOld @Deprecated("Use AbstractKtorServerTelemetryBuilder instead", ReplaceWith("AbstractKtorServerTelemetryBuilder")) From 76494b8ed04330a159e4e1c867ee682eebd63a02 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 11 Dec 2024 12:19:24 -0800 Subject: [PATCH 21/24] spotless --- .../ktor/v2_0/common/internal/KtorServerTracingUtil.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracingUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracingUtil.kt index fb5758a097a6..e03c8be47f08 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracingUtil.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracingUtil.kt @@ -15,8 +15,8 @@ import io.opentelemetry.extension.kotlin.asContextElement import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor import io.opentelemetry.instrumentation.api.internal.InstrumenterUtil -import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTracingBuilder import io.opentelemetry.instrumentation.ktor.v2_0.common.ApplicationRequestGetter +import io.opentelemetry.instrumentation.ktor.v2_0.common.server.AbstractKtorServerTracingBuilder import kotlinx.coroutines.withContext /** From 07a380b3ffe6bd0de30b8fcfd4c17b2486e29c8f Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 12 Dec 2024 14:28:05 -0800 Subject: [PATCH 22/24] Remove unused, and add experimental server telemetry --- .../v2_0/common/AbstractKtorClientTelemetryBuilder.kt | 8 -------- .../ktor/v2_0/common/internal/Experimental.kt | 5 +++++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetryBuilder.kt index f93a49f966a9..ddb10c6bc68b 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetryBuilder.kt @@ -116,12 +116,4 @@ abstract class AbstractKtorClientTelemetryBuilder( val response: HttpResponse?, val error: Throwable? ) - - /** - * Can be used via the unstable method {@link - * Experimental#setEmitExperimentalHttpClientMetrics(AbstractKtorClientTelemetryBuilder, boolean)}. - */ - internal fun emitExperimentalHttpClientMetrics() { - builder.setEmitExperimentalHttpClientMetrics(true) - } } diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/Experimental.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/Experimental.kt index f49c58d6c95b..2add55107800 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/Experimental.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/Experimental.kt @@ -6,6 +6,7 @@ package io.opentelemetry.instrumentation.ktor.v2_0.common.internal import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorClientTelemetryBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.common.AbstractKtorServerTelemetryBuilder class Experimental private constructor() { @@ -13,5 +14,9 @@ class Experimental private constructor() { fun emitExperimentalTelemetry(builder: AbstractKtorClientTelemetryBuilder) { builder.internalBuilder.setEmitExperimentalHttpClientMetrics(true) } + + fun emitExperimentalTelemetry(builder: AbstractKtorServerTelemetryBuilder) { + builder.builder.setEmitExperimentalHttpServerMetrics(true) + } } } From 6260a862251e508f7d6a4c0551fc0d26d8fc6bea Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 12 Dec 2024 14:32:27 -0800 Subject: [PATCH 23/24] test deprecated code --- .../ktor/v1_0/KtorHttpServerOldTest.kt | 143 ++++++++++++++++++ .../ktor/v1_0/KtorOldTestUtil.kt | 22 +++ .../ktor/v2_0/KtorHttpClientOldTest.kt | 28 ++++ .../ktor/v2_0/KtorHttpServerOldTest.kt | 28 ++++ .../ktor/v2_0/KtorOldTestUtil.kt | 23 +++ .../instrumentation/ktor/v2_0/KtorTestUtil.kt | 3 +- .../ktor/v3_0/KtorHttpClientOldTest.kt | 28 ++++ .../ktor/v3_0/KtorHttpServerOldTest.kt | 35 +++++ 8 files changed, 308 insertions(+), 2 deletions(-) create mode 100644 instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerOldTest.kt create mode 100644 instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorOldTestUtil.kt create mode 100644 instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpClientOldTest.kt create mode 100644 instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerOldTest.kt create mode 100644 instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorOldTestUtil.kt create mode 100644 instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpClientOldTest.kt create mode 100644 instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpServerOldTest.kt diff --git a/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerOldTest.kt b/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerOldTest.kt new file mode 100644 index 000000000000..3dc5c701a0fc --- /dev/null +++ b/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerOldTest.kt @@ -0,0 +1,143 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.v1_0 + +import io.ktor.application.* +import io.ktor.http.* +import io.ktor.request.* +import io.ktor.response.* +import io.ktor.routing.* +import io.ktor.server.engine.* +import io.ktor.server.netty.* +import io.opentelemetry.api.trace.Span +import io.opentelemetry.api.trace.SpanKind +import io.opentelemetry.api.trace.StatusCode +import io.opentelemetry.context.Context +import io.opentelemetry.extension.kotlin.asContextElement +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint +import io.opentelemetry.semconv.ServerAttributes +import kotlinx.coroutines.withContext +import org.junit.jupiter.api.extension.RegisterExtension +import java.util.concurrent.ExecutionException +import java.util.concurrent.TimeUnit + +class KtorHttpServerOldTest : AbstractHttpServerTest() { + + companion object { + @JvmStatic + @RegisterExtension + val testing = HttpServerInstrumentationExtension.forLibrary() + } + + override fun setupServer(): ApplicationEngine { + return embeddedServer(Netty, port = port) { + KtorOldTestUtil.installOpenTelemetry(this, testing.openTelemetry) + + routing { + get(ServerEndpoint.SUCCESS.path) { + controller(ServerEndpoint.SUCCESS) { + call.respondText(ServerEndpoint.SUCCESS.body, status = HttpStatusCode.fromValue(ServerEndpoint.SUCCESS.status)) + } + } + + get(ServerEndpoint.REDIRECT.path) { + controller(ServerEndpoint.REDIRECT) { + call.respondRedirect(ServerEndpoint.REDIRECT.body) + } + } + + get(ServerEndpoint.ERROR.path) { + controller(ServerEndpoint.ERROR) { + call.respondText(ServerEndpoint.ERROR.body, status = HttpStatusCode.fromValue(ServerEndpoint.ERROR.status)) + } + } + + get(ServerEndpoint.EXCEPTION.path) { + controller(ServerEndpoint.EXCEPTION) { + throw IllegalStateException(ServerEndpoint.EXCEPTION.body) + } + } + + get("/query") { + controller(ServerEndpoint.QUERY_PARAM) { + call.respondText("some=${call.request.queryParameters["some"]}", status = HttpStatusCode.fromValue(ServerEndpoint.QUERY_PARAM.status)) + } + } + + get("/path/{id}/param") { + controller(ServerEndpoint.PATH_PARAM) { + call.respondText( + call.parameters["id"] + ?: "", + status = HttpStatusCode.fromValue(ServerEndpoint.PATH_PARAM.status), + ) + } + } + + get("/child") { + controller(ServerEndpoint.INDEXED_CHILD) { + ServerEndpoint.INDEXED_CHILD.collectSpanAttributes { call.request.queryParameters[it] } + call.respondText(ServerEndpoint.INDEXED_CHILD.body, status = HttpStatusCode.fromValue(ServerEndpoint.INDEXED_CHILD.status)) + } + } + + get("/captureHeaders") { + controller(ServerEndpoint.CAPTURE_HEADERS) { + call.response.header("X-Test-Response", call.request.header("X-Test-Request") ?: "") + call.respondText(ServerEndpoint.CAPTURE_HEADERS.body, status = HttpStatusCode.fromValue(ServerEndpoint.CAPTURE_HEADERS.status)) + } + } + } + }.start() + } + + override fun stopServer(server: ApplicationEngine) { + server.stop(0, 10, TimeUnit.SECONDS) + } + + // Copy in HttpServerTest.controller but make it a suspending function + private suspend fun controller(endpoint: ServerEndpoint, wrapped: suspend () -> Unit) { + assert(Span.current().spanContext.isValid, { "Controller should have a parent span. " }) + if (endpoint == ServerEndpoint.NOT_FOUND) { + wrapped() + } + val span = testing.openTelemetry.getTracer("test").spanBuilder("controller").setSpanKind(SpanKind.INTERNAL).startSpan() + try { + withContext(Context.current().with(span).asContextElement()) { + wrapped() + } + span.end() + } catch (e: Exception) { + span.setStatus(StatusCode.ERROR) + span.recordException(if (e is ExecutionException) e.cause ?: e else e) + span.end() + throw e + } + } + + override fun configure(options: HttpServerTestOptions) { + options.setTestPathParam(true) + + options.setHttpAttributes { + HttpServerTestOptions.DEFAULT_HTTP_ATTRIBUTES - ServerAttributes.SERVER_PORT + } + + options.setExpectedHttpRoute { endpoint, method -> + when (endpoint) { + ServerEndpoint.PATH_PARAM -> "/path/{id}/param" + else -> expectedHttpRoute(endpoint, method) + } + } + // ktor does not have a controller lifecycle so the server span ends immediately when the + // response is sent, which is before the controller span finishes. + options.setVerifyServerSpanEndTime(false) + + options.setResponseCodeOnNonStandardHttpMethod(404) + } +} diff --git a/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorOldTestUtil.kt b/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorOldTestUtil.kt new file mode 100644 index 000000000000..e9ff18ea1565 --- /dev/null +++ b/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorOldTestUtil.kt @@ -0,0 +1,22 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.v1_0 + +import io.ktor.application.* +import io.opentelemetry.api.OpenTelemetry +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest + +class KtorOldTestUtil { + companion object { + fun installOpenTelemetry(application: Application, openTelemetry: OpenTelemetry) { + application.install(KtorServerTracing) { + setOpenTelemetry(openTelemetry) + setCapturedRequestHeaders(listOf(AbstractHttpServerTest.TEST_REQUEST_HEADER)) + setCapturedResponseHeaders(listOf(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) + } + } + } +} diff --git a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpClientOldTest.kt b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpClientOldTest.kt new file mode 100644 index 000000000000..be7dfca50080 --- /dev/null +++ b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpClientOldTest.kt @@ -0,0 +1,28 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.v2_0 + +import io.ktor.client.* +import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTracing +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension +import org.junit.jupiter.api.extension.RegisterExtension + +class KtorHttpClientOldTest : AbstractKtorHttpClientTest() { + + companion object { + @JvmStatic + @RegisterExtension + private val TESTING = HttpClientInstrumentationExtension.forLibrary() + } + + override fun HttpClientConfig<*>.installTracing() { + install(KtorClientTracing) { + setOpenTelemetry(TESTING.openTelemetry) + capturedRequestHeaders(TEST_REQUEST_HEADER) + capturedResponseHeaders(TEST_RESPONSE_HEADER) + } + } +} diff --git a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerOldTest.kt b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerOldTest.kt new file mode 100644 index 000000000000..d11469ac3a71 --- /dev/null +++ b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerOldTest.kt @@ -0,0 +1,28 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.v2_0 + +import io.ktor.server.application.* +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension +import org.junit.jupiter.api.extension.RegisterExtension + +class KtorHttpServerOldTest : AbstractKtorHttpServerTest() { + + companion object { + @JvmStatic + @RegisterExtension + val TESTING: InstrumentationExtension = HttpServerInstrumentationExtension.forLibrary() + } + + override fun getTesting(): InstrumentationExtension { + return TESTING + } + + override fun installOpenTelemetry(application: Application) { + KtorOldTestUtil.installOpenTelemetry(application, TESTING.openTelemetry) + } +} diff --git a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorOldTestUtil.kt b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorOldTestUtil.kt new file mode 100644 index 000000000000..10cc11f52222 --- /dev/null +++ b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorOldTestUtil.kt @@ -0,0 +1,23 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.v2_0 + +import io.ktor.server.application.* +import io.opentelemetry.api.OpenTelemetry +import io.opentelemetry.instrumentation.ktor.v2_0.server.KtorServerTracing +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest + +class KtorOldTestUtil { + companion object { + fun installOpenTelemetry(application: Application, openTelemetry: OpenTelemetry) { + application.install(KtorServerTracing) { + setOpenTelemetry(openTelemetry) + capturedRequestHeaders(AbstractHttpServerTest.TEST_REQUEST_HEADER) + capturedResponseHeaders(AbstractHttpServerTest.TEST_RESPONSE_HEADER) + } + } + } +} diff --git a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorTestUtil.kt b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorTestUtil.kt index 73fdf2052dce..dc85e9030b48 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorTestUtil.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorTestUtil.kt @@ -7,13 +7,12 @@ package io.opentelemetry.instrumentation.ktor.v2_0 import io.ktor.server.application.* import io.opentelemetry.api.OpenTelemetry -import io.opentelemetry.instrumentation.ktor.v2_0.server.KtorServerTracing import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest class KtorTestUtil { companion object { fun installOpenTelemetry(application: Application, openTelemetry: OpenTelemetry) { - application.install(KtorServerTracing) { + application.install(KtorServerTelemetry) { setOpenTelemetry(openTelemetry) capturedRequestHeaders(AbstractHttpServerTest.TEST_REQUEST_HEADER) capturedResponseHeaders(AbstractHttpServerTest.TEST_RESPONSE_HEADER) diff --git a/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpClientOldTest.kt b/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpClientOldTest.kt new file mode 100644 index 000000000000..89b0d57bae03 --- /dev/null +++ b/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpClientOldTest.kt @@ -0,0 +1,28 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.v3_0 + +import io.ktor.client.* +import io.opentelemetry.instrumentation.ktor.v3_0.client.KtorClientTracing +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension +import org.junit.jupiter.api.extension.RegisterExtension + +class KtorHttpClientOldTest : AbstractKtorHttpClientTest() { + + companion object { + @JvmStatic + @RegisterExtension + private val TESTING = HttpClientInstrumentationExtension.forLibrary() + } + + override fun HttpClientConfig<*>.installTracing() { + install(KtorClientTracing) { + setOpenTelemetry(TESTING.openTelemetry) + capturedRequestHeaders(TEST_REQUEST_HEADER) + capturedResponseHeaders(TEST_RESPONSE_HEADER) + } + } +} diff --git a/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpServerOldTest.kt b/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpServerOldTest.kt new file mode 100644 index 000000000000..5a92a1df2d15 --- /dev/null +++ b/instrumentation/ktor/ktor-3.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v3_0/KtorHttpServerOldTest.kt @@ -0,0 +1,35 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.v3_0 + +import io.ktor.server.application.* +import io.opentelemetry.instrumentation.ktor.v3_0.server.KtorServerTracing +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension +import org.junit.jupiter.api.extension.RegisterExtension + +class KtorHttpServerOldTest : AbstractKtorHttpServerTest() { + + companion object { + @JvmStatic + @RegisterExtension + val TESTING: InstrumentationExtension = HttpServerInstrumentationExtension.forLibrary() + } + + override fun getTesting(): InstrumentationExtension { + return TESTING + } + + override fun installOpenTelemetry(application: Application) { + application.apply { + install(KtorServerTracing) { + setOpenTelemetry(TESTING.openTelemetry) + capturedRequestHeaders(TEST_REQUEST_HEADER) + capturedResponseHeaders(TEST_RESPONSE_HEADER) + } + } + } +} From fc032cb049fdaa96b769c6b969d448210175b9a7 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Mon, 16 Dec 2024 19:02:27 -0800 Subject: [PATCH 24/24] simpler --- .../v2_0/common/AbstractKtorClientTelemetryBuilder.kt | 8 +++++--- .../ktor/v2_0/common/internal/Experimental.kt | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetryBuilder.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetryBuilder.kt index ddb10c6bc68b..f07d5c6764ed 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetryBuilder.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/AbstractKtorClientTelemetryBuilder.kt @@ -27,17 +27,19 @@ abstract class AbstractKtorClientTelemetryBuilder( } internal lateinit var openTelemetry: OpenTelemetry - internal lateinit var internalBuilder: DefaultHttpClientInstrumenterBuilder protected lateinit var builder: DefaultHttpClientInstrumenterBuilder + internal fun builder(): DefaultHttpClientInstrumenterBuilder { + return builder + } + fun setOpenTelemetry(openTelemetry: OpenTelemetry) { this.openTelemetry = openTelemetry - this.internalBuilder = DefaultHttpClientInstrumenterBuilder.create( + this.builder = DefaultHttpClientInstrumenterBuilder.create( instrumentationName, openTelemetry, KtorHttpClientAttributesGetter ) - this.builder = internalBuilder } protected fun getOpenTelemetry(): OpenTelemetry { diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/Experimental.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/Experimental.kt index 2add55107800..9fc388d14254 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/Experimental.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/Experimental.kt @@ -12,7 +12,7 @@ class Experimental private constructor() { companion object { fun emitExperimentalTelemetry(builder: AbstractKtorClientTelemetryBuilder) { - builder.internalBuilder.setEmitExperimentalHttpClientMetrics(true) + builder.builder().setEmitExperimentalHttpClientMetrics(true) } fun emitExperimentalTelemetry(builder: AbstractKtorServerTelemetryBuilder) {