-
Notifications
You must be signed in to change notification settings - Fork 0
/
span_options.go
43 lines (36 loc) · 852 Bytes
/
span_options.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
package tracing
import (
"runtime"
"strings"
"k8s.io/apimachinery/pkg/types"
)
type SpanOptions struct {
operation string
resource *types.NamespacedName
}
func (o *SpanOptions) Operation() string {
if o.operation == "" {
pc, _, _, _ := runtime.Caller(2)
funcName := runtime.FuncForPC(pc).Name()
lastSlash := strings.LastIndexByte(funcName, '/')
if lastSlash < 0 {
lastSlash = 0
} else {
lastSlash++
}
firstDot := strings.IndexByte(funcName[lastSlash:], '.') + lastSlash
return funcName[firstDot+1:]
}
return o.operation
}
type SpanOptionFunc func(*SpanOptions)
func WithOperationName(operation string) SpanOptionFunc {
return func(o *SpanOptions) {
o.operation = operation
}
}
func WithCustomResource(resource types.NamespacedName) SpanOptionFunc {
return func(o *SpanOptions) {
o.resource = &resource
}
}