-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace.go
61 lines (48 loc) · 1.04 KB
/
trace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package debug
import (
"fmt"
"time"
"github.com/micro/cli/v2"
"github.com/btccom/go-micro/v2"
"github.com/btccom/go-micro/v2/debug/service"
log "github.com/btccom/go-micro/v2/logger"
)
const (
// logUsage message for logs command
traceUsage = "Required usage: micro trace example"
)
func getTrace(ctx *cli.Context, srvOpts ...micro.Option) {
log.Trace("debug")
// TODO look for trace id
if ctx.Args().Len() == 0 {
fmt.Println("Require service name")
return
}
name := ctx.Args().Get(0)
// must specify service name
if len(name) == 0 {
fmt.Println(traceUsage)
return
}
// initialise a new service log
// TODO: allow "--source" e.g. kubernetes
srv := service.NewClient(name)
spans, err := srv.Trace()
if err != nil {
fmt.Println(err)
return
}
if len(spans) == 0 {
return
}
fmt.Println("Id\tName\tTime\tDuration\tStatus")
for _, span := range spans {
fmt.Printf("%s\t%s\t%s\t%v\t%s\n",
span.Trace,
span.Name,
time.Unix(0, int64(span.Started)).String(),
time.Duration(span.Duration),
"",
)
}
}