Skip to main content
Version: 2.8.x(Latest)

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

package main

import (
"context"

"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcmd"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/gproc"
)

var (
Main = &gcmd.Command{
Name: "main",
Brief: "main process",
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
g.Log().Debug(ctx, `this is main process`)
return gproc.ShellRun(ctx, `go run sub.go`)
},
}
)

func main() {
Main.Run(gctx.GetInitCtx())
}

Sub Process

sub.go

package main

import (
"context"

"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcmd"
"github.com/gogf/gf/v2/os/gctx"
)

var (
Sub = &gcmd.Command{
Name: "sub",
Brief: "sub process",
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
g.Log().Debug(ctx, `this is sub process`)
return nil
},
}
)

func main() {
Sub.Run(gctx.GetInitCtx())
}

Execution Result

After execution, the terminal output is as follows:

$ go run main.go
2022-06-21 20:35:06.196 [DEBU] {00698a61e2a2fa1661da5d7993d72e8c} this is main process
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.