-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.go
55 lines (43 loc) · 1.38 KB
/
example.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
package main
import (
"context"
"fmt"
"github.com/cksidharthan/go-jaeger/pkg/client"
"github.com/cksidharthan/go-jaeger/pkg/trace"
"github.com/sirupsen/logrus"
"time"
)
func main() {
exLogger := logrus.StandardLogger()
jaegerClient, err := client.New(&client.Opts{
CollectorURL: "http://localhost:14268/api/traces",
ServiceName: "test_service",
Environment: "dev",
Logger: exLogger,
})
if err != nil {
fmt.Println(err)
}
defer jaegerClient.Disconnect(context.Background())
methodTrace := trace.NewTraceWithContext(context.Background())
defer methodTrace.Close()
firstFunc(methodTrace, "John", "Doe")
time.Sleep(1 * time.Second)
firstFunc(methodTrace, "Jane", "Doe")
}
func firstFunc(funcTrace *trace.Trace, firstName string, lastName string) {
subTrace := funcTrace.StartNewSpanWithName(fmt.Sprintf("changeName(%s, %s)", firstName, lastName))
subTrace.SetTag("process", "firstFunc")
defer subTrace.Close()
time.Sleep(1 * time.Second)
changeName(subTrace, firstName, lastName)
}
func changeName(funcTrace *trace.Trace, firstName string, lastName string) {
subTrace := funcTrace.StartNewSpanWithName(fmt.Sprintf("changeName(%s, %s)", firstName, lastName))
defer subTrace.Close()
time.Sleep(1 * time.Second)
subTrace.SetTag("first_name", firstName)
subTrace.SetTag("last_name", lastName)
subTrace.SetTag("process", "firstFunc")
time.Sleep(1 * time.Second)
}