summaryrefslogtreecommitdiff
path: root/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/option.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/technologize/otel-go-contrib/otelginmetrics/option.go')
-rw-r--r--vendor/github.com/technologize/otel-go-contrib/otelginmetrics/option.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/option.go b/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/option.go
new file mode 100644
index 000000000..144ef9378
--- /dev/null
+++ b/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/option.go
@@ -0,0 +1,74 @@
+package otelginmetrics
+
+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(serverName, route string, request *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(serverName, route string, request *http.Request) bool) Option {
+ return optionFunc(func(cfg *config) {
+ cfg.shouldRecord = shouldRecord
+ })
+}