...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package metric
16
17 import "go.opentelemetry.io/otel/attribute"
18
19
20 type MeterConfig struct {
21 instrumentationVersion string
22 schemaURL string
23 attrs attribute.Set
24
25
26 noCmp [0]func()
27 }
28
29
30
31 func (cfg MeterConfig) InstrumentationVersion() string {
32 return cfg.instrumentationVersion
33 }
34
35
36
37 func (cfg MeterConfig) InstrumentationAttributes() attribute.Set {
38 return cfg.attrs
39 }
40
41
42 func (cfg MeterConfig) SchemaURL() string {
43 return cfg.schemaURL
44 }
45
46
47 type MeterOption interface {
48
49 applyMeter(MeterConfig) MeterConfig
50 }
51
52
53
54 func NewMeterConfig(opts ...MeterOption) MeterConfig {
55 var config MeterConfig
56 for _, o := range opts {
57 config = o.applyMeter(config)
58 }
59 return config
60 }
61
62 type meterOptionFunc func(MeterConfig) MeterConfig
63
64 func (fn meterOptionFunc) applyMeter(cfg MeterConfig) MeterConfig {
65 return fn(cfg)
66 }
67
68
69 func WithInstrumentationVersion(version string) MeterOption {
70 return meterOptionFunc(func(config MeterConfig) MeterConfig {
71 config.instrumentationVersion = version
72 return config
73 })
74 }
75
76
77
78
79 func WithInstrumentationAttributes(attr ...attribute.KeyValue) MeterOption {
80 return meterOptionFunc(func(config MeterConfig) MeterConfig {
81 config.attrs = attribute.NewSet(attr...)
82 return config
83 })
84 }
85
86
87 func WithSchemaURL(schemaURL string) MeterOption {
88 return meterOptionFunc(func(config MeterConfig) MeterConfig {
89 config.schemaURL = schemaURL
90 return config
91 })
92 }
93
View as plain text