forked from KasperskyLab/klogga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (51 loc) · 1.12 KB
/
main.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
package main
import (
"context"
"github.com/KasperskyLab/klogga"
fxAdapter "github.com/KasperskyLab/klogga/adapters/fx"
"go.uber.org/fx"
"time"
)
func main() {
fx.New(CreateApp()).Run()
}
func CreateApp() fx.Option {
return fx.Options(
fx.Provide(NewRunner,
fx.Annotate(func(r *Runner) fxAdapter.Runner { return r }, fxAdapter.TagRunner...)),
fxAdapter.Full(),
fx.Invoke(fxAdapter.RegisterRunners), // register runnerA
)
}
type Runner struct {
trs klogga.Tracer
stop chan struct{}
}
func NewRunner(trsFactory klogga.TracerProvider) *Runner {
return &Runner{
trs: trsFactory.Named("runner_a"),
}
}
func (r *Runner) Start(ctx context.Context) error {
span := klogga.StartLeaf(ctx)
defer r.trs.Finish(span)
go func() {
for i := 0; ; i++ {
r.LogSomething(i)
select {
case <-r.stop:
return
case <-time.After(2 * time.Second):
}
}
}()
return nil
}
func (*Runner) Stop(context.Context) error {
return nil
}
func (r *Runner) LogSomething(iteration int) {
span := klogga.StartLeaf(context.Background(), klogga.WithName("run_func"))
defer r.trs.Finish(span)
span.Val("iteration", iteration)
}