Skip to content

Commit

Permalink
Fix directory separator in ProcessResource attributes (open-telemetry…
Browse files Browse the repository at this point in the history
…#6716)

The separator char used to build the Java executable path in
ProcessResource is wrong: `File.pathSeparatorChar` is the PATH variable
separator (`:` on Linux, `;` on Windows), the right one for directories
is `File.separatorChar` (`/` on Linux, `\` on Windows).

Note that this issue was already present in
[sdk-extensions-resources](https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk-extensions/resources/src/main/java/io/opentelemetry/sdk/extension/resources/ProcessResource.java#L64)
before it was moved here; should it be fixed there too?
  • Loading branch information
fcrespel authored and LironKS committed Oct 23, 2022
1 parent 2f1e055 commit ca44a4e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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));
}
Expand Down

0 comments on commit ca44a4e

Please sign in to comment.