-
Notifications
You must be signed in to change notification settings - Fork 53
/
options.go
100 lines (86 loc) · 2.75 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
package lightstepoc
import (
"github.com/lightstep/lightstep-tracer-go"
"github.com/lightstep/lightstep-tracer-go/constants"
"github.com/opentracing/opentracing-go"
)
// By default, the exporter will attempt to connect to a local satellite
const (
DefaultSatelliteHost = "localhost"
DefaultSatellitePort = 8360
)
// Option provides configuration for the Exporter
type Option func(*config)
// Attributes provide extra information in a span
type Attributes map[string]interface{}
// WithAccessToken sets an access token for communicating with LightStep
func WithAccessToken(accessToken string) Option {
return func(c *config) {
c.tracerOptions.AccessToken = accessToken
}
}
// WithSatelliteHost sets the satellite host to which spans will be sent
func WithSatelliteHost(satelliteHost string) Option {
return func(c *config) {
c.tracerOptions.Collector.Host = satelliteHost
}
}
// WithSatellitePort sets the satellite port to which spans will be sent
func WithSatellitePort(satellitePort int) Option {
return func(c *config) {
c.tracerOptions.Collector.Port = satellitePort
}
}
// WithInsecure prevents the Exporter from communicating over TLS with the satellite,
// i.e., the connection will run over HTTP instead of HTTPS
func WithInsecure(insecure bool) Option {
return func(c *config) {
c.tracerOptions.Collector.Plaintext = insecure
}
}
// WithMetaEventReportingEnabled configures the tracer to send meta events,
// e.g., events for span creation
func WithMetaEventReportingEnabled(metaEventReportingEnabled bool) Option {
return func(c *config) {
c.tracerOptions.MetaEventReportingEnabled = metaEventReportingEnabled
}
}
// WithComponentName overrides the component (service) name that will be used in LightStep
func WithComponentName(componentName string) Option {
return func(c *config) {
if componentName != "" {
c.tracerOptions.Tags[constants.ComponentNameKey] = componentName
}
}
}
// WithDefaultAttributes sets attributes that will be appended to every span that is exported to the trace.
func WithDefaultAttributes(attrs Attributes) Option {
return func(c *config) {
for key, value := range attrs {
c.tracerOptions.Tags[key] = value
}
}
}
// WithMaxBufferedSpans sets the maximum number of spans that will be buffered
// before sending them to a collector.
// Should be used to override the `DefaultMaxSpan` value of 1000.
func WithMaxBufferedSpans(value int) Option {
return func(c *config) {
c.tracerOptions.MaxBufferedSpans = value
}
}
type config struct {
tracerOptions lightstep.Options
}
func defaultConfig() *config {
return &config{
tracerOptions: lightstep.Options{
Collector: lightstep.Endpoint{
Host: DefaultSatelliteHost,
Port: DefaultSatellitePort,
},
Tags: make(opentracing.Tags),
UseHttp: true,
},
}
}