Detrix Rust Client
Debug-on-demand observability library for Rust applications. Enables AI-powered debugging of running Rust processes without code modifications or restarts.
Features
- Zero overhead when sleeping: No debugger loaded until explicitly woken
- No code changes required: Add metrics to any line of code at runtime
- Production-safe: Non-breaking observation points (logpoints) that don't pause execution
- Clean lifecycle: Unlike Python's debugpy, LLDB can be fully stopped on sleep
Installation
Add to your Cargo.toml:
[]
= "1.0.0"
Quick Start
use ;
Try It
Run the end-to-end example that simulates an AI agent: builds a sample app, wakes it, adds metrics, and captures events.
# 1. Start the Detrix server
# 2. Run the agent simulation (from clients/rust/)
Other examples in examples/:
| Example | Description | Run |
|---|---|---|
basic_usage |
Init / wake / sleep cycle | cargo run --example basic_usage |
trade_bot |
Long-running app with embedded client | cargo run --example trade_bot |
test_wake |
Agent simulation (builds app, wakes, observes) | cargo run --example test_wake |
Architecture
┌─────────────────────────────────────────────────────────────────────┐
│ Rust Application Process │
│ ┌─────────────────────────────────────────────────────────────────┐│
│ │ Application Code ││
│ │ use detrix_rs as detrix; ││
│ │ detrix::init(Config::default())?; ││
│ └─────────────────────────────────────────────────────────────────┘│
│ ┌─────────────────────────────────────────────────────────────────┐│
│ │ Control Plane HTTP Server (background thread) ││
│ │ - Exposes /detrix/* endpoints ││
│ │ - Manages lldb-dap process lifecycle ││
│ └─────────────────────────────────────────────────────────────────┘│
│ ┌─────────────────────────────────────────────────────────────────┐│
│ │ LLDB Manager ││
│ │ - Spawns: lldb-dap --connection listen://host:port ││
│ │ - Sends DAP attach request with PID ││
│ │ - Monitors process health ││
│ └─────────────────────────────────────────────────────────────────┘│
└─────────────────────────────────────────────────────────────────────┘
│
│ ptrace attach (OS-level)
↓
┌─────────────────────────────────────────────────────────────────────┐
│ lldb-dap Process (SEPARATE process) │
│ ┌─────────────────────────────────────────────────────────────────┐│
│ │ DAP Server ││
│ │ - Listens on debug_port ││
│ │ - Accepts connections from Detrix daemon ││
│ │ - Sets logpoints for metrics ││
│ └─────────────────────────────────────────────────────────────────┘│
└─────────────────────────────────────────────────────────────────────┘
API
Initialization
use ;
use Duration;
// With defaults
init?;
// With custom configuration
init?;
Status
let status = status;
println!;
println!;
if let Some = status.connection_id
Wake/Sleep (programmatic)
// Wake: start debugger and register with daemon
let response = wake?;
println!;
// Or wake with daemon URL override
let response = wake_with_url?;
// Sleep: stop debugger and unregister
let response = sleep?;
Shutdown
// Cleanup on application exit
shutdown?;
Control Plane Endpoints
| Endpoint | Method | Auth | Description |
|---|---|---|---|
/detrix/health |
GET | No | Health check (always 200 OK) |
/detrix/status |
GET | Yes* | Current state, ports, connection info |
/detrix/info |
GET | Yes* | App metadata (name, PID, Rust version) |
/detrix/wake |
POST | Yes* | Start debugger, register with daemon |
/detrix/sleep |
POST | Yes* | Stop debugger, unregister |
*Localhost bypass: 127.0.0.1 and ::1 always authorized
Environment Variables
| Variable | Description | Default |
|---|---|---|
DETRIX_NAME |
Connection name | detrix-client-{pid} |
DETRIX_DAEMON_URL |
Daemon URL | http://127.0.0.1:8090 |
DETRIX_CONTROL_HOST |
Control plane bind host | 127.0.0.1 |
DETRIX_CONTROL_PORT |
Control plane port | 0 (auto) |
DETRIX_DEBUG_PORT |
Debug adapter port | 0 (auto) |
DETRIX_TOKEN |
Auth token for remote access | - |
DETRIX_LLDB_DAP_PATH |
Path to lldb-dap binary | searches PATH |
DETRIX_HOME |
Detrix home directory | ~/detrix |
DETRIX_HEALTH_CHECK_TIMEOUT |
Health check timeout (seconds) | 2.0 |
DETRIX_REGISTER_TIMEOUT |
Registration timeout (seconds) | 5.0 |
DETRIX_UNREGISTER_TIMEOUT |
Unregistration timeout (seconds) | 2.0 |
Build Information
The client automatically detects build metadata from:
- Explicit parameters (via
Config::builder().build_commit()/.build_tag()) - Environment variables at runtime:
DETRIX_BUILD_COMMIT/DETRIX_BUILD_TAGGIT_COMMIT,CI_COMMIT_SHA,GITHUB_SHAGIT_TAG,CI_COMMIT_TAG,GITHUB_REF_NAME
- Compile-time injection (via environment variables during
cargo build):GIT_COMMIT= - Runtime git detection (local dev only)
Docker Example
FROM rust:1.75 AS builder
ARG GIT_COMMIT=unknown
ARG GIT_TAG=unknown
# Set at build time - captured by build.rs
ENV GIT_COMMIT=${GIT_COMMIT}
ENV GIT_TAG=${GIT_TAG}
RUN cargo build --release
Build with:
Requirements
lldb-dap
The client requires lldb-dap (formerly lldb-vscode) to be installed:
macOS:
# Via Homebrew LLVM
# Binary at: /opt/homebrew/opt/llvm/bin/lldb-dap
# Or via Xcode Command Line Tools
# Binary at: xcrun -f lldb-dap
Linux:
# Ubuntu/Debian
# Binary at: /usr/bin/lldb-dap
Debug Symbols
For useful debugging, compile with debug symbols:
# Cargo.toml
[]
= true
Platform Notes
macOS
- May need to grant "Developer Tools" access in System Preferences
- lldb-dap paths:
/opt/homebrew/opt/llvm/bin/lldb-dapor viaxcrun -f lldb-dap
Linux
- ptrace_scope=1 works (lldb-dap spawned as child process)
- Check:
cat /proc/sys/kernel/yama/ptrace_scope
License
MIT