-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.go
108 lines (93 loc) · 3.31 KB
/
config.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
103
104
105
106
107
108
package telemetry
import (
"time"
"go.opentelemetry.io/contrib/instrumentation/runtime"
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
"go.opentelemetry.io/otel/sdk/metric/selector/simple"
"go.opentelemetry.io/otel/sdk/resource"
)
type meterProviderConfig struct {
resource *resource.Resource
collectPeriod time.Duration
collectTimeout time.Duration
pushTimeout time.Duration
exporter metricsdk.Exporter
shutdownExporter ShutdownExporter
aggregatorSelector metricsdk.AggregatorSelector
hostInstrumentation bool
runtimeInstrumentation bool
runtimeInstrumentationOpts []runtime.Option
}
func newMeterProviderConfig(opts []MeterProviderOption) meterProviderConfig {
cfg := meterProviderConfig{
resource: resource.Default(),
collectPeriod: controller.DefaultPeriod,
collectTimeout: controller.DefaultPeriod,
pushTimeout: controller.DefaultPeriod,
aggregatorSelector: simple.NewWithHistogramDistribution(),
}
for _, opt := range opts {
opt(&cfg)
}
return cfg
}
// MeterProviderOption is the interface that applies the value to a meter provider configurations.
type MeterProviderOption func(*meterProviderConfig)
// WithResource sets the Resource of a MeterProvider.
func WithResource(resource *resource.Resource) MeterProviderOption {
return func(cfg *meterProviderConfig) {
cfg.resource = resource
}
}
// WithCollectPeriod sets CollectPeriod of a MeterProvider.
//
// CollectPeriod is the interval between calls to Collect a checkpoint.
func WithCollectPeriod(collectPeriod time.Duration) MeterProviderOption {
return func(cfg *meterProviderConfig) {
cfg.collectPeriod = collectPeriod
}
}
// WithCollectTimeout sets CollectTimeout of a MeterProvider.
//
// CollectTimeout is the timeout of the Context passed to Collect() and subsequently to Observer
// instrument callbacks.
func WithCollectTimeout(collectTimeout time.Duration) MeterProviderOption {
return func(cfg *meterProviderConfig) {
cfg.collectTimeout = collectTimeout
}
}
// WithPushTimeout sets PushTimeout of a MeterProvider.
//
// PushTimeout is the timeout of the Context when a exporter is configured.
func WithPushTimeout(pushTimeout time.Duration) MeterProviderOption {
return func(cfg *meterProviderConfig) {
cfg.pushTimeout = pushTimeout
}
}
// WithExporter sets exporter and its shutdown function.
func WithExporter(exporter metricsdk.Exporter, shutdownExporter ShutdownExporter) MeterProviderOption {
return func(cfg *meterProviderConfig) {
cfg.exporter = exporter
cfg.shutdownExporter = shutdownExporter
}
}
// WithAggregatorSelector sets selector of aggregator.
func WithAggregatorSelector(aggregatorSelector metricsdk.AggregatorSelector) MeterProviderOption {
return func(cfg *meterProviderConfig) {
cfg.aggregatorSelector = aggregatorSelector
}
}
// WithHostInstrumentation enables host instrumentation.
func WithHostInstrumentation() MeterProviderOption {
return func(cfg *meterProviderConfig) {
cfg.hostInstrumentation = true
}
}
// WithRuntimeInstrumentation enables runtime instrumentation.
func WithRuntimeInstrumentation(opts ...runtime.Option) MeterProviderOption {
return func(cfg *meterProviderConfig) {
cfg.runtimeInstrumentation = true
cfg.runtimeInstrumentationOpts = opts
}
}