Multi-Process Tracing Examples
Code Source: https://github.com/gogf/examples/tree/main/observability/trace/processes
Description
This directory contains examples demonstrating distributed tracing across multiple processes using different GoFrame process management approaches. It includes:
-
Command-Line Process Management (
gcmd/
)- Uses
gcmd
package for process management - Demonstrates command-line based process creation
- Shows trace context propagation between parent and child processes
- Uses
-
Process Management (
gproc/
)- Uses
gproc
package for process management - Demonstrates programmatic process creation
- Shows trace context propagation in process hierarchy
- Uses
Directory Structure
.
├── gcmd/ # Command-line process management example
│ ├── main.go # Main process implementation
│ └── sub/ # Sub-process implementation
│ └── sub.go # Sub-process code
├── gproc/ # Process management example
│ ├── main.go # Main process implementation
│ └── sub/ # Sub-process implementation
│ └── sub.go # Sub-process code
├── go.mod # Go module file
└── go.sum # Go module checksums
Requirements
Features
The examples showcase the following features:
-
Process Management
- Process creation and execution
- Command-line argument handling
- Process communication
- Error handling
-
Trace Context Propagation
- Parent-child process trace linking
- Context management across processes
- Trace baggage handling
-
Logging and Debugging
- Process identification
- Debug logging
- Error reporting
Comparison of Approaches
Command-Line Management (gcmd/)
-
Features:
- Command-line interface
- Structured command handling
- Built-in help and documentation
- Command hierarchy support
-
Use Cases:
- CLI applications
- Command-driven tools
- Interactive applications
Process Management (gproc/)
-
Features:
- Programmatic process control
- Direct process manipulation
- Shell command execution
- Process synchronization
-
Use Cases:
- Background processes
- Service management
- Process automation
Usage
Command-Line Example
-
Navigate to gcmd example:
cd gcmd
-
Run the example:
go run main.go
Process Management Example
-
Navigate to gproc example:
cd gproc
-
Run the example:
go run main.go
Implementation Details
Both examples demonstrate:
-
Process Creation
- Main process initialization
- Sub-process spawning
- Process environment setup
-
Context Management
- Context creation and initialization
- Context propagation between processes
- Context cleanup
-
Error Handling
- Process execution errors
- Command execution errors
- Graceful error reporting
Troubleshooting
-
Process Issues:
- Check process execution permissions
- Verify process environment variables
- Review process exit codes
-
Context Issues:
- Verify context propagation
- Check context cancellation
- Review context deadlines
-
General Issues:
- Check Go environment setup
- Verify GoFrame installation
- Review application logs