-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.go
59 lines (49 loc) · 1.54 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
package telemetry
import (
"go.opentelemetry.io/contrib/instrumentation/runtime"
metricsdk "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
)
type meterProviderConfig struct {
resource *resource.Resource
exporter metricsdk.Exporter
hostInstrumentation bool
runtimeInstrumentation bool
runtimeInstrumentationOpts []runtime.Option
}
func newMeterProviderConfig(opts []MeterProviderOption) meterProviderConfig {
cfg := meterProviderConfig{
resource: resource.Default(),
}
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
}
}
// WithExporter sets exporter and its shutdown function.
func WithExporter(exporter metricsdk.Exporter) MeterProviderOption {
return func(cfg *meterProviderConfig) {
cfg.exporter = exporter
}
}
// 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
}
}