Introduction

The GoFrame command management component also supports cross-process tracing features, which are particularly useful for processes that run temporarily.

The overall tracing of the framework adopts the OpenTelemetry specification.

Usage Example

Main Process

main.go

  1. package main
  2. import (
  3. "context"
  4. "github.com/gogf/gf/v2/frame/g"
  5. "github.com/gogf/gf/v2/os/gcmd"
  6. "github.com/gogf/gf/v2/os/gctx"
  7. "github.com/gogf/gf/v2/os/gproc"
  8. )
  9. var (
  10. Main = &gcmd.Command{
  11. Name: "main",
  12. Brief: "main process",
  13. Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
  14. g.Log().Debug(ctx, `this is main process`)
  15. return gproc.ShellRun(ctx, `go run sub.go`)
  16. },
  17. }
  18. )
  19. func main() {
  20. Main.Run(gctx.GetInitCtx())
  21. }

Sub Process

sub.go

  1. package main
  2. import (
  3. "context"
  4. "github.com/gogf/gf/v2/frame/g"
  5. "github.com/gogf/gf/v2/os/gcmd"
  6. "github.com/gogf/gf/v2/os/gctx"
  7. )
  8. var (
  9. Sub = &gcmd.Command{
  10. Name: "sub",
  11. Brief: "sub process",
  12. Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
  13. g.Log().Debug(ctx, `this is sub process`)
  14. return nil
  15. },
  16. }
  17. )
  18. func main() {
  19. Sub.Run(gctx.GetInitCtx())
  20. }

Execution Result

After execution, the terminal output is as follows:

  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

You can see that the link information has been automatically passed to the sub-process.