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"); 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..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 @@ -28,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("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)); } @@ -44,8 +42,7 @@ void windows() { assertThat(attributes.get(ResourceAttributes.PROCESS_PID)).isGreaterThan(1); assertThat(attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH)) - .contains("java") - .endsWith(".exe"); + .matches(".*[/\\\\]java\\.exe"); assertThat(attributes.get(ResourceAttributes.PROCESS_COMMAND_LINE)) .contains(attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH)); }