/
options.go
102 lines (84 loc) · 2.49 KB
/
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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package leafSentryTracer
import (
"github.com/getsentry/sentry-go"
leafTime "github.com/paulusrobin/leaf-utilities/time"
"github.com/paulusrobin/leaf-utilities/tracer/integrations/sentry/ext"
"github.com/paulusrobin/leaf-utilities/tracer/integrations/sentry/messageDestinationType"
"github.com/paulusrobin/leaf-utilities/tracer/integrations/sentry/spanType"
leafTracer "github.com/paulusrobin/leaf-utilities/tracer/tracer"
"github.com/paulusrobin/leaf-utilities/tracer/tracer/tracer"
"net/http"
"time"
)
// =============
// StartOption
// =============
type (
StartOption interface {
Apply(o *startOption)
}
startOption struct {
sentryOptions sentry.ClientOptions
deferFlushDuration time.Duration
}
)
func defaultStartOption() startOption {
return startOption{
sentryOptions: sentry.ClientOptions{},
deferFlushDuration: 2 * time.Second,
}
}
type withSentryOptions struct{ sentry.ClientOptions }
func (w withSentryOptions) Apply(o *startOption) {
o.sentryOptions = w.ClientOptions
}
func WithSentryOptions(options sentry.ClientOptions) StartOption {
return withSentryOptions{options}
}
type withDeferFlushDuration struct{ time.Duration }
func (w withDeferFlushDuration) Apply(o *startOption) {
o.deferFlushDuration = w.Duration
}
func WithDeferFlushDuration(duration time.Duration) StartOption {
return withDeferFlushDuration{duration}
}
// =================
// StartSpanOption
// =================
type (
StartSpanOption = leafTracer.StartSpanOption
DataStoreOption struct {
Collection string
Operation string
ParameterizedQuery string
QueryParameters []interface{}
DatabaseName string
DatastoreProduct string
}
MessageProducerOption struct {
Library string
DestinationType messageDestinationType.Enum
DestinationName string
DestinationTemporary bool
}
)
func WithSpanType(t spanType.Enum) StartSpanOption {
return tracer.Tag(ext.SpanType, t.Code())
}
func WithDataStore(option DataStoreOption) StartSpanOption {
return tracer.Tag(ext.SpanTypeDataStore, option)
}
func WithMessageProducer(option MessageProducerOption) StartSpanOption {
return tracer.Tag(ext.SpanTypeMessageProducer, option)
}
func WithExternal(option *http.Request) StartSpanOption {
return tracer.Tag(ext.SpanTypeExternal, option)
}
func defaultStartSpanConfig() leafTracer.StartSpanConfig {
return leafTracer.StartSpanConfig{
Parent: nil,
StartTime: leafTime.Now(),
Tags: make(map[string]interface{}),
SpanID: 0,
}
}