Skip to content

Trace Scripts

Jaroslav Bachorik edited this page Jul 12, 2026 · 4 revisions

Trace scripts

A trace script defines where BTrace instruments a target JVM and what it should report. Scripts are ordinary Java source with BTrace annotations.

Classic Java probe

@BTrace
public class SlowMethods {
  @OnMethod(clazz = "com.example.OrderService", method = "*")
  public static void onEntry(@ProbeMethodName String method) {
    println(method);
  }
}

Stable 2.2.x probes use org.openjdk.btrace packages.

Probe locations

Common locations include method entry, return, error, calls, field access, timers, and lifecycle events. See the BTrace annotations page for the supported annotations and arguments.

Safety and overhead

BTrace verifies probes before submission and restricts what injected code can do. Keep probes narrow, prefer thresholds and sampling on hot paths, and detach when the question is answered. See the stable source documentation.

For more examples, use the stable-release documentation.

Clone this wiki locally