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

Populate process.command_args for Java 9+ and improve process.command_line for Java 8 #8130

Merged
merged 7 commits into from
Apr 13, 2023

Conversation

tylerbenson
Copy link
Member

@tylerbenson tylerbenson commented Mar 24, 2023

command_args is defined as:

All the command arguments (including the command/executable itself) as received by the process. On Linux-based systems (and some other Unixoid systems supporting procfs), can be set according to the list of null-delimited strings extracted from proc/[pid]/cmdline. For libc-based executables, this would be the full argv vector passed to main.

process.command_line only included vm arguments, not the program arguments:

The full command used to launch the process as a single string representing the full command. On Windows, can be set to the result of GetCommandLineW. Do not set this if you have to assemble it just for monitoring; use process.command_args instead.

Based on review below, I opted to only provide command_line for Java 8 and prefer command_args for Java 9+.

@tylerbenson tylerbenson requested a review from a team as a code owner March 24, 2023 14:52
@tylerbenson
Copy link
Member Author

When running the test in intellij, it generates an attribute like this:

attributes.get(ResourceAttributes.PROCESS_COMMAND_ARGS) = {ArrayList@2627}  size = 11
 0 = ".../Library/Java/JavaVirtualMachines/java/Contents/Home/bin/java"
 1 = "-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:64303,suspend=y,server=n"
 2 = "-ea"
 3 = "-Didea.test.cyclic.buffer.size=1048576"
 4 = "-javaagent:.../Library/Caches/JetBrains/IntelliJIdea/groovyHotSwap/gragent.jar"
 5 = "-javaagent:.../Library/Caches/JetBrains/IntelliJIdea/captureAgent/debugger-agent.jar=file:/private/var/folders/vj/.../T/capture1.props"
 6 = "-Dfile.encoding=UTF-8"
 7 = "com.intellij.rt.junit.JUnitStarter"
 8 = "-ideVersion5"
 9 = "-junit5"
 10 = "io.opentelemetry.instrumentation.resources.ProcessResourceTest"

`command_args` is defined as:
> All the command arguments (including the command/executable itself) as received by the process. On Linux-based systems (and some other Unixoid systems supporting procfs), can be set according to the list of null-delimited strings extracted from proc/[pid]/cmdline. For libc-based executables, this would be the full argv vector passed to main.

`process.command_line` only included vm arguments, not the program arguments:
> The full command used to launch the process as a single string representing the full command. On Windows, can be set to the result of GetCommandLineW. Do not set this if you have to assemble it just for monitoring; use process.command_args instead.

(I didn't remove `command_line` to maintain backward compatibility, but it should be removed in the future in favor of `command_args`.)
Not sure of a better way to do this without going to the proc file in linux... Java seems to forget about that param.
And only set `ResourceAttributes.PROCESS_COMMAND_LINE` if Java 8.

Without the actual `ProcessHandle` arguments command, we can't distinguish between `a b` vs `"a b"`.
@tylerbenson tylerbenson changed the title Populate process.command_args and fix process.command_line Populate process.command_args with Java 9+ and improve process.command_line for Java 8 Apr 10, 2023
@tylerbenson tylerbenson changed the title Populate process.command_args with Java 9+ and improve process.command_line for Java 8 Populate process.command_args for Java 9+ and improve process.command_line for Java 8 Apr 10, 2023
@tylerbenson tylerbenson force-pushed the tyler/command_args branch 2 times, most recently from aa25674 to c60d72a Compare April 11, 2023 17:41
@trask trask merged commit afc327e into open-telemetry:main Apr 13, 2023
@tylerbenson tylerbenson deleted the tyler/command_args branch April 13, 2023 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants