Introduction

The process management component supports cross-process tracinging features, which are especially useful for some temporarily running processes. The overall tracinging of the framework adopts the OpenTelemetry specification.

Usage Example

Main Process

main.go

  1. package main
  2. import (
  3. "github.com/gogf/gf/v2/frame/g"
  4. "github.com/gogf/gf/v2/os/gctx"
  5. "github.com/gogf/gf/v2/os/gproc"
  6. )
  7. func main() {
  8. ctx := gctx.GetInitCtx()
  9. g.Log().Debug(ctx, `this is main process`)
  10. if err := gproc.ShellRun(ctx, `go run sub.go`); err != nil {
  11. panic(err)
  12. }
  13. }

Subprocess

sub.go

  1. package main
  2. import (
  3. "github.com/gogf/gf/v2/frame/g"
  4. "github.com/gogf/gf/v2/os/gctx"
  5. )
  6. func main() {
  7. ctx := gctx.GetInitCtx()
  8. g.Log().Debug(ctx, `this is sub process`)
  9. }

Execution Result

After execution, the terminal outputs the following:

  1. $ go run main.go
  2. 2022-06-21 20:35:06.196 [DEBU] {00698a61e2a2fa1661da5d7993d72e8c} this is main process
  3. 2022-06-21 20:35:07.482 [DEBU] {00698a61e2a2fa1661da5d7993d72e8c} this is sub process

As you can see, the trace information has been automatically passed to the subprocess.