explaingit

btraceio/btrace

5,991JavaAudience · developerComplexity · 3/5Setup · moderate

TLDR

A tool that lets you trace what a running Java application is doing, which methods are called, what data flows through them, without stopping the app or touching its source code.

Mindmap

mindmap
  root((BTrace))
    What it does
      Live JVM tracing
      Bytecode injection
      Safe observation only
    How it works
      Attach by process ID
      Compile script on attach
      Return data live
    CLI Tools
      btrace attach command
      btracec pre-compile
      btracer start with agent
    Safety Model
      No side effects
      Cannot crash app
      Restricted script actions
    Audience
      Java backend developers
      Production debuggers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Attach to a running production Java process and trace specific method calls without restarting the application.

USE CASE 2

Capture method arguments and return values in real time to diagnose a performance or correctness issue in production.

USE CASE 3

Pre-compile a BTrace script with btracec to validate it before attaching it to a live application.

Tech stack

JavaJVMMaven

Getting it running

Difficulty · moderate Time to first run · 30min

Scripts must follow BTrace's safety restrictions and the app must expose a JVM attach port, attaching to production may require explicit JVM flags.

License terms are not described in the explanation, contributing requires signing the Oracle Contributor Agreement.

In plain English

BTrace is a tool that lets you inspect a running Java application without stopping or modifying it. You write a small script that describes what you want to trace (for example, which methods to watch, what data to capture, or when to print output), then point BTrace at the process ID of a running Java application. BTrace injects the tracing instructions directly into the running application's bytecode, gathers the information, and returns it to you, all without restarting the application or changing its source code. The concept is similar to DTrace, a system-level tracing tool available on some Unix-based operating systems. BTrace brings the same general idea to the Java Virtual Machine layer: observe what a program is doing in production without interrupting it. The tool is designed to be safe by limiting what a tracing script can do, so it cannot crash or permanently alter the application it is attached to. Using BTrace involves three command-line tools. The btrace command attaches to a running process by its process ID, compiles your script on the spot, and starts the trace. The btracec command pre-compiles a script to a class file if you prefer to validate it separately. The btracer command starts a new Java application with the trace agent already loaded from the beginning. A Maven plugin is also available for projects that want to compile BTrace scripts as part of their build. The README is brief and points readers to the project's Wiki for a full user guide. Contributing code requires signing the Oracle Contributor Agreement before a pull request can be accepted.

Copy-paste prompts

Prompt 1
I want to trace calls to a specific method in my running Spring Boot app using BTrace. How do I write a minimal tracing script and attach it to the process by PID?
Prompt 2
I'm investigating a memory issue in a production Java app. How do I write a BTrace script that logs the arguments and return value of the suspected method each time it's called?
Prompt 3
I want to add BTrace script compilation to my Maven build so errors are caught before deployment. How do I configure the BTrace Maven plugin?
Open on GitHub → Explain another repo

← btraceio on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.