diff --git a/conventions/build.gradle.kts b/conventions/build.gradle.kts index 1989b30e52bd..e389c9cc0526 100644 --- a/conventions/build.gradle.kts +++ b/conventions/build.gradle.kts @@ -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.21.0") + implementation("com.diffplug.spotless:spotless-plugin-gradle:6.22.0") implementation("com.google.guava:guava:32.1.2-jre") implementation("gradle.plugin.com.google.protobuf:protobuf-gradle-plugin:0.8.18") implementation("com.github.johnrengelman:shadow:8.1.1") diff --git a/conventions/src/main/kotlin/otel.spotless-conventions.gradle.kts b/conventions/src/main/kotlin/otel.spotless-conventions.gradle.kts index 9c9ae5b0b838..3cb5868df939 100644 --- a/conventions/src/main/kotlin/otel.spotless-conventions.gradle.kts +++ b/conventions/src/main/kotlin/otel.spotless-conventions.gradle.kts @@ -74,7 +74,9 @@ spotless { // depends on ktlint_standard_wrapping "ktlint_standard_trailing-comma-on-declaration-site" to "disabled", // also very hard to find out where this happens - "ktlint_standard_wrapping" to "disabled" + "ktlint_standard_wrapping" to "disabled", + // we use variable names like v1_10Deps + "ktlint_standard_property-naming" to "disabled" ) ) } diff --git a/examples/distro/build.gradle b/examples/distro/build.gradle index 3d57b5ebc9ac..110dd2895744 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.21.0" + classpath "com.diffplug.spotless:spotless-plugin-gradle:6.22.0" classpath "gradle.plugin.com.github.johnrengelman:shadow:8.0.0" classpath "io.opentelemetry.instrumentation:gradle-plugins:1.31.0-alpha-SNAPSHOT" } diff --git a/instrumentation/gwt-2.0/javaagent/build.gradle.kts b/instrumentation/gwt-2.0/javaagent/build.gradle.kts index a1f77afd1f5f..7a94b9010330 100644 --- a/instrumentation/gwt-2.0/javaagent/build.gradle.kts +++ b/instrumentation/gwt-2.0/javaagent/build.gradle.kts @@ -62,13 +62,15 @@ val launcher = javaToolchains.launcherFor { class CompilerArgumentsProvider : CommandLineArgumentProvider { override fun asArguments(): Iterable = listOf( - "test.gwt.Greeting", // gwt module + // gwt module + "test.gwt.Greeting", "-war", layout.buildDirectory.dir("testapp/war").get().asFile.absolutePath, "-logLevel", "INFO", "-localWorkers", "2", "-compileReport", "-extra", layout.buildDirectory.dir("testapp/extra").get().asFile.absolutePath, - "-draftCompile", // makes compile a bit faster + // makes compile a bit faster + "-draftCompile", ) } diff --git a/instrumentation/kotlinx-coroutines/javaagent/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/KotlinCoroutinesInstrumentationTest.kt b/instrumentation/kotlinx-coroutines/javaagent/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/KotlinCoroutinesInstrumentationTest.kt index c0a8be58a5c6..a545a862b932 100644 --- a/instrumentation/kotlinx-coroutines/javaagent/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/KotlinCoroutinesInstrumentationTest.kt +++ b/instrumentation/kotlinx-coroutines/javaagent/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/KotlinCoroutinesInstrumentationTest.kt @@ -460,20 +460,20 @@ class KotlinCoroutinesInstrumentationTest { ) } - private val ANIMAL: ContextKey = ContextKey.named("animal") + private val animalKey: ContextKey = ContextKey.named("animal") @ParameterizedTest @ArgumentsSource(DispatchersSource::class) fun `context contains expected value`(dispatcher: DispatcherWrapper) { runTest(dispatcher) { - val context1 = Context.current().with(ANIMAL, "cat") + val context1 = Context.current().with(animalKey, "cat") runBlocking(context1.asContextElement()) { - assertThat(Context.current().get(ANIMAL)).isEqualTo("cat") - assertThat(coroutineContext.getOpenTelemetryContext().get(ANIMAL)).isEqualTo("cat") + assertThat(Context.current().get(animalKey)).isEqualTo("cat") + assertThat(coroutineContext.getOpenTelemetryContext().get(animalKey)).isEqualTo("cat") tracedChild("nested1") - withContext(context1.with(ANIMAL, "dog").asContextElement()) { - assertThat(Context.current().get(ANIMAL)).isEqualTo("dog") - assertThat(coroutineContext.getOpenTelemetryContext().get(ANIMAL)).isEqualTo("dog") + withContext(context1.with(animalKey, "dog").asContextElement()) { + assertThat(Context.current().get(animalKey)).isEqualTo("dog") + assertThat(coroutineContext.getOpenTelemetryContext().get(animalKey)).isEqualTo("dog") tracedChild("nested2") } } @@ -641,16 +641,15 @@ class KotlinCoroutinesInstrumentationTest { } class DispatchersSource : ArgumentsProvider { - override fun provideArguments(context: ExtensionContext?): Stream = - Stream.of( - // Wrap dispatchers since it seems that ParameterizedTest tries to automatically close - // Closeable arguments with no way to avoid it. - arguments(DispatcherWrapper(Dispatchers.Default)), - arguments(DispatcherWrapper(Dispatchers.IO)), - arguments(DispatcherWrapper(Dispatchers.Unconfined)), - arguments(DispatcherWrapper(threadPool.asCoroutineDispatcher())), - arguments(DispatcherWrapper(singleThread.asCoroutineDispatcher())), - ) + override fun provideArguments(context: ExtensionContext?): Stream = Stream.of( + // Wrap dispatchers since it seems that ParameterizedTest tries to automatically close + // Closeable arguments with no way to avoid it. + arguments(DispatcherWrapper(Dispatchers.Default)), + arguments(DispatcherWrapper(Dispatchers.IO)), + arguments(DispatcherWrapper(Dispatchers.Unconfined)), + arguments(DispatcherWrapper(threadPool.asCoroutineDispatcher())), + arguments(DispatcherWrapper(singleThread.asCoroutineDispatcher())), + ) } class DispatcherWrapper(val dispatcher: CoroutineDispatcher) { 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 1a9c896f4844..414d822eb79c 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 @@ -58,9 +58,7 @@ class KtorServerTracing private constructor( this.statusExtractor = extractor } - fun setSpanKindExtractor( - extractor: (SpanKindExtractor) -> SpanKindExtractor - ) { + fun setSpanKindExtractor(extractor: (SpanKindExtractor) -> SpanKindExtractor) { this.spanKindExtractor = extractor } 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 1de791433926..a2bdedd75c04 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 @@ -30,15 +30,13 @@ class KtorClientTracingBuilder { this.openTelemetry = openTelemetry } - fun setCapturedRequestHeaders(vararg headers: String) = - setCapturedRequestHeaders(headers.asList()) + fun setCapturedRequestHeaders(vararg headers: String) = setCapturedRequestHeaders(headers.asList()) fun setCapturedRequestHeaders(headers: List) { httpAttributesExtractorBuilder.setCapturedRequestHeaders(headers) } - fun setCapturedResponseHeaders(vararg headers: String) = - setCapturedResponseHeaders(headers.asList()) + fun setCapturedResponseHeaders(vararg headers: String) = setCapturedResponseHeaders(headers.asList()) fun setCapturedResponseHeaders(headers: List) { httpAttributesExtractorBuilder.setCapturedResponseHeaders(headers) @@ -49,8 +47,7 @@ class KtorClientTracingBuilder { httpSpanNameExtractorBuilder.setKnownMethods(knownMethods) } - fun addAttributesExtractors(vararg extractors: AttributesExtractor) = - addAttributesExtractors(extractors.asList()) + fun addAttributesExtractors(vararg extractors: AttributesExtractor) = addAttributesExtractors(extractors.asList()) fun addAttributesExtractors(extractors: Iterable>) { additionalExtractors += extractors @@ -61,9 +58,7 @@ class KtorClientTracingBuilder { * * @param emitExperimentalHttpClientMetrics `true` if the experimental HTTP client metrics are to be emitted. */ - fun setEmitExperimentalHttpClientMetrics( - emitExperimentalHttpClientMetrics: Boolean - ) { + fun setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics: Boolean) { this.emitExperimentalHttpClientMetrics = emitExperimentalHttpClientMetrics } diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorHttpClientAttributesGetter.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorHttpClientAttributesGetter.kt index c60aaf82fba6..850037aa74e0 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorHttpClientAttributesGetter.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorHttpClientAttributesGetter.kt @@ -11,23 +11,17 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttribut internal object KtorHttpClientAttributesGetter : HttpClientAttributesGetter { - override fun getUrlFull(request: HttpRequestData) = - request.url.toString() + override fun getUrlFull(request: HttpRequestData) = request.url.toString() - override fun getHttpRequestMethod(request: HttpRequestData) = - request.method.value + override fun getHttpRequestMethod(request: HttpRequestData) = request.method.value - override fun getHttpRequestHeader(request: HttpRequestData, name: String) = - request.headers.getAll(name).orEmpty() + override fun getHttpRequestHeader(request: HttpRequestData, name: String) = request.headers.getAll(name).orEmpty() - override fun getHttpResponseStatusCode(request: HttpRequestData, response: HttpResponse, error: Throwable?) = - response.status.value + override fun getHttpResponseStatusCode(request: HttpRequestData, response: HttpResponse, error: Throwable?) = response.status.value - override fun getHttpResponseHeader(request: HttpRequestData, response: HttpResponse, name: String) = - response.headers.getAll(name).orEmpty() + override fun getHttpResponseHeader(request: HttpRequestData, response: HttpResponse, name: String) = response.headers.getAll(name).orEmpty() - override fun getNetworkProtocolName(request: HttpRequestData?, response: HttpResponse?): String? = - response?.version?.name + override fun getNetworkProtocolName(request: HttpRequestData?, response: HttpResponse?): String? = response?.version?.name override fun getNetworkProtocolVersion(request: HttpRequestData?, response: HttpResponse?): String? { val version = response?.version ?: return null diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt index 86c765c93847..99f4696a066e 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt @@ -59,9 +59,7 @@ class KtorServerTracing private constructor( this.statusExtractor = extractor } - fun setSpanKindExtractor( - extractor: (SpanKindExtractor) -> SpanKindExtractor - ) { + fun setSpanKindExtractor(extractor: (SpanKindExtractor) -> SpanKindExtractor) { this.spanKindExtractor = extractor } 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 d67bb3a88993..37ef4d56d86c 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 @@ -30,12 +30,11 @@ abstract class AbstractKtorHttpClientTest : AbstractHttpClientTest.installTracing() - override fun buildRequest(requestMethod: String, uri: URI, requestHeaders: MutableMap) = - HttpRequestBuilder(uri.toURL()).apply { - method = HttpMethod.parse(requestMethod) + override fun buildRequest(requestMethod: String, uri: URI, requestHeaders: MutableMap) = HttpRequestBuilder(uri.toURL()).apply { + method = HttpMethod.parse(requestMethod) - requestHeaders.forEach { (header, value) -> headers.append(header, value) } - } + requestHeaders.forEach { (header, value) -> headers.append(header, value) } + } override fun sendRequest(request: HttpRequestBuilder, method: String, uri: URI, headers: MutableMap) = runBlocking { client.request(request).status.value 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 6c02eb39ee1b..ebc49ea136d0 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 @@ -9,17 +9,28 @@ import java.util.regex.Pattern // Source: Regular Expressions Cookbook 2nd edition - 8.17. // Matching IPv6 Addresses -private val ipv6 = Pattern.compile( // Non Compressed - "^(?:(?:(?:[A-F0-9]{1,4}:){6}" + // Compressed with at most 6 colons - "|(?=(?:[A-F0-9]{0,4}:){0,6}" + // and 4 bytes and anchored - "(?:[0-9]{1,3}\\.){3}[0-9]{1,3}(?![:.\\w]))" + // and at most 1 double colon - "(([0-9A-F]{1,4}:){0,5}|:)((:[0-9A-F]{1,4}){1,5}:|:)" + // Compressed with 7 colons and 5 numbers - "|::(?:[A-F0-9]{1,4}:){5})" + // 255.255.255. - "(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\\.){3}" + // 255 - "(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" + // Standard - "|(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}" + // Compressed with at most 7 colons and anchored - "|(?=(?:[A-F0-9]{0,4}:){0,7}[A-F0-9]{0,4}(?![:.\\w]))" + // and at most 1 double colon - "(([0-9A-F]{1,4}:){1,7}|:)((:[0-9A-F]{1,4}){1,7}|:)" + // Compressed with 8 colons +private val ipv6 = Pattern.compile( + // Non Compressed + "^(?:(?:(?:[A-F0-9]{1,4}:){6}" + + // Compressed with at most 6 colons + "|(?=(?:[A-F0-9]{0,4}:){0,6}" + + // and 4 bytes and anchored + "(?:[0-9]{1,3}\\.){3}[0-9]{1,3}(?![:.\\w]))" + + // and at most 1 double colon + "(([0-9A-F]{1,4}:){0,5}|:)((:[0-9A-F]{1,4}){1,5}:|:)" + + // Compressed with 7 colons and 5 numbers + "|::(?:[A-F0-9]{1,4}:){5})" + + // 255.255.255. + "(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\\.){3}" + + // 255 + "(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" + + // Standard + "|(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}" + + // Compressed with at most 7 colons and anchored + "|(?=(?:[A-F0-9]{0,4}:){0,7}[A-F0-9]{0,4}(?![:.\\w]))" + + // and at most 1 double colon + "(([0-9A-F]{1,4}:){1,7}|:)((:[0-9A-F]{1,4}){1,7}|:)" + + // Compressed with 8 colons "|(?:[A-F0-9]{1,4}:){7}:|:(:[A-F0-9]{1,4}){7})(?![:.\\w])\$", Pattern.CASE_INSENSITIVE, ) diff --git a/instrumentation/opentelemetry-extension-kotlin-1.0/javaagent/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/extensionkotlin/ContextExtensionInstrumentationTest.kt b/instrumentation/opentelemetry-extension-kotlin-1.0/javaagent/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/extensionkotlin/ContextExtensionInstrumentationTest.kt index f128de112a97..15fc7c6c28f9 100644 --- a/instrumentation/opentelemetry-extension-kotlin-1.0/javaagent/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/extensionkotlin/ContextExtensionInstrumentationTest.kt +++ b/instrumentation/opentelemetry-extension-kotlin-1.0/javaagent/src/test/kotlin/io/opentelemetry/javaagent/instrumentation/extensionkotlin/ContextExtensionInstrumentationTest.kt @@ -13,17 +13,17 @@ import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test class ContextExtensionInstrumentationTest { - private val ANIMAL: ContextKey = ContextKey.named("animal") + private val animalKey: ContextKey = ContextKey.named("animal") @Test fun `is instrumented`() { - val context1 = Context.root().with(ANIMAL, "cat") + val context1 = Context.root().with(animalKey, "cat") val contextElement = context1.asContextElement() // check that the context element is from the opentelemetry-extension-kotlin that is shaded // inside the agent assertThat(contextElement.javaClass.name).startsWith("io.opentelemetry.javaagent.shaded") val context2 = contextElement.getOpenTelemetryContext() - assertThat(context2.get(ANIMAL)).isEqualTo("cat") + assertThat(context2.get(animalKey)).isEqualTo("cat") // instrumentation does not preserve context identity due to conversion between application and // agent context assert(context1 != context2) { "Not instrumented" }