Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix directory separator in ProcessResource attributes #6716

Merged
merged 3 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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;
Expand All @@ -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")
Copy link
Member

@trask trask Sep 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe something like .matches("[/\\]java")? e.g. to avoid the test verification relying on the same logic that we missed previously

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the tests accordingly.

.doesNotEndWith(".exe");
assertThat(attributes.get(ResourceAttributes.PROCESS_COMMAND_LINE))
.contains(attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH));
Expand All @@ -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));
Expand Down