Loading...
Loading...
Debugging workflows for Python (pdb, debugpy), Go (delve), Rust (lldb), and Node.js, including container debugging (kubectl debug, ephemeral containers) and production-safe debugging techniques with distributed tracing and correlation IDs. Use when setting breakpoints, debugging containers/pods, remote debugging, or production debugging.
npx skill4agent add ancoleman/ai-design-components debugging-techniques# Python 3.7+
def buggy_function(x, y):
breakpoint() # Stops execution here
return x / y
# Older Python
import pdb
pdb.set_trace()listnextstepcontinueprint varwherequitipdbpip install ipdbpudbpip install pudbdebugpypytest --pdb # Drop into debugger on test failurereferences/python-debugging.mdgo install github.com/go-delve/delve/cmd/dlv@latestdlv debug main.go # Debug main package
dlv test github.com/me/pkg # Debug test suite
dlv attach <pid> # Attach to running process
dlv debug -- --config prod.yaml # Pass argumentsbreak main.mainbreak file.go:10continuenextstepprint xgoroutinegoroutinesgoroutines -tstack(dlv) goroutines # List all goroutines
(dlv) goroutines -t # Show stacktraces
(dlv) goroutines -with user # Filter user goroutines
(dlv) goroutine 5 # Switch to goroutine 5references/go-debugging.mdcargo build # Debug build includes symbols by defaultrust-lldb target/debug/myapp # LLDB wrapper for Rust
rust-gdb target/debug/myapp # GDB wrapper (alternative)breakpoint set -f main.rs -l 10breakpoint set -n mainruncontinuenextstepprint variableframe variablebacktracethread listvadimcn.vscode-lldblaunch.jsonreferences/rust-debugging.mdnode --inspect-brk app.js # Start and pause immediately
node --inspect app.js # Start and run
node --inspect=0.0.0.0:9229 app.js # Specify host/portchrome://inspectlaunch.json{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/app.js"
}EXPOSE 9229
CMD ["node", "--inspect=0.0.0.0:9229", "app.js"]references/nodejs-debugging.md# Add ephemeral debugging container
kubectl debug -it <pod-name> --image=nicolaka/netshoot
# Share process namespace (see other container processes)
kubectl debug -it <pod-name> --image=busybox --share-processes
# Target specific container
kubectl debug -it <pod-name> --image=busybox --target=appnicolaka/netshootbusyboxalpineubuntukubectl debug node/<node-name> -it --image=ubuntudocker exec -it <container-id> sh
# If no shell available
docker run -it --pid=container:<container-id> \
--net=container:<container-id> \
busybox shreferences/container-debugging.mdimport logging
import json
logger = logging.getLogger(__name__)
logger.info(json.dumps({
"event": "user_login_failed",
"user_id": user_id,
"error": str(e),
"correlation_id": request_id
}))func handleRequest(w http.ResponseWriter, r *http.Request) {
correlationID := r.Header.Get("X-Correlation-ID")
if correlationID == "" {
correlationID = generateUUID()
}
ctx := context.WithValue(r.Context(), "correlationID", correlationID)
log.Printf("[%s] Processing request", correlationID)
}from opentelemetry import trace
tracer = trace.get_tracer(__name__)
def process_order(order_id):
with tracer.start_as_current_span("process_order") as span:
span.set_attribute("order.id", order_id)
span.add_event("Order validated")references/production-debugging.md| Language | Primary Tool | Installation | Best For |
|---|---|---|---|
| Python | pdb | Built-in | Simple scripts, server environments |
| ipdb | | Enhanced UX, IPython users | |
| debugpy | VS Code extension | IDE integration, remote debugging | |
| Go | delve | | All Go debugging, goroutines |
| Rust | rust-lldb | System package | Mac, Linux, MSVC Windows |
| rust-gdb | System package | Linux, prefer GDB | |
| Node.js | node --inspect | Built-in | All Node.js debugging, Chrome DevTools |
| Scenario | Recommended Technique | Tools |
|---|---|---|
| Local development | Interactive debugger | pdb, delve, lldb, node --inspect |
| Bug in test | Test-specific debugging | pytest --pdb, dlv test, cargo test |
| Remote server | SSH tunnel + remote attach | VS Code Remote, debugpy |
| Container (local) | docker exec -it | sh/bash + debugger |
| Kubernetes pod | Ephemeral container | kubectl debug --image=nicolaka/netshoot |
| Distroless image | Ephemeral container (required) | kubectl debug with busybox/alpine |
| Production issue | Log analysis + error tracking | Structured logs, Sentry, correlation IDs |
| Goroutine deadlock | Goroutine inspection | delve goroutines -t |
| Crashed process | Core dump analysis | gdb core, lldb -c core |
| Distributed failure | Distributed tracing | OpenTelemetry, Jaeger, correlation IDs |
| Race condition | Race detector + debugger | go run -race, cargo test |
pytest --pdb # Drops into pdb on failuredlv test github.com/user/project/pkg
(dlv) break TestMyFunction
(dlv) continuecargo test --no-run
rust-lldb target/debug/deps/myapp-<hash>
(lldb) breakpoint set -n test_name
(lldb) run test_name# Step 1: Check pod status
kubectl get pod my-app-pod -o wide
# Step 2: Check logs first
kubectl logs my-app-pod
# Step 3: Add ephemeral container if logs insufficient
kubectl debug -it my-app-pod --image=nicolaka/netshoot
# Step 4: Inside debug container, investigate
curl localhost:8080
netstat -tuln
nslookup api.example.com# Step 1: Check error tracking (Sentry)
# - Find error details, stack trace
# - Copy correlation ID from error report
# Step 2: Search logs for correlation ID
# In log aggregation tool (ELK, Splunk):
# correlation_id:"abc-123-def"
# Step 3: View distributed trace
# In tracing tool (Jaeger, Datadog):
# Search by correlation ID, review span timeline
# Step 4: Reproduce in staging
# Use production data (sanitized) if needed
# Add additional logging if needed
# Step 5: Fix and deploy
# Create feature flag for gradual rollout
# Deploy to canary environment first
# Monitor error rates closelyreferences/python-debugging.mdreferences/go-debugging.mdreferences/rust-debugging.mdreferences/nodejs-debugging.mdreferences/container-debugging.mdreferences/production-debugging.mdreferences/decision-trees.mdexamples/auth-securityperformance-engineeringkubernetes-operationstesting-strategiesobservability