-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
51 lines (42 loc) · 1.35 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
package grpcmetrics
import "go.opentelemetry.io/otel/metric"
// Option applies an option value when creating a Handler.
type Option interface {
apply(*config)
}
type optionFunc func(*config)
func (f optionFunc) apply(c *config) {
f(c)
}
type config struct {
meterProvider metric.MeterProvider
instrumentationName string
instrumentSizes bool
instrumentLatency bool
}
// WithInstrumentationName returns an Option to set custom name for metrics scope.
func WithInstrumentationName(name string) Option {
return optionFunc(func(c *config) {
c.instrumentationName = name
})
}
// WithMeterProvider returns an Option to use custom MetricProvider when creating metrics.
func WithMeterProvider(p metric.MeterProvider) Option {
return optionFunc(func(c *config) {
c.meterProvider = p
})
}
// WithInstrumentSizes enable instrument for rpc.{server|client}.response.size and rpc.{server|client}.request.size.
// This is a histogram which is quite costly.
func WithInstrumentSizes(instrumentSizes bool) Option {
return optionFunc(func(c *config) {
c.instrumentSizes = instrumentSizes
})
}
// WithInstrumentLatency enable instrument for rpc.{server|client}.duration.
// This is a histogram which is quite costly.
func WithInstrumentLatency(instrumentLatency bool) Option {
return optionFunc(func(c *config) {
c.instrumentLatency = instrumentLatency
})
}