From c22bb598e506bff8ad2dc518f4f73a3ca031d0fb Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 8 Jan 2025 07:37:47 -0800 Subject: [PATCH] fix(deps): update spotless packages to v7 (major) (#13004) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Lauri Tulmin --- benchmark-overhead/build.gradle.kts | 2 +- conventions/build.gradle.kts | 4 +- .../otel.spotless-conventions.gradle.kts | 6 +- examples/distro/build.gradle | 2 +- examples/extension/build.gradle | 2 +- .../javaagent/build.gradle.kts | 4 +- .../jmx/engine/MetricRegistrar.java | 8 +- .../ExpandFramesClassVisitor.java | 20 +-- .../KotlinCoroutinesInstrumentationTest.kt | 8 +- .../kotlinxcoroutines/flow/FlowUtil.kt | 6 +- .../KotlinCoroutines13InstrumentationTest.kt | 4 +- .../ktor/v1_0/ApplicationRequestGetter.kt | 8 +- .../v1_0/KtorHttpServerAttributesGetter.kt | 37 ++---- .../ktor/v1_0/KtorServerTelemetry.kt | 10 +- .../ktor/v1_0/KtorServerTracing.kt | 10 +- .../ktor/v1_0/KtorHttpServerOldTest.kt | 114 +++++++++--------- .../ktor/v1_0/KtorHttpServerTest.kt | 114 +++++++++--------- .../v1_0/KtorServerSpanKindExtractorTest.kt | 50 ++++---- .../AbstractKtorClientTelemetryBuilder.kt | 12 +- .../AbstractKtorServerTelemetryBuilder.kt | 14 +-- .../v2_0/common/ApplicationRequestGetter.kt | 8 +- .../common/KtorHttpServerAttributesGetter.kt | 37 ++---- .../AbstractKtorClientTracingBuilder.kt | 8 +- .../internal/KtorServerTelemetryUtil.kt | 12 +- .../common/internal/KtorServerTracingUtil.kt | 12 +- .../AbstractKtorServerTracingBuilder.kt | 14 +-- .../ktor/v2_0/KtorHttpServerTest.kt | 4 +- .../ktor/v2_0/KtorHttpServerOldTest.kt | 4 +- .../ktor/v2_0/KtorHttpServerTest.kt | 4 +- .../v2_0/KtorServerSpanKindExtractorTest.kt | 48 ++++---- .../ktor/v2_0/AbstractKtorHttpServerTest.kt | 114 +++++++++--------- .../ktor/v3_0/KtorHttpServerTest.kt | 4 +- .../ktor/v3_0/KtorHttpServerOldTest.kt | 4 +- .../ktor/v3_0/KtorHttpServerTest.kt | 4 +- .../ktor/v3_0/AbstractKtorHttpServerTest.kt | 114 +++++++++--------- .../instrumentation/ktor/IsIpAddress.kt | 4 +- .../micrometer/v1_5/OpenTelemetryMeter.java | 4 +- .../netty-4.1/javaagent/build.gradle.kts | 3 +- .../redisson/RedissonRequest.java | 2 +- .../spring/data/v3_0/KotlinSpringDataTest.kt | 3 +- .../data/v3_0/repository/PersistenceConfig.kt | 24 ++-- 41 files changed, 387 insertions(+), 479 deletions(-) diff --git a/benchmark-overhead/build.gradle.kts b/benchmark-overhead/build.gradle.kts index 6e6fbb1898..7b5a020e7a 100644 --- a/benchmark-overhead/build.gradle.kts +++ b/benchmark-overhead/build.gradle.kts @@ -1,6 +1,6 @@ plugins { id("java") - id("com.diffplug.spotless") version "6.25.0" + id("com.diffplug.spotless") version "7.0.1" } spotless { diff --git a/conventions/build.gradle.kts b/conventions/build.gradle.kts index ca5bc14aca..24a0fba0a5 100644 --- a/conventions/build.gradle.kts +++ b/conventions/build.gradle.kts @@ -1,7 +1,7 @@ plugins { `kotlin-dsl` // When updating, update below in dependencies too - id("com.diffplug.spotless") version "6.25.0" + id("com.diffplug.spotless") version "7.0.1" } spotless { @@ -54,7 +54,7 @@ dependencies { implementation("org.apache.maven:maven-aether-provider:3.3.9") // When updating, update above in plugins too - implementation("com.diffplug.spotless:spotless-plugin-gradle:6.25.0") + implementation("com.diffplug.spotless:spotless-plugin-gradle:7.0.1") implementation("com.google.guava:guava:33.4.0-jre") implementation("gradle.plugin.com.google.protobuf:protobuf-gradle-plugin:0.8.18") implementation("com.gradleup.shadow:shadow-gradle-plugin:8.3.5") diff --git a/conventions/src/main/kotlin/otel.spotless-conventions.gradle.kts b/conventions/src/main/kotlin/otel.spotless-conventions.gradle.kts index 3cb5868df9..c3a3beb1cf 100644 --- a/conventions/src/main/kotlin/otel.spotless-conventions.gradle.kts +++ b/conventions/src/main/kotlin/otel.spotless-conventions.gradle.kts @@ -76,7 +76,9 @@ spotless { // also very hard to find out where this happens "ktlint_standard_wrapping" to "disabled", // we use variable names like v1_10Deps - "ktlint_standard_property-naming" to "disabled" + "ktlint_standard_property-naming" to "disabled", + // prevent moving comment to next line in latestDepTestLibrary("xxx") { // see xxx module + "ktlint_standard_function-literal" to "disabled" ) ) } @@ -97,7 +99,7 @@ if (project == rootProject) { "**/*.dockerfile", "**/gradle.properties" ) - indentWithSpaces() + leadingTabsToSpaces() trimTrailingWhitespace() endWithNewline() } diff --git a/examples/distro/build.gradle b/examples/distro/build.gradle index 8d9c8b2a18..af545d171d 100644 --- a/examples/distro/build.gradle +++ b/examples/distro/build.gradle @@ -12,7 +12,7 @@ buildscript { } } dependencies { - classpath "com.diffplug.spotless:spotless-plugin-gradle:6.25.0" + classpath "com.diffplug.spotless:spotless-plugin-gradle:7.0.1" classpath "com.gradleup.shadow:shadow-gradle-plugin:8.3.5" classpath "io.opentelemetry.instrumentation:gradle-plugins:2.12.0-alpha-SNAPSHOT" } diff --git a/examples/extension/build.gradle b/examples/extension/build.gradle index 87e0854dec..425309bd6b 100644 --- a/examples/extension/build.gradle +++ b/examples/extension/build.gradle @@ -11,7 +11,7 @@ plugins { See https://imperceptiblethoughts.com/shadow/ for more details about Shadow plugin. */ id "com.gradleup.shadow" version "8.3.5" - id "com.diffplug.spotless" version "6.25.0" + id "com.diffplug.spotless" version "7.0.1" id "io.opentelemetry.instrumentation.muzzle-generation" version "2.12.0-alpha-SNAPSHOT" id "io.opentelemetry.instrumentation.muzzle-check" version "2.12.0-alpha-SNAPSHOT" diff --git a/instrumentation/finagle-http-23.11/javaagent/build.gradle.kts b/instrumentation/finagle-http-23.11/javaagent/build.gradle.kts index 292ca2ac47..d9cc98b430 100644 --- a/instrumentation/finagle-http-23.11/javaagent/build.gradle.kts +++ b/instrumentation/finagle-http-23.11/javaagent/build.gradle.kts @@ -25,9 +25,7 @@ val scalaMinor = Regex("""^([0-9]+\.[0-9]+)\.?.*$""").find(scalaVersion)!!.run { minorVersion } -val scalified = fun(pack: String): String { - return "${pack}_$scalaMinor" -} +val scalified = fun(pack: String): String = "${pack}_$scalaMinor" dependencies { bootstrap(project(":instrumentation:executors:bootstrap")) diff --git a/instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricRegistrar.java b/instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricRegistrar.java index a984c7fd3d..482b1e99f3 100644 --- a/instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricRegistrar.java +++ b/instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/MetricRegistrar.java @@ -71,7 +71,7 @@ class MetricRegistrar { String unit = metricInfo.getUnit(); switch (instrumentType) { - // CHECKSTYLE:OFF + // CHECKSTYLE:OFF case COUNTER: { // CHECKSTYLE:ON @@ -88,7 +88,7 @@ class MetricRegistrar { } break; - // CHECKSTYLE:OFF + // CHECKSTYLE:OFF case UPDOWNCOUNTER: { // CHECKSTYLE:ON @@ -105,7 +105,7 @@ class MetricRegistrar { } break; - // CHECKSTYLE:OFF + // CHECKSTYLE:OFF case GAUGE: { // CHECKSTYLE:ON @@ -121,7 +121,7 @@ class MetricRegistrar { logger.log(INFO, "Created Gauge for {0}", metricName); } break; - // CHECKSTYLE:OFF + // CHECKSTYLE:OFF case STATE: { // CHECKSTYLE:ON diff --git a/instrumentation/kotlinx-coroutines/kotlinx-coroutines-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/instrumentationannotations/ExpandFramesClassVisitor.java b/instrumentation/kotlinx-coroutines/kotlinx-coroutines-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/instrumentationannotations/ExpandFramesClassVisitor.java index 71a7dcd55c..8171d68349 100644 --- a/instrumentation/kotlinx-coroutines/kotlinx-coroutines-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/instrumentationannotations/ExpandFramesClassVisitor.java +++ b/instrumentation/kotlinx-coroutines/kotlinx-coroutines-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/instrumentationannotations/ExpandFramesClassVisitor.java @@ -95,34 +95,34 @@ class ExpandFramesClassVisitor extends ClassVisitor { @Override public void visitFrame(int type, int numLocal, Object[] local, int numStack, Object[] stack) { switch (type) { - // An expanded frame. + // An expanded frame. case Opcodes.F_NEW: - // A compressed frame with complete frame data. + // A compressed frame with complete frame data. case Opcodes.F_FULL: copy(local, numLocal, currentLocals); copy(stack, numStack, currentStack); break; - // A compressed frame with exactly the same locals as the previous frame and with an empty - // stack. + // A compressed frame with exactly the same locals as the previous frame and with an empty + // stack. case Opcodes.F_SAME: currentStack.clear(); break; - // A compressed frame with exactly the same locals as the previous frame and with a single - // value on the stack. + // A compressed frame with exactly the same locals as the previous frame and with a single + // value on the stack. case Opcodes.F_SAME1: currentStack.clear(); currentStack.add(stack[0]); break; - // A compressed frame where locals are the same as the locals in the previous frame, - // except that additional 1-3 locals are defined, and with an empty stack. + // A compressed frame where locals are the same as the locals in the previous frame, + // except that additional 1-3 locals are defined, and with an empty stack. case Opcodes.F_APPEND: currentStack.clear(); for (int i = 0; i < numLocal; i++) { currentLocals.add(local[i]); } break; - // A compressed frame where locals are the same as the locals in the previous frame, - // except that the last 1-3 locals are absent and with an empty stack. + // A compressed frame where locals are the same as the locals in the previous frame, + // except that the last 1-3 locals are absent and with an empty stack. case Opcodes.F_CHOP: currentStack.clear(); for (Iterator iterator = diff --git a/instrumentation/kotlinx-coroutines/kotlinx-coroutines-1.0/javaagent/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/KotlinCoroutinesInstrumentationTest.kt b/instrumentation/kotlinx-coroutines/kotlinx-coroutines-1.0/javaagent/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/KotlinCoroutinesInstrumentationTest.kt index 9feeb198ce..f95bba0684 100644 --- a/instrumentation/kotlinx-coroutines/kotlinx-coroutines-1.0/javaagent/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/KotlinCoroutinesInstrumentationTest.kt +++ b/instrumentation/kotlinx-coroutines/kotlinx-coroutines-1.0/javaagent/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/KotlinCoroutinesInstrumentationTest.kt @@ -461,9 +461,7 @@ class KotlinCoroutinesInstrumentationTest { tracer.spanBuilder(opName).startSpan().end() } - private fun runTest(dispatcherWrapper: DispatcherWrapper, block: suspend CoroutineScope.() -> T): T { - return runTest(dispatcherWrapper.dispatcher, block) - } + private fun runTest(dispatcherWrapper: DispatcherWrapper, block: suspend CoroutineScope.() -> T): T = runTest(dispatcherWrapper.dispatcher, block) private fun runTest(dispatcher: CoroutineDispatcher, block: suspend CoroutineScope.() -> T): T { val parentSpan = tracer.spanBuilder("parent").startSpan() @@ -562,9 +560,7 @@ class KotlinCoroutinesInstrumentationTest { oldState.close() } - override fun updateThreadContext(context: CoroutineContext): Scope { - return otelContext.makeCurrent() - } + override fun updateThreadContext(context: CoroutineContext): Scope = otelContext.makeCurrent() } // regression test for diff --git a/instrumentation/kotlinx-coroutines/kotlinx-coroutines-flow-1.3/javaagent-kotlin/src/main/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/flow/FlowUtil.kt b/instrumentation/kotlinx-coroutines/kotlinx-coroutines-flow-1.3/javaagent-kotlin/src/main/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/flow/FlowUtil.kt index 65008f55ca..402251782c 100644 --- a/instrumentation/kotlinx-coroutines/kotlinx-coroutines-flow-1.3/javaagent-kotlin/src/main/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/flow/FlowUtil.kt +++ b/instrumentation/kotlinx-coroutines/kotlinx-coroutines-flow-1.3/javaagent-kotlin/src/main/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/flow/FlowUtil.kt @@ -10,8 +10,6 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.onCompletion -fun onComplete(flow: Flow<*>, instrumenter: Instrumenter, context: Context, request: REQUEST & Any): Flow<*> { - return flow.onCompletion { cause: Throwable? -> - instrumenter.end(context, request, null, cause) - } +fun onComplete(flow: Flow<*>, instrumenter: Instrumenter, context: Context, request: REQUEST & Any): Flow<*> = flow.onCompletion { cause: Throwable? -> + instrumenter.end(context, request, null, cause) } diff --git a/instrumentation/kotlinx-coroutines/kotlinx-coroutines-flow-1.3/javaagent/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/KotlinCoroutines13InstrumentationTest.kt b/instrumentation/kotlinx-coroutines/kotlinx-coroutines-flow-1.3/javaagent/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/KotlinCoroutines13InstrumentationTest.kt index ed6fc90b61..62902124a5 100644 --- a/instrumentation/kotlinx-coroutines/kotlinx-coroutines-flow-1.3/javaagent/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/KotlinCoroutines13InstrumentationTest.kt +++ b/instrumentation/kotlinx-coroutines/kotlinx-coroutines-flow-1.3/javaagent/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/KotlinCoroutines13InstrumentationTest.kt @@ -185,9 +185,7 @@ class KotlinCoroutines13InstrumentationTest { tracer.spanBuilder(opName).startSpan().end() } - private fun runTest(dispatcherWrapper: DispatcherWrapper, block: suspend CoroutineScope.() -> T): T { - return runTest(dispatcherWrapper.dispatcher, block) - } + private fun runTest(dispatcherWrapper: DispatcherWrapper, block: suspend CoroutineScope.() -> T): T = runTest(dispatcherWrapper.dispatcher, block) private fun runTest(dispatcher: CoroutineDispatcher, block: suspend CoroutineScope.() -> T): T { val parentSpan = tracer.spanBuilder("parent").startSpan() diff --git a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/ApplicationRequestGetter.kt b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/ApplicationRequestGetter.kt index edf3db8548..60313cfb4b 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/ApplicationRequestGetter.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/ApplicationRequestGetter.kt @@ -9,11 +9,7 @@ import io.ktor.request.* import io.opentelemetry.context.propagation.TextMapGetter internal object ApplicationRequestGetter : TextMapGetter { - override fun keys(carrier: ApplicationRequest): Iterable { - return carrier.headers.names() - } + override fun keys(carrier: ApplicationRequest): Iterable = carrier.headers.names() - override fun get(carrier: ApplicationRequest?, name: String): String? { - return carrier?.headers?.get(name) - } + override fun get(carrier: ApplicationRequest?, name: String): String? = carrier?.headers?.get(name) } diff --git a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerAttributesGetter.kt b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerAttributesGetter.kt index 8b4c5e5101..9a1bd475d2 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerAttributesGetter.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerAttributesGetter.kt @@ -11,43 +11,26 @@ import io.ktor.response.* import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesGetter import io.opentelemetry.instrumentation.ktor.isIpAddress -internal enum class KtorHttpServerAttributesGetter : - HttpServerAttributesGetter { +internal enum class KtorHttpServerAttributesGetter : HttpServerAttributesGetter { INSTANCE, ; - override fun getHttpRequestMethod(request: ApplicationRequest): String { - return request.httpMethod.value - } + override fun getHttpRequestMethod(request: ApplicationRequest): String = request.httpMethod.value - override fun getHttpRequestHeader(request: ApplicationRequest, name: String): List { - return request.headers.getAll(name) ?: emptyList() - } + override fun getHttpRequestHeader(request: ApplicationRequest, name: String): List = request.headers.getAll(name) ?: emptyList() - override fun getHttpResponseStatusCode(request: ApplicationRequest, response: ApplicationResponse, error: Throwable?): Int? { - return response.status()?.value - } + override fun getHttpResponseStatusCode(request: ApplicationRequest, response: ApplicationResponse, error: Throwable?): Int? = response.status()?.value - override fun getHttpResponseHeader(request: ApplicationRequest, response: ApplicationResponse, name: String): List { - return response.headers.allValues().getAll(name) ?: emptyList() - } + override fun getHttpResponseHeader(request: ApplicationRequest, response: ApplicationResponse, name: String): List = response.headers.allValues().getAll(name) ?: emptyList() - override fun getUrlScheme(request: ApplicationRequest): String { - return request.origin.scheme - } + override fun getUrlScheme(request: ApplicationRequest): String = request.origin.scheme - override fun getUrlPath(request: ApplicationRequest): String { - return request.path() - } + override fun getUrlPath(request: ApplicationRequest): String = request.path() - override fun getUrlQuery(request: ApplicationRequest): String { - return request.queryString() - } + override fun getUrlQuery(request: ApplicationRequest): String = request.queryString() - override fun getNetworkProtocolName(request: ApplicationRequest, response: ApplicationResponse?): String? = - if (request.httpVersion.startsWith("HTTP/")) "http" else null + override fun getNetworkProtocolName(request: ApplicationRequest, response: ApplicationResponse?): String? = if (request.httpVersion.startsWith("HTTP/")) "http" else null - override fun getNetworkProtocolVersion(request: ApplicationRequest, response: ApplicationResponse?): String? = - if (request.httpVersion.startsWith("HTTP/")) request.httpVersion.substring("HTTP/".length) else null + override fun getNetworkProtocolVersion(request: ApplicationRequest, response: ApplicationResponse?): String? = if (request.httpVersion.startsWith("HTTP/")) request.httpVersion.substring("HTTP/".length) else null override fun getNetworkPeerAddress(request: ApplicationRequest, response: ApplicationResponse?): String? { val remote = request.local.remoteHost 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 588bf41549..ccac1c8af9 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 @@ -48,10 +48,12 @@ class KtorServerTelemetry private constructor( extractor: (SpanStatusExtractor) -> SpanStatusExtractor ) { builder.setStatusExtractor { prevExtractor -> - SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder, - request: ApplicationRequest, - response: ApplicationResponse?, - throwable: Throwable? -> + SpanStatusExtractor { + spanStatusBuilder: SpanStatusBuilder, + request: ApplicationRequest, + response: ApplicationResponse?, + throwable: Throwable? + -> extractor(prevExtractor).extract(spanStatusBuilder, request, response, throwable) } } 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 1073053d06..3101b8c385 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 @@ -49,10 +49,12 @@ class KtorServerTracing private constructor( extractor: (SpanStatusExtractor) -> SpanStatusExtractor ) { builder.setStatusExtractor { prevExtractor -> - SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder, - request: ApplicationRequest, - response: ApplicationResponse?, - throwable: Throwable? -> + SpanStatusExtractor { + spanStatusBuilder: SpanStatusBuilder, + request: ApplicationRequest, + response: ApplicationResponse?, + throwable: Throwable? + -> extractor(prevExtractor).extract(spanStatusBuilder, request, response, throwable) } } 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 index 3dc5c701a0..828052cdb0 100644 --- 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 @@ -35,67 +35,65 @@ class KtorHttpServerOldTest : AbstractHttpServerTest() { val testing = HttpServerInstrumentationExtension.forLibrary() } - override fun setupServer(): ApplicationEngine { - return embeddedServer(Netty, port = port) { - KtorOldTestUtil.installOpenTelemetry(this, testing.openTelemetry) + override fun setupServer(): ApplicationEngine = 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)) - } + routing { + get(ServerEndpoint.SUCCESS.path) { + controller(ServerEndpoint.SUCCESS) { + call.respondText(ServerEndpoint.SUCCESS.body, status = HttpStatusCode.fromValue(ServerEndpoint.SUCCESS.status)) } } - }.start() - } + + 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) diff --git a/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerTest.kt b/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerTest.kt index 36258096a5..78cd9f22db 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerTest.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerTest.kt @@ -35,67 +35,65 @@ class KtorHttpServerTest : AbstractHttpServerTest() { val testing = HttpServerInstrumentationExtension.forLibrary() } - override fun setupServer(): ApplicationEngine { - return embeddedServer(Netty, port = port) { - KtorTestUtil.installOpenTelemetry(this, testing.openTelemetry) + override fun setupServer(): ApplicationEngine = embeddedServer(Netty, port = port) { + KtorTestUtil.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)) - } + routing { + get(ServerEndpoint.SUCCESS.path) { + controller(ServerEndpoint.SUCCESS) { + call.respondText(ServerEndpoint.SUCCESS.body, status = HttpStatusCode.fromValue(ServerEndpoint.SUCCESS.status)) } } - }.start() - } + + 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) 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 a494ed33ac..6e63807223 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 @@ -56,32 +56,30 @@ class KtorServerSpanKindExtractorTest : AbstractHttpServerUsingTest - if (req.uri.startsWith("/from-pubsub/")) { - SpanKind.CONSUMER - } else { - SpanKind.SERVER - } + override fun setupServer(): ApplicationEngine = embeddedServer(Netty, port = port) { + install(KtorServerTelemetry) { + setOpenTelemetry(testing.openTelemetry) + setSpanKindExtractor { + SpanKindExtractor { req -> + if (req.uri.startsWith("/from-pubsub/")) { + SpanKind.CONSUMER + } else { + SpanKind.SERVER } } } + } - routing { - post(consumerKindEndpoint.path) { - call.respondText(consumerKindEndpoint.body, status = HttpStatusCode.fromValue(consumerKindEndpoint.status)) - } - - post(serverKindEndpoint.path) { - call.respondText(serverKindEndpoint.body, status = HttpStatusCode.fromValue(serverKindEndpoint.status)) - } + routing { + post(consumerKindEndpoint.path) { + call.respondText(consumerKindEndpoint.body, status = HttpStatusCode.fromValue(consumerKindEndpoint.status)) } - }.start() - } + + post(serverKindEndpoint.path) { + call.respondText(serverKindEndpoint.body, status = HttpStatusCode.fromValue(serverKindEndpoint.status)) + } + } + }.start() override fun stopServer(server: ApplicationEngine) { server.stop(0, 10, TimeUnit.SECONDS) @@ -105,10 +103,8 @@ class KtorServerSpanKindExtractorTest : AbstractHttpServerUsingTest { - return Stream.of( - arguments(consumerKindEndpoint, SpanKind.CONSUMER), - arguments(serverKindEndpoint, SpanKind.SERVER), - ) - } + private fun provideArguments(): Stream = Stream.of( + arguments(consumerKindEndpoint, SpanKind.CONSUMER), + arguments(serverKindEndpoint, SpanKind.SERVER), + ) } 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 f07d5c6764..9a73fadd93 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 @@ -29,9 +29,7 @@ abstract class AbstractKtorClientTelemetryBuilder( internal lateinit var openTelemetry: OpenTelemetry protected lateinit var builder: DefaultHttpClientInstrumenterBuilder - internal fun builder(): DefaultHttpClientInstrumenterBuilder { - return builder - } + internal fun builder(): DefaultHttpClientInstrumenterBuilder = builder fun setOpenTelemetry(openTelemetry: OpenTelemetry) { this.openTelemetry = openTelemetry @@ -42,9 +40,7 @@ abstract class AbstractKtorClientTelemetryBuilder( ) } - protected fun getOpenTelemetry(): OpenTelemetry { - return openTelemetry - } + protected fun getOpenTelemetry(): OpenTelemetry = openTelemetry fun capturedRequestHeaders(vararg headers: String) = capturedRequestHeaders(headers.asIterable()) @@ -98,9 +94,7 @@ abstract class AbstractKtorClientTelemetryBuilder( onEnd = block } - internal fun build(): Extractor { - return Extractor(onStart, onEnd) - } + internal fun build(): Extractor = Extractor(onStart, onEnd) } internal class Extractor(val onStart: OnStartData.() -> Unit, val onEnd: OnEndData.() -> Unit) 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 2e042bea3f..781423dcfa 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 @@ -44,10 +44,12 @@ abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationNam fun spanStatusExtractor(extract: SpanStatusData.(SpanStatusExtractor) -> Unit) { builder.setStatusExtractor { prevExtractor -> - SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder, - request: ApplicationRequest, - response: ApplicationResponse?, - throwable: Throwable? -> + SpanStatusExtractor { + spanStatusBuilder: SpanStatusBuilder, + request: ApplicationRequest, + response: ApplicationResponse?, + throwable: Throwable? + -> extract( SpanStatusData(spanStatusBuilder, request, response, throwable), prevExtractor @@ -102,9 +104,7 @@ abstract class AbstractKtorServerTelemetryBuilder(private val instrumentationNam onEnd = block } - internal fun build(): Extractor { - return Extractor(onStart, onEnd) - } + internal fun build(): Extractor = Extractor(onStart, onEnd) } internal class Extractor(val onStart: OnStartData.() -> Unit, val onEnd: OnEndData.() -> Unit) diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/ApplicationRequestGetter.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/ApplicationRequestGetter.kt index acd04567f1..f11cd9513e 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/ApplicationRequestGetter.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/ApplicationRequestGetter.kt @@ -9,11 +9,7 @@ import io.ktor.server.request.* import io.opentelemetry.context.propagation.TextMapGetter internal object ApplicationRequestGetter : TextMapGetter { - override fun keys(carrier: ApplicationRequest): Iterable { - return carrier.headers.names() - } + override fun keys(carrier: ApplicationRequest): Iterable = carrier.headers.names() - override fun get(carrier: ApplicationRequest?, name: String): String? { - return carrier?.headers?.get(name) - } + override fun get(carrier: ApplicationRequest?, name: String): String? = carrier?.headers?.get(name) } diff --git a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/KtorHttpServerAttributesGetter.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/KtorHttpServerAttributesGetter.kt index 8c4ab938f5..92f3cb84a9 100644 --- a/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/KtorHttpServerAttributesGetter.kt +++ b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/KtorHttpServerAttributesGetter.kt @@ -11,43 +11,26 @@ import io.ktor.server.response.* import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesGetter import io.opentelemetry.instrumentation.ktor.isIpAddress -internal enum class KtorHttpServerAttributesGetter : - HttpServerAttributesGetter { +internal enum class KtorHttpServerAttributesGetter : HttpServerAttributesGetter { INSTANCE; - override fun getHttpRequestMethod(request: ApplicationRequest): String { - return request.httpMethod.value - } + override fun getHttpRequestMethod(request: ApplicationRequest): String = request.httpMethod.value - override fun getHttpRequestHeader(request: ApplicationRequest, name: String): List { - return request.headers.getAll(name) ?: emptyList() - } + override fun getHttpRequestHeader(request: ApplicationRequest, name: String): List = request.headers.getAll(name) ?: emptyList() - override fun getHttpResponseStatusCode(request: ApplicationRequest, response: ApplicationResponse, error: Throwable?): Int? { - return response.status()?.value - } + override fun getHttpResponseStatusCode(request: ApplicationRequest, response: ApplicationResponse, error: Throwable?): Int? = response.status()?.value - override fun getHttpResponseHeader(request: ApplicationRequest, response: ApplicationResponse, name: String): List { - return response.headers.allValues().getAll(name) ?: emptyList() - } + override fun getHttpResponseHeader(request: ApplicationRequest, response: ApplicationResponse, name: String): List = response.headers.allValues().getAll(name) ?: emptyList() - override fun getUrlScheme(request: ApplicationRequest): String { - return request.origin.scheme - } + override fun getUrlScheme(request: ApplicationRequest): String = request.origin.scheme - override fun getUrlPath(request: ApplicationRequest): String { - return request.path() - } + override fun getUrlPath(request: ApplicationRequest): String = request.path() - override fun getUrlQuery(request: ApplicationRequest): String { - return request.queryString() - } + override fun getUrlQuery(request: ApplicationRequest): String = request.queryString() - override fun getNetworkProtocolName(request: ApplicationRequest, response: ApplicationResponse?): String? = - if (request.httpVersion.startsWith("HTTP/")) "http" else null + override fun getNetworkProtocolName(request: ApplicationRequest, response: ApplicationResponse?): String? = if (request.httpVersion.startsWith("HTTP/")) "http" else null - override fun getNetworkProtocolVersion(request: ApplicationRequest, response: ApplicationResponse?): String? = - if (request.httpVersion.startsWith("HTTP/")) request.httpVersion.substring("HTTP/".length) else null + override fun getNetworkProtocolVersion(request: ApplicationRequest, response: ApplicationResponse?): String? = if (request.httpVersion.startsWith("HTTP/")) request.httpVersion.substring("HTTP/".length) else null override fun getNetworkPeerAddress(request: ApplicationRequest, response: ApplicationResponse?): String? { val remote = request.local.remoteHost 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 12bff47951..4c4bb8ed48 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 @@ -40,9 +40,7 @@ abstract class AbstractKtorClientTracingBuilder( ) } - protected fun getOpenTelemetry(): OpenTelemetry { - return openTelemetry - } + protected fun getOpenTelemetry(): OpenTelemetry = openTelemetry @Deprecated( "Please use method `capturedRequestHeaders`", @@ -137,9 +135,7 @@ abstract class AbstractKtorClientTracingBuilder( onEnd = block } - internal fun build(): Extractor { - return Extractor(onStart, onEnd) - } + internal fun build(): Extractor = Extractor(onStart, onEnd) } internal class Extractor(val onStart: OnStartData.() -> Unit, val onEnd: OnEndData.() -> Unit) 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 37f04c8568..832fc390c5 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 @@ -73,11 +73,9 @@ object KtorServerTelemetryUtil { } } - private fun instrumenter(builder: AbstractKtorServerTelemetryBuilder): Instrumenter { - return InstrumenterUtil.buildUpstreamInstrumenter( - builder.builder.instrumenterBuilder(), - ApplicationRequestGetter, - builder.spanKindExtractor(SpanKindExtractor.alwaysServer()) - ) - } + private fun instrumenter(builder: AbstractKtorServerTelemetryBuilder): Instrumenter = InstrumenterUtil.buildUpstreamInstrumenter( + 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/internal/KtorServerTracingUtil.kt b/instrumentation/ktor/ktor-2-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/common/internal/KtorServerTracingUtil.kt index e03c8be47f..c773189abd 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 @@ -74,11 +74,9 @@ object KtorServerTracingUtil { } } - private fun instrumenter(builder: AbstractKtorServerTracingBuilder): Instrumenter { - return InstrumenterUtil.buildUpstreamInstrumenter( - builder.serverBuilder.instrumenterBuilder(), - ApplicationRequestGetter, - builder.spanKindExtractor(SpanKindExtractor.alwaysServer()) - ) - } + private fun instrumenter(builder: AbstractKtorServerTracingBuilder): Instrumenter = 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/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 8064f208a2..9fec8fb5c7 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 @@ -55,10 +55,12 @@ abstract class AbstractKtorServerTracingBuilder(private val instrumentationName: fun spanStatusExtractor(extract: SpanStatusData.(SpanStatusExtractor) -> Unit) { serverBuilder.setStatusExtractor { prevExtractor -> - SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder, - request: ApplicationRequest, - response: ApplicationResponse?, - throwable: Throwable? -> + SpanStatusExtractor { + spanStatusBuilder: SpanStatusBuilder, + request: ApplicationRequest, + response: ApplicationResponse?, + throwable: Throwable? + -> extract( SpanStatusData(spanStatusBuilder, request, response, throwable), prevExtractor @@ -132,9 +134,7 @@ abstract class AbstractKtorServerTracingBuilder(private val instrumentationName: onEnd = block } - internal fun build(): Extractor { - return Extractor(onStart, onEnd) - } + internal fun build(): Extractor = Extractor(onStart, onEnd) } internal class Extractor(val onStart: OnStartData.() -> Unit, val onEnd: OnEndData.() -> Unit) diff --git a/instrumentation/ktor/ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerTest.kt b/instrumentation/ktor/ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerTest.kt index ec212c5399..4507b4ca0f 100644 --- a/instrumentation/ktor/ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerTest.kt +++ b/instrumentation/ktor/ktor-2.0/javaagent/src/test/java/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerTest.kt @@ -19,9 +19,7 @@ class KtorHttpServerTest : AbstractKtorHttpServerTest() { val TESTING: InstrumentationExtension = HttpServerInstrumentationExtension.forAgent() } - override fun getTesting(): InstrumentationExtension { - return TESTING - } + override fun getTesting(): InstrumentationExtension = TESTING override fun installOpenTelemetry(application: Application) { } 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 index d11469ac3a..f2c747b61a 100644 --- 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 @@ -18,9 +18,7 @@ class KtorHttpServerOldTest : AbstractKtorHttpServerTest() { val TESTING: InstrumentationExtension = HttpServerInstrumentationExtension.forLibrary() } - override fun getTesting(): InstrumentationExtension { - return TESTING - } + override fun getTesting(): InstrumentationExtension = 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/KtorHttpServerTest.kt b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpServerTest.kt index ef76aac9cd..5a48603ecd 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 @@ -18,9 +18,7 @@ class KtorHttpServerTest : AbstractKtorHttpServerTest() { val TESTING: InstrumentationExtension = HttpServerInstrumentationExtension.forLibrary() } - override fun getTesting(): InstrumentationExtension { - return TESTING - } + override fun getTesting(): InstrumentationExtension = TESTING override fun installOpenTelemetry(application: Application) { KtorTestUtil.installOpenTelemetry(application, TESTING.openTelemetry) diff --git a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorServerSpanKindExtractorTest.kt b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorServerSpanKindExtractorTest.kt index 9605454d3b..645460ce73 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorServerSpanKindExtractorTest.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorServerSpanKindExtractorTest.kt @@ -56,30 +56,28 @@ class KtorServerSpanKindExtractorTest : AbstractHttpServerUsingTest { - return Stream.of( - arguments(consumerKindEndpoint, SpanKind.CONSUMER), - arguments(serverKindEndpoint, SpanKind.SERVER), - ) - } + private fun provideArguments(): Stream = Stream.of( + arguments(consumerKindEndpoint, SpanKind.CONSUMER), + arguments(serverKindEndpoint, SpanKind.SERVER), + ) } diff --git a/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/AbstractKtorHttpServerTest.kt b/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/AbstractKtorHttpServerTest.kt index 863492509c..aaeea35eb5 100644 --- a/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/AbstractKtorHttpServerTest.kt +++ b/instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/AbstractKtorHttpServerTest.kt @@ -32,67 +32,65 @@ abstract class AbstractKtorHttpServerTest : AbstractHttpServerTest { - return embeddedServer(Netty, port = port) { - installOpenTelemetry(this) + override fun setupServer(): EmbeddedServer<*, *> = embeddedServer(Netty, port = port) { + installOpenTelemetry(this) - 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)) - } + routing { + get(ServerEndpoint.SUCCESS.path) { + controller(ServerEndpoint.SUCCESS) { + call.respondText(ServerEndpoint.SUCCESS.body, status = HttpStatusCode.fromValue(ServerEndpoint.SUCCESS.status)) } } - }.start() - } + + 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: EmbeddedServer<*, *>) { server.stop(0, 10, TimeUnit.SECONDS) diff --git a/instrumentation/ktor/ktor-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/IsIpAddress.kt b/instrumentation/ktor/ktor-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/IsIpAddress.kt index ebc49ea136..2dcf476fd8 100644 --- a/instrumentation/ktor/ktor-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/IsIpAddress.kt +++ b/instrumentation/ktor/ktor-common/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/IsIpAddress.kt @@ -42,6 +42,4 @@ private val ipv4 = Pattern.compile( "(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\$", ) -fun isIpAddress(address: String): Boolean { - return ipv4.matcher(address).matches() || ipv6.matcher(address).matches() -} +fun isIpAddress(address: String): Boolean = ipv4.matcher(address).matches() || ipv6.matcher(address).matches() diff --git a/instrumentation/micrometer/micrometer-1.5/library/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/OpenTelemetryMeter.java b/instrumentation/micrometer/micrometer-1.5/library/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/OpenTelemetryMeter.java index 93a0bf0758..8644ef6155 100644 --- a/instrumentation/micrometer/micrometer-1.5/library/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/OpenTelemetryMeter.java +++ b/instrumentation/micrometer/micrometer-1.5/library/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/OpenTelemetryMeter.java @@ -40,7 +40,7 @@ final class OpenTelemetryMeter extends AbstractMeter implements Meter, Removable switch (measurement.getStatistic()) { case TOTAL: - // fall through + // fall through case TOTAL_TIME: case COUNT: observableInstruments.add( @@ -63,7 +63,7 @@ final class OpenTelemetryMeter extends AbstractMeter implements Meter, Removable break; case DURATION: - // fall through + // fall through case MAX: case VALUE: case UNKNOWN: diff --git a/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts b/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts index 050eea01a4..7378e34c37 100644 --- a/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts +++ b/instrumentation/netty/netty-4.1/javaagent/build.gradle.kts @@ -74,7 +74,8 @@ if (!(findProperty("testLatestDeps") as Boolean)) { configurations.configureEach { if (!name.contains("muzzle")) { resolutionStrategy.eachDependency { - if (requested.group == "io.netty" && requested.name != "netty-bom" && + if (requested.group == "io.netty" && + requested.name != "netty-bom" && !requested.name.startsWith("netty-transport-native") && !requested.name.startsWith("netty-transport-classes")) { useVersion("4.1.0.Final") diff --git a/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonRequest.java b/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonRequest.java index 06f1677279..2bf432f4b0 100644 --- a/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonRequest.java +++ b/instrumentation/redisson/redisson-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonRequest.java @@ -60,7 +60,7 @@ public abstract class RedissonRequest { switch (sanitizedStatements.size()) { case 0: return null; - // optimize for the most common case + // optimize for the most common case case 1: return sanitizedStatements.get(0); default: diff --git a/instrumentation/spring/spring-data/spring-data-3.0/kotlin-testing/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/spring/data/v3_0/KotlinSpringDataTest.kt b/instrumentation/spring/spring-data/spring-data-3.0/kotlin-testing/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/spring/data/v3_0/KotlinSpringDataTest.kt index 00bf53d148..e493fd68a2 100644 --- a/instrumentation/spring/spring-data/spring-data-3.0/kotlin-testing/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/spring/data/v3_0/KotlinSpringDataTest.kt +++ b/instrumentation/spring/spring-data/spring-data-3.0/kotlin-testing/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/spring/data/v3_0/KotlinSpringDataTest.kt @@ -48,8 +48,7 @@ class KotlinSpringDataTest { Assertions.assertThat(customer?.name).isEqualTo("Name") } - testing.waitAndAssertTraces({ - trace -> + testing.waitAndAssertTraces({ trace -> trace.hasSpansSatisfyingExactly({ it.hasName("CustomerRepository.findById").hasNoParent() }, { diff --git a/instrumentation/spring/spring-data/spring-data-3.0/kotlin-testing/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/spring/data/v3_0/repository/PersistenceConfig.kt b/instrumentation/spring/spring-data/spring-data-3.0/kotlin-testing/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/spring/data/v3_0/repository/PersistenceConfig.kt index 4b2f1e463e..2a742fca98 100644 --- a/instrumentation/spring/spring-data/spring-data-3.0/kotlin-testing/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/spring/data/v3_0/repository/PersistenceConfig.kt +++ b/instrumentation/spring/spring-data/spring-data-3.0/kotlin-testing/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/spring/data/v3_0/repository/PersistenceConfig.kt @@ -23,19 +23,17 @@ import java.nio.charset.StandardCharsets class PersistenceConfig { @Bean - fun connectionFactory(): ConnectionFactory? { - return ConnectionFactories.find( - ConnectionFactoryOptions.builder() - .option(ConnectionFactoryOptions.DRIVER, "h2") - .option(ConnectionFactoryOptions.PROTOCOL, "mem") - .option(ConnectionFactoryOptions.HOST, "localhost") - .option(ConnectionFactoryOptions.USER, "sa") - .option(ConnectionFactoryOptions.PASSWORD, "") - .option(ConnectionFactoryOptions.DATABASE, "db") - .option(Option.valueOf("DB_CLOSE_DELAY"), "-1") - .build() - ) - } + fun connectionFactory(): ConnectionFactory? = ConnectionFactories.find( + ConnectionFactoryOptions.builder() + .option(ConnectionFactoryOptions.DRIVER, "h2") + .option(ConnectionFactoryOptions.PROTOCOL, "mem") + .option(ConnectionFactoryOptions.HOST, "localhost") + .option(ConnectionFactoryOptions.USER, "sa") + .option(ConnectionFactoryOptions.PASSWORD, "") + .option(ConnectionFactoryOptions.DATABASE, "db") + .option(Option.valueOf("DB_CLOSE_DELAY"), "-1") + .build() + ) @Bean fun initializer(connectionFactory: ConnectionFactory): ConnectionFactoryInitializer {