-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracing
44 lines (38 loc) · 1.42 KB
/
tracing
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
import (
"gitlab.wildberries.ru/finance/go-infrastructure/tracing"
"context"
"fmt"
)
{{ $decorator := (or .Vars.DecoratorName (printf "%sWithTracing" .Interface.Name)) }}
{{ $structName := (or .Vars.DecoratorName (printf "d%s" $decorator)) }}
{{ $spanName := (or .Vars.InstanceName .Interface.Name) }}
{{ $setName := (or .Vars.SetName false) }}
{{ $db := (or .Vars.db false) }}
type (
{{$structName}} struct {
{{ if $setName }} name string {{ end }}
{{.Interface.Type}}
_opts []tracing.DBSpanOption
}
)
func New{{$decorator}} ( {{ if $setName }} name string, {{ end }} base {{.Interface.Type}}, opts ...tracing.DBSpanOption) ({{$.Interface.Type}}, error) {
if base == nil {
return nil, fmt.Errorf("base interface cannot be nil")
}
return &{{$structName}} { {{ if $setName}}
name: name, {{ end }}
{{.Interface.Name}}: base,
_opts: opts,
}, nil
}
{{range $method := .Interface.Methods}}
{{if $method.AcceptsContext}}
func (_d {{$structName}}) {{$method.Declaration}} {
_span, ctx := tracing.{{ if $db }}StartDBSpan{{ else }}StartSpanFromContext{{ end }}(ctx, {{if $setName }}_d.name+".{{$method.Name}}"{{ else }}"{{$.Interface.Name}}.{{$method.Name}}"{{end}})
defer func() {
_span.FinishWithError(err)
}()
{{$method.Pass (printf "_d.%s." $.Interface.Name) }}
}
{{end}}
{{end}}