/
option.go
74 lines (62 loc) · 2 KB
/
option.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
package otelhttpmetrics
import (
"net/http"
"go.opentelemetry.io/otel/attribute"
)
// Option applies a configuration to the given config
type Option interface {
apply(cfg *config)
}
type optionFunc func(cfg *config)
func (fn optionFunc) apply(cfg *config) {
fn(cfg)
}
// WithAttributes sets a func using which what attributes to be recorded can be specified.
// By default the DefaultAttributes is used
func WithAttributes(attributes func(*http.Request) []attribute.KeyValue) Option {
return optionFunc(func(cfg *config) {
cfg.attributes = attributes
})
}
// WithRecordInFlight determines whether to record In Flight Requests or not
// By default the recordInFlight is true
func WithRecordInFlightDisabled() Option {
return optionFunc(func(cfg *config) {
cfg.recordInFlight = false
})
}
// WithRecordDuration determines whether to record Duration of Requests or not
// By default the recordDuration is true
func WithRecordDurationDisabled() Option {
return optionFunc(func(cfg *config) {
cfg.recordDuration = false
})
}
// WithRecordSize determines whether to record Size of Requests and Responses or not
// By default the recordSize is true
func WithRecordSizeDisabled() Option {
return optionFunc(func(cfg *config) {
cfg.recordSize = false
})
}
// WithGroupedStatus determines whether to group the response status codes or not. If true 2xx, 3xx will be stored
// By default the groupedStatus is true
func WithGroupedStatusDisabled() Option {
return optionFunc(func(cfg *config) {
cfg.groupedStatus = false
})
}
// WithRecorder sets a recorder for recording requests
// By default the open telemetry recorder is used
func WithRecorder(recorder Recorder) Option {
return optionFunc(func(cfg *config) {
cfg.recorder = recorder
})
}
// WithShouldRecordFunc sets a func using which whether a record should be recorded
// By default the all api calls are recorded
func WithShouldRecordFunc(shouldRecord func(*http.Request) bool) Option {
return optionFunc(func(cfg *config) {
cfg.shouldRecord = shouldRecord
})
}