The jfr-connection
module provides a core library for configuring, starting, stopping,
and reading Java Flight Recording
files from a JVM. The code does not depend on the jdk.jfr
module and will compile and run against JDK 8 or higher. It uses a connection to an MBean
server, which can be the platform MBean server, or a remote MBean server connected by
means of JMX.
- Java 8+
- Build with
./gradlew :jfr-connection:build
The main entry point is io.opentelemetry.contrib.jfr.connection.FlightRecorderConnection
:
// The MBeanServerConnection can be local or remote
MBeanServerConnection mBeanServer = ManagementFactory.getPlatformMBeanServer();
FlightRecorderConnection flightRecorderConnection = FlightRecorderConnection.connect(mBeanServer);
RecordingOptions recordingOptions = new RecordingOptions.Builder().disk("true").build();
RecordingConfiguration recordingConfiguration = RecordingConfiguration.PROFILE_CONFIGURATION;
try (Recording recording = flightRecorderConnection.newRecording(recordingOptions, recordingConfiguration)) {
recording.start();
TimeUnit.SECONDS.sleep(10);
recording.stop();
recording.dump(Paths.get(System.getProperty("user.dir"), "recording.jfr").toString());
}
Note on Oracle JDK 8:
For Oracle JDK 8, it may be necessary to unlock the Java Flight Recorder
commercial feature with the JVM arg -XX:+UnlockCommercialFeatures -XX:+FlightRecorder
.
Starting with JDK 8u262, Java Flight Recorder is available for all OpenJDK distributions.
- Trask Stalnaker, Microsoft
- Jason Plumb, Splunk
- Jean Bisutti, Microsoft
- David Grieve, Microsoft
Learn more about component owners in component_owners.yml.