Documentation
¶
Overview ¶
Package detrix provides the Detrix Go client for debug-on-demand observability.
This client enables Go applications to be observed by the Detrix daemon without any code modifications or performance overhead when inactive.
Basic usage:
import "github.com/anthropics/detrix-go"
func main() {
// Initialize client (starts control plane, stays SLEEPING)
err := detrix.Init(detrix.Config{
Name: "my-service",
DaemonURL: "http://127.0.0.1:8090",
})
if err != nil {
log.Fatal(err)
}
defer detrix.Shutdown()
// ... your application code ...
// When you need observability:
resp, err := detrix.Wake()
if err != nil {
log.Printf("Wake failed: %v", err)
}
// When done:
detrix.Sleep()
}
Unlike Python's debugpy, Delve can be fully stopped on Sleep(), providing cleaner resource management.
Index ¶
Constants ¶
const ( WakeStatusAwake = generated.Awake WakeStatusAlreadyAwake = generated.AlreadyAwake SleepStatusSleeping = generated.SleepResponseStatusSleeping SleepStatusAlreadySleeping = generated.SleepResponseStatusAlreadySleeping )
Re-export status constants for convenience.
Variables ¶
var ( ErrNotInitialized = errors.New("detrix client not initialized") ErrAlreadyInitialized = errors.New("detrix client already initialized") ErrWakeInProgress = errors.New("wake operation already in progress") )
Common errors
var ( // Version is the client version (set via ldflags or defaults to "1.0.0") Version = "1.1.1" // BuildCommit is the git commit SHA (set via ldflags) BuildCommit = "" // BuildTime is when the binary was built (set via ldflags) BuildTime = "" )
Version information (can be set via ldflags at build time)
Functions ¶
func Init ¶
Init initializes the Detrix client.
This starts the control plane HTTP server but does NOT contact the daemon. The client starts in SLEEPING state.
Configuration can also be provided via environment variables:
- DETRIX_NAME
- DETRIX_DAEMON_URL
- DETRIX_CONTROL_HOST
- DETRIX_CONTROL_PORT
- DETRIX_DEBUG_PORT
- DETRIX_DELVE_PATH
- DETRIX_HOME
- DETRIX_HEALTH_CHECK_TIMEOUT (seconds, e.g. "2.0")
- DETRIX_REGISTER_TIMEOUT (seconds, e.g. "5.0")
- DETRIX_UNREGISTER_TIMEOUT (seconds, e.g. "2.0")
Function parameters take precedence over environment variables.
Types ¶
type ClientState ¶
type ClientState = generated.ClientState
ClientState represents the client state.
type Config ¶
type Config struct {
// Name is the connection name (default: "detrix-client-{pid}")
Name string
// ControlHost is the host for the control plane server (default: "127.0.0.1")
ControlHost string
// AdvertiseHost is the host sent to the detrix server for registration.
// If set, this is used instead of ControlHost when registering with the detrix server.
// Useful in Docker/cloud where bind address (0.0.0.0) differs from
// the reachable address (container hostname).
AdvertiseHost string
// ControlPort is the port for the control plane (0 = auto-assign)
ControlPort int
// DebugPort is the port for the debug adapter (0 = auto-assign)
DebugPort int
// DaemonURL is the URL of the Detrix daemon (default: "http://127.0.0.1:8090")
DaemonURL string
// DelvePath is the path to the dlv binary (default: searches PATH)
DelvePath string
// DetrixHome is the path to the Detrix home directory (default: ~/detrix)
DetrixHome string
// HealthCheckTimeout is the timeout for daemon health checks (default: 2s)
HealthCheckTimeout time.Duration
// RegisterTimeout is the timeout for connection registration (default: 5s)
RegisterTimeout time.Duration
// UnregisterTimeout is the timeout for connection unregistration (default: 2s)
UnregisterTimeout time.Duration
// DelveStartTimeout is the timeout for Delve to start (default: 10s)
DelveStartTimeout time.Duration
// SafeMode enables production-safe mode: only logpoints (non-blocking) are allowed.
// Disables operations that require breakpoints: function calls, stack traces, memory snapshots.
// Recommended for production environments where execution pauses are unacceptable.
SafeMode bool
// WorkspaceRoot overrides the workspace root sent to the daemon.
// Default: current working directory (os.Getwd).
// Set this in Docker/cloud where the CWD doesn't match the build source path.
WorkspaceRoot string
// BuildCommit allows explicit override of build commit detection (optional)
BuildCommit string
// BuildTag allows explicit override of build tag detection (optional)
BuildTag string
}
Config holds client configuration.
type SleepResponse ¶
type SleepResponse = generated.SleepResponse
SleepResponse is the response from a sleep operation. Type alias to generated type for API compatibility.
func Sleep ¶
func Sleep() (SleepResponse, error)
Sleep stops the debugger and unregisters from the daemon.
Unlike Python's debugpy, Delve can be fully stopped, providing cleaner resource management.
type SleepStatus ¶
type SleepStatus = generated.SleepResponseStatus
SleepStatus represents the status field in SleepResponse.
type StatusResponse ¶
type StatusResponse = generated.StatusResponse
StatusResponse contains the current client status. Type alias to generated type for API compatibility.
type WakeResponse ¶
type WakeResponse = generated.WakeResponse
WakeResponse is the response from a wake operation. Type alias to generated type for API compatibility.
func Wake ¶
func Wake() (WakeResponse, error)
Wake starts the debugger and registers with the daemon.
This spawns a Delve process to attach to the current process, then registers the connection with the Detrix daemon.
func WakeWithURL ¶
func WakeWithURL(daemonURL string) (WakeResponse, error)
WakeWithURL starts the debugger with a daemon URL override.
type WakeStatus ¶
type WakeStatus = generated.WakeResponseStatus
WakeStatus represents the status field in WakeResponse.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
Example basic demonstrates the Detrix Go client usage.
|
Example basic demonstrates the Detrix Go client usage. |
|
basic_usage
command
Example basic_usage demonstrates the Detrix Go client usage.
|
Example basic_usage demonstrates the Detrix Go client usage. |
|
test_dap_eval
command
Test DAP evaluate with function calls directly against Delve
|
Test DAP evaluate with function calls directly against Delve |
|
test_wake
command
Agent simulation test - wake a running Go app and observe it.
|
Agent simulation test - wake a running Go app and observe it. |
|
trade_bot
command
Long-running trading bot with Detrix client - runs until Ctrl+C
|
Long-running trading bot with Detrix client - runs until Ctrl+C |
|
internal
|
|
|
auth
Package auth provides authentication utilities for the Detrix client.
|
Package auth provides authentication utilities for the Detrix client. |
|
control
Package control provides the HTTP control plane server for the Detrix client.
|
Package control provides the HTTP control plane server for the Detrix client. |
|
daemon
Package daemon provides HTTP client for communicating with the Detrix daemon.
|
Package daemon provides HTTP client for communicating with the Detrix daemon. |
|
delve
Package delve provides Delve process lifecycle management.
|
Package delve provides Delve process lifecycle management. |
|
generated
Package generated provides primitives to interact with the openapi HTTP API.
|
Package generated provides primitives to interact with the openapi HTTP API. |
|
state
Package state provides thread-safe state management for the Detrix client.
|
Package state provides thread-safe state management for the Detrix client. |