-
Notifications
You must be signed in to change notification settings - Fork 3
/
option.go
75 lines (59 loc) · 1.71 KB
/
option.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package tracing
import (
"time"
"go.opentelemetry.io/otel/trace"
)
type SpanStartOption interface {
apply(o *startSpanOption)
}
type startSpanOption struct {
kind spanKind
}
func defaultSpanStartOption() *startSpanOption {
return &startSpanOption{
kind: SpanKindUnspecified,
}
}
func (o *startSpanOption) translateToTraceOptions() []trace.SpanStartOption {
traceOptions := make([]trace.SpanStartOption, 0, 2)
traceOptions = append(traceOptions, trace.WithSpanKind(o.kind), trace.WithTimestamp(time.Now()))
return traceOptions
}
type fnStartSpanOption func(opts *startSpanOption)
func (fn fnStartSpanOption) apply(opts *startSpanOption) { fn(opts) }
func newFnStartSpanOption(fn func(option *startSpanOption)) SpanStartOption {
return fnStartSpanOption(fn)
}
func WithSpanKind(kind spanKind) SpanStartOption {
return newFnStartSpanOption(func(option *startSpanOption) {
option.kind = kind
})
}
type SpanEventOption interface {
apply(o *spanEventOption)
}
func defaultSpanEventOption() *spanEventOption {
return &spanEventOption{
withStackTrace: false,
}
}
type spanEventOption struct {
withStackTrace bool
}
func (o *spanEventOption) translateToEventOptions() []trace.EventOption {
eventOptions := make([]trace.EventOption, 0, 1)
if o.withStackTrace {
eventOptions = append(eventOptions, trace.WithStackTrace(true))
}
return eventOptions
}
type fnSpanEventOption func(opts *spanEventOption)
func (fn fnSpanEventOption) apply(opts *spanEventOption) { fn(opts) }
func newFnSpanEventOption(fn func(option *spanEventOption)) SpanEventOption {
return fnSpanEventOption(fn)
}
func WithStackTrace() SpanEventOption {
return newFnSpanEventOption(func(option *spanEventOption) {
option.withStackTrace = true
})
}