Skip to content

Adaptive Instrumentation

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

Adaptive instrumentation

BTrace can gate probe handlers by instrumentation level. This lets a probe stay lightweight by default and enable more detailed handlers only when needed.

Define levels

Use enableAt = @Level(...) on @OnMethod:

@OnMethod(clazz = "com.example.Service", enableAt = @Level("=0"))
public static void lightHandler() {
  count();
}

@OnMethod(clazz = "com.example.Service", enableAt = @Level(">=1"))
public static void detailedHandler() {
  println(method);
}

Change the active level

Handlers can call:

BTraceUtils.setInstrumentationLevel(1);
int current = BTraceUtils.getInstrumentationLevel();

See the stable-release documentation for more information on level expressions, events, and sampling.

Clone this wiki locally