From 8c791b994f4dc6eb34038f6e1a2b0641d6d8ec18 Mon Sep 17 00:00:00 2001 From: Fabien Crespel Date: Wed, 21 Sep 2022 23:39:04 +0200 Subject: [PATCH 1/3] Fix directory separator in ProcessResource attributes --- .../instrumentation/resources/ProcessResource.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/resources/library/src/main/java/io/opentelemetry/instrumentation/resources/ProcessResource.java b/instrumentation/resources/library/src/main/java/io/opentelemetry/instrumentation/resources/ProcessResource.java index a1e881fe3575..4d2700555a3a 100644 --- a/instrumentation/resources/library/src/main/java/io/opentelemetry/instrumentation/resources/ProcessResource.java +++ b/instrumentation/resources/library/src/main/java/io/opentelemetry/instrumentation/resources/ProcessResource.java @@ -61,9 +61,9 @@ private static Resource doBuildResource() { if (javaHome != null) { StringBuilder executablePath = new StringBuilder(javaHome); executablePath - .append(File.pathSeparatorChar) + .append(File.separatorChar) .append("bin") - .append(File.pathSeparatorChar) + .append(File.separatorChar) .append("java"); if (osName != null && osName.toLowerCase().startsWith("windows")) { executablePath.append(".exe"); From a13f3a18d811f1b3802b9805828911feb0e9ecb6 Mon Sep 17 00:00:00 2001 From: Fabien Crespel Date: Fri, 23 Sep 2022 21:29:19 +0000 Subject: [PATCH 2/3] Update ProcessResourceTest with directory separator --- .../instrumentation/resources/ProcessResourceTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/instrumentation/resources/library/src/test/java/io/opentelemetry/instrumentation/resources/ProcessResourceTest.java b/instrumentation/resources/library/src/test/java/io/opentelemetry/instrumentation/resources/ProcessResourceTest.java index 8ba697bdc2ba..cd4aa23d74f9 100644 --- a/instrumentation/resources/library/src/test/java/io/opentelemetry/instrumentation/resources/ProcessResourceTest.java +++ b/instrumentation/resources/library/src/test/java/io/opentelemetry/instrumentation/resources/ProcessResourceTest.java @@ -10,6 +10,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; +import java.io.File; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -29,7 +30,7 @@ void notWindows() { assertThat(attributes.get(ResourceAttributes.PROCESS_PID)).isGreaterThan(1); assertThat(attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH)) - .contains("java") + .contains(File.separatorChar + "java") .doesNotEndWith(".exe"); assertThat(attributes.get(ResourceAttributes.PROCESS_COMMAND_LINE)) .contains(attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH)); @@ -44,7 +45,7 @@ void windows() { assertThat(attributes.get(ResourceAttributes.PROCESS_PID)).isGreaterThan(1); assertThat(attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH)) - .contains("java") + .contains(File.separatorChar + "java") .endsWith(".exe"); assertThat(attributes.get(ResourceAttributes.PROCESS_COMMAND_LINE)) .contains(attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH)); From 1ab1e6601d5256b55241e0d7858dbe24835d4fd4 Mon Sep 17 00:00:00 2001 From: Fabien Crespel Date: Sat, 24 Sep 2022 21:27:34 +0000 Subject: [PATCH 3/3] Update ProcessResourceTest --- .../instrumentation/resources/ProcessResourceTest.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/instrumentation/resources/library/src/test/java/io/opentelemetry/instrumentation/resources/ProcessResourceTest.java b/instrumentation/resources/library/src/test/java/io/opentelemetry/instrumentation/resources/ProcessResourceTest.java index cd4aa23d74f9..9fde20d97a72 100644 --- a/instrumentation/resources/library/src/test/java/io/opentelemetry/instrumentation/resources/ProcessResourceTest.java +++ b/instrumentation/resources/library/src/test/java/io/opentelemetry/instrumentation/resources/ProcessResourceTest.java @@ -10,7 +10,6 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; -import java.io.File; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -29,9 +28,7 @@ void notWindows() { Attributes attributes = resource.getAttributes(); assertThat(attributes.get(ResourceAttributes.PROCESS_PID)).isGreaterThan(1); - assertThat(attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH)) - .contains(File.separatorChar + "java") - .doesNotEndWith(".exe"); + assertThat(attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH)).matches(".*[/\\\\]java"); assertThat(attributes.get(ResourceAttributes.PROCESS_COMMAND_LINE)) .contains(attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH)); } @@ -45,8 +42,7 @@ void windows() { assertThat(attributes.get(ResourceAttributes.PROCESS_PID)).isGreaterThan(1); assertThat(attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH)) - .contains(File.separatorChar + "java") - .endsWith(".exe"); + .matches(".*[/\\\\]java\\.exe"); assertThat(attributes.get(ResourceAttributes.PROCESS_COMMAND_LINE)) .contains(attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH)); }