generated from NdoleStudio/go-http-client
-
Notifications
You must be signed in to change notification settings - Fork 2
/
option.go
55 lines (46 loc) · 1.41 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
package otelroundtripper
import (
"net/http"
"strings"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
)
// 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)
}
// WithParent sets the underlying http.RoundTripper which is wrapped by this round tripper.
// If the provided http.RoundTripper is nil, http.DefaultTransport will be used as the base http.RoundTripper
func WithParent(parent http.RoundTripper) Option {
return optionFunc(func(cfg *config) {
if parent != nil {
cfg.parent = parent
}
})
}
// WithName sets the prefix for the metrics emitted by this round tripper.
// by default, the "http.client" name is used.
func WithName(name string) Option {
return optionFunc(func(cfg *config) {
if strings.TrimSpace(name) != "" {
cfg.name = strings.TrimSpace(name)
}
})
}
// WithMeter sets the underlying metric.Meter that is used to create metric instruments
// By default the no-op meter is used.
func WithMeter(meter metric.Meter) Option {
return optionFunc(func(cfg *config) {
cfg.meter = meter
})
}
// WithAttributes sets a list of attribute.KeyValue labels for all metrics associated with this round tripper
func WithAttributes(attributes ...attribute.KeyValue) Option {
return optionFunc(func(cfg *config) {
cfg.attributes = attributes
})
}