Skip to content

Commit 5c26f02

Browse files
authored
Code review sweep (run 25194642489) (#18466)
Co-authored-by: otelbot <197425009+otelbot@users.noreply.github.com>
1 parent f9fab4f commit 5c26f02

15 files changed

Lines changed: 41 additions & 31 deletions

File tree

instrumentation/kotlinx-coroutines/kotlinx-coroutines-flow-1.3/javaagent-kotlin/src/main/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/flow/FlowUtil.kt renamed to instrumentation/kotlinx-coroutines/kotlinx-coroutines-flow-1.3/javaagent-kotlin/src/main/kotlin/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/v1_0/flow/FlowUtil.kt

File renamed without changes.

instrumentation/kotlinx-coroutines/kotlinx-coroutines-flow-1.3/javaagent/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ muzzle {
1616
group.set("org.jetbrains.kotlinx")
1717
module.set("kotlinx-coroutines-core-jvm")
1818
versions.set("[1.3.9,)")
19+
assertInverse.set(true)
1920
}
2021
}
2122

instrumentation/ktor/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions
2323
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint
2424
import io.opentelemetry.semconv.ServerAttributes
2525
import kotlinx.coroutines.withContext
26+
import org.assertj.core.api.Assertions.assertThat
2627
import org.junit.jupiter.api.extension.RegisterExtension
2728
import java.util.concurrent.ExecutionException
2829
import java.util.concurrent.TimeUnit
@@ -101,7 +102,7 @@ class KtorHttpServerTest : AbstractHttpServerTest<ApplicationEngine>() {
101102

102103
// Copy in HttpServerTest.controller but make it a suspending function
103104
private suspend fun controller(endpoint: ServerEndpoint, wrapped: suspend () -> Unit) {
104-
assert(Span.current().spanContext.isValid, { "Controller should have a parent span. " })
105+
assertThat(Span.current().spanContext.isValid).isTrue()
105106
if (endpoint == ServerEndpoint.NOT_FOUND) {
106107
wrapped()
107108
return

instrumentation/ktor/ktor-2.0/testing/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorHttpClientSingleConnection.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import io.ktor.client.request.*
1010
import io.opentelemetry.instrumentation.testing.junit.http.SingleConnection
1111
import kotlinx.coroutines.runBlocking
1212

13-
class KtorHttpClientSingleConnection(
13+
internal class KtorHttpClientSingleConnection(
1414
private val client: HttpClient,
1515
private val host: String,
1616
private val port: Int

instrumentation/ktor/ktor-3.0/javaagent/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ tasks {
5959
classpath = sourceSets.test.get().runtimeClasspath
6060

6161
jvmArgs("-Dotel.instrumentation.http.server.emit-experimental-telemetry=true")
62+
systemProperty("metadataConfig", "otel.instrumentation.http.server.emit-experimental-telemetry=true")
6263
}
6364

6465
val testStableSemconv by registering(Test::class) {

instrumentation/ktor/ktor-3.0/metadata.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ configurations:
4747
type: list
4848
default: ""
4949
- name: otel.instrumentation.common.peer-service-mapping
50+
declarative_name: java.common.peer_service_mapping
5051
description: Used to specify a mapping from host names or IP addresses to peer services.
5152
type: map
5253
default: ""

instrumentation/ktor/ktor-common-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/common/v2_0/KtorHttpServerAttributesGetter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import java.lang.invoke.MethodType
1717

1818
internal object KtorHttpServerAttributesGetter : HttpServerAttributesGetter<ApplicationRequest, ApplicationResponse> {
1919

20-
private val getRemoteAddressMethodHandle: MethodHandle? = getRemoteAddressMethodHandle()
20+
private val GET_REMOTE_ADDRESS_METHOD_HANDLE: MethodHandle? = getRemoteAddressMethodHandle()
2121

2222
private fun getRemoteAddressMethodHandle(): MethodHandle? = try {
2323
MethodHandles.lookup().findVirtual(RequestConnectionPoint::class.java, "getRemoteAddress", MethodType.methodType(String::class.java))
@@ -44,12 +44,12 @@ internal object KtorHttpServerAttributesGetter : HttpServerAttributesGetter<Appl
4444
override fun getNetworkProtocolVersion(request: ApplicationRequest, response: ApplicationResponse?): String? = if (request.httpVersion.startsWith("HTTP/")) request.httpVersion.substring("HTTP/".length) else null
4545

4646
override fun getNetworkPeerAddress(request: ApplicationRequest, response: ApplicationResponse?): String? {
47-
if (getRemoteAddressMethodHandle == null) {
47+
if (GET_REMOTE_ADDRESS_METHOD_HANDLE == null) {
4848
return null
4949
}
5050

5151
val remote = try {
52-
getRemoteAddressMethodHandle.invoke(request.local) as String
52+
GET_REMOTE_ADDRESS_METHOD_HANDLE.invoke(request.local) as String
5353
} catch (ignored: Throwable) {
5454
"unknown"
5555
}

instrumentation/ktor/ktor-common-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/common/v2_0/internal/IsIpAddress.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import java.util.regex.Pattern
99

1010
// Source: Regular Expressions Cookbook 2nd edition - 8.17.
1111
// Matching IPv6 Addresses
12-
private val ipv6 = Pattern.compile(
12+
private val IPV6 = Pattern.compile(
1313
// Non Compressed
1414
"^(?:(?:(?:[A-F0-9]{1,4}:){6}" +
1515
// Compressed with at most 6 colons
@@ -37,9 +37,9 @@ private val ipv6 = Pattern.compile(
3737

3838
// Source: Regular Expressions Cookbook 2nd edition - 8.16.
3939
// Matching IPv4 Addresses
40-
private val ipv4 = Pattern.compile(
40+
private val IPV4 = Pattern.compile(
4141
"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}" +
4242
"(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\$",
4343
)
4444

45-
fun isIpAddress(address: String): Boolean = ipv4.matcher(address).matches() || ipv6.matcher(address).matches()
45+
fun isIpAddress(address: String): Boolean = IPV4.matcher(address).matches() || IPV6.matcher(address).matches()

instrumentation/ktor/ktor-common-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/common/v2_0/internal/KtorClientTelemetryUtil.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import kotlinx.coroutines.withContext
2424
* any time.
2525
*/
2626
object KtorClientTelemetryUtil {
27-
private val openTelemetryContextKey = AttributeKey<Context>("OpenTelemetry")
27+
private val OPEN_TELEMETRY_CONTEXT_KEY = AttributeKey<Context>("OpenTelemetry")
2828

2929
fun install(plugin: AbstractKtorClientTelemetry, scope: HttpClient) {
3030
installSpanCreation(plugin, scope)
@@ -49,7 +49,7 @@ object KtorClientTelemetryUtil {
4949

5050
if (openTelemetryContext != null) {
5151
try {
52-
requestBuilder.attributes.put(openTelemetryContextKey, openTelemetryContext)
52+
requestBuilder.attributes.put(OPEN_TELEMETRY_CONTEXT_KEY, openTelemetryContext)
5353
plugin.populateRequestHeaders(requestBuilder, openTelemetryContext)
5454

5555
withContext(openTelemetryContext.asContextElement()) { proceed() }
@@ -69,7 +69,7 @@ object KtorClientTelemetryUtil {
6969
scope.receivePipeline.insertPhaseBefore(HttpReceivePipeline.State, endSpanPhase)
7070

7171
scope.receivePipeline.intercept(endSpanPhase) {
72-
val openTelemetryContext = it.call.attributes.getOrNull(openTelemetryContextKey)
72+
val openTelemetryContext = it.call.attributes.getOrNull(OPEN_TELEMETRY_CONTEXT_KEY)
7373
openTelemetryContext ?: return@intercept
7474

7575
scope.launch {

instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/v7_0/ApiClientInstrumentation.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ public static class ExecuteAdvice {
8080

8181
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false)
8282
public static void onExit(
83-
@Advice.Return ApiResponse<?> response, @Advice.Thrown Throwable throwable) {
83+
@Advice.Return @Nullable ApiResponse<?> response,
84+
@Advice.Thrown @Nullable Throwable throwable) {
8485
CurrentState currentState = CurrentState.remove();
8586
if (currentState == null) {
8687
return;
@@ -119,7 +120,11 @@ public static Object[] onEnter(
119120

120121
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false)
121122
public static void onExit(
122-
@Advice.Thrown @Nullable Throwable throwable, @Advice.Enter Object[] enterResult) {
123+
@Advice.Thrown @Nullable Throwable throwable,
124+
@Advice.Enter @Nullable Object[] enterResult) {
125+
if (enterResult == null) {
126+
return;
127+
}
123128
CurrentState current = (CurrentState) enterResult[0];
124129
if (current != null) {
125130
current.getScope().close();

0 commit comments

Comments
 (0)