elastic / apm-agent-java

https://www.elastic.co/guide/en/apm/agent/java/current/index.html
Apache License 2.0
567 stars 321 forks source link

Improve process instrumentation for Java 9 #966

Open SylvainJuge opened 4 years ago

SylvainJuge commented 4 years ago

Problem description

This is an improvement on elastic/apm-agent-java#903 (external process execution instrumentation).

Starting from Java 9, there is a new API available for process execution ProcessHandle, which is not covered by #903. As a result, any usage of this API will not result in spans be created.

Proposed solution

Instrument Process.toHandle() to wrap returned ProcessHandle instance.

Wrapped ProcessHandle should end current process span on those methods

This would also allow to use ProcessHandle.Info and capture program arguments, PID or other attributes.

Alternatively, we could also use CompletableFuture.thenApply(...) to chain a task that will terminate the process span.

SylvainJuge commented 3 years ago

As part of #1613 adding support for Java 9 API here would probably allow to detect proper termination of process, hence being able to set the span outcome properly.