-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
83 lines (69 loc) · 2.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package gqlgenmetrics
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
instrumentRequestDuration bool
instrumentRequestCount bool
instrumentResolverDuration bool
instrumentResolverCount bool
instrumentResolverCustomOnly 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
})
}
// WithInstrumentRequestDuration enable/disable reporting of 'gql.request.duration' metric
// which is a histogram and could results in high cardinality.
// enabled by default.
func WithInstrumentRequestDuration(instrumentRequestDuration bool) Option {
return optionFunc(func(c *config) {
c.instrumentRequestDuration = instrumentRequestDuration
})
}
// WithInstrumentRequestCount enable/disable reporting of 'gql.request.completed' metric
// enabled by default.
func WithInstrumentRequestCount(instrumentRequestCount bool) Option {
return optionFunc(func(c *config) {
c.instrumentRequestCount = instrumentRequestCount
})
}
// WithInstrumentResolverDuration enable/disable reporting of 'gql.resolver.duration' metric
// which is a histogram and could results in high cardinality.
// enabled by default.
func WithInstrumentResolverDuration(instrumentResolverDuration bool) Option {
return optionFunc(func(c *config) {
c.instrumentResolverDuration = instrumentResolverDuration
})
}
// WithInstrumentResolverCount enable/disable reporting of 'gql.resolver.completes' metric.
// enabled by default.
func WithInstrumentResolverCount(instrumentResolverCount bool) Option {
return optionFunc(func(c *config) {
c.instrumentResolverCount = instrumentResolverCount
})
}
// WithInstrumentResolverCustomOnly allows reducing cardinality of the 'gql.resolver.duration' and 'gql.resolver.completed'
// metrics by only reporting custom field resolvers.
// disabled by default.
func WithInstrumentResolverCustomOnly(instrumentResolverCustomOnly bool) Option {
return optionFunc(func(c *config) {
c.instrumentResolverCustomOnly = instrumentResolverCustomOnly
})
}